Home

 

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 1.

Figure 1. Indexing


In Figure Figure 1, 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 Delete 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.

 

Parent topic:

Advanced topics


pc17970_


 

Home