Home
Indexing
Each selector and value within a data item in a bag have three associated index numbers:
- The index relative to other items that have the same selector.
- The index relative to the category of selector (user or system) to which the item belongs.
- The index relative to all the data items in the bag (user and system).
This allows indexing by user selectors, system selectors, or both as shown in Figure 1.
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