Indexing

Each selector and value within a data item in a bag have three associated index numbers:

This allows indexing by user selectors, system selectors, or both as shown in Figure 17.

Figure 17. Indexing
Indexing is described in the surrounding text.

In Figure Figure 17, user item 3 (selector A) can be referred to by the following index pairs:

Selector ItemIndex
selector A 1
MQSEL_ANY_USER_SELECTOR 2
MQSEL_ANY_SELECTOR 3

The index is zero-based like an array in C; if there are 'n' occurrences, the index ranges from zero through 'n-1', with no gaps.

Indexes are used when replacing or removing existing data items from a bag. When used in this way, the insertion order is preserved, but indexes of other data items can be affected. For examples of this, see Changing information within a bag and Deleting data items.

The three types of indexing allow easy retrieval of data items. For example, if there are three instances of a particular selector in a bag, the mqCountItems call can count the number of instances of that selector, and the mqInquire* calls can specify both the selector and the index to inquire those values only. This is useful for attributes that can have a list of values such as some of the exits on channels.