background image
C H A P T E R 1 1
Data Storage and Retrieval
About Data Storage on Newton Devices
11-11
Querying for Indexed Values
11
Queries can retrieve items according to the presence of one or more index keys and
can test key values as well. A query that tests for the presence or value of an index
key is called an index query.
Soups that have single-slot indexes allow queries to use a single index key to select
soup entries. Detailed information is provided in "Querying on Single-Slot
Indexes" beginning on page 11-39.
Soups that have multiple-slot indexes allow queries to use multiple index keys to
select soup entries. Detailed information is provided in "Querying on Multiple-Slot
Indexes" beginning on page 11-47.
Index queries can be based only on slot names for which an index has been generated.
For example, to select entries according to the presence of the
foo
slot, the soup
that receives the
Query
message must be indexed on the
foo
slot. Entries not
having a
foo
slot are not included in the set of entries referenced by the
foo
index.
Although the entries in the soup are not actually in any particular order themselves,
the index keys associated with them can be sorted in a specific order that is defined
for each NewtonScript data type. Thus, you can envision the contents of an index
as a sequence of entries arranged in key order, as shown in Figure 11-2.
Figure 11-2
An index provides random access and imposes order
The
aSoup
soup shown in Figure 11-2 is indexed on the
foo
slot, which means
that the value of each entry's
foo
slot is used as its index key. Only those entries
containing a
foo
slot are included in this index. By sorting key values, the index
imposes order on their corresponding soup entries, which are otherwise unordered.
2 3 4 5
Ascending key order
Descending key order
Index on
foo
slot
Store
Soup
1
4
2
3
5
6
{foo:
, ...
}
{foo:
, ...
}
{foo:
, ...
}
{foo:
, ...
}
{bar:
, ...
}
{bar:
, ...
}
© 2007-2024, o7 studio » при воспроизведении материала сайта ссылка обязательна