YggIndex.mesa
Copyright Ó 1988, 1989 by Xerox Corporation. All rights reserved.
Bob Hagmann January 3, 1989 4:08:08 pm PST
Index layer for Yggdrasil.
DIRECTORY
BTree USING [Tree],
BTreeVM USING [CacheSize, Handle],
IO USING [STREAM],
Rope USING [ROPE],
YggDID USING [DID],
YggEnvironment USING [nullTransID, TransID],
YggRep USING [TypedPrimitiveElement, unknown];
YggIndex: CEDAR DEFINITIONS
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
Index description
An index is maintained at some container. The index is for some attribute name. The index maps YggRep.TypedPrimitiveElement's to documents within the container with the TypedPrimitiveElement as one of its values for the attribute name. The indexed TypedPrimitiveElement may be a singleton or a member of a list of values.
Index: TYPE = REF IndexRep;
IndexRep: TYPE = RECORD [
backingStream: IO.STREAM,
realStream: IO.STREAM,
btreevmHandle: BTreeVM.Handle,
tree: BTree.Tree,
unused: BOOL ← FALSE
];
Access methods
Only key-based access methods are supported on an index. These are provided by btrees.
A sequence of database entries, sorted in btree order, can be accessed using either an enumerator or generator style of retrieval. Generators employ a cursor to indicate a logical position in the sequence being retrieved.
Cursor: TYPE = REF CursorRep;
CursorRep: TYPE = RECORD [
];
Basic operations
Open: PROC [did: YggDID.DID, fileUse: ATOM, cacheSize: BTreeVM.CacheSize, initialize: BOOLFALSE, trans: YggEnvironment.TransID ← YggEnvironment.nullTransID] RETURNS [index: Index];
Initiates indexing activity. This can be called any number of times to get a new Index handle or reopen an index that has been closed.
EntryProc: TYPE = PROC [value: YggRep.TypedPrimitiveElement, did: YggDID.DID] RETURNS [continue: BOOL];
EnumerateEntries: PROC [index: Index, start: YggRep.TypedPrimitiveElement ← [YggRep.unknown, NIL], end: YggRep.TypedPrimitiveElement ← [YggRep.unknown, NIL], proc: EntryProc];
Calls `proc' for each entry in the specified range of key values. The enumeration is halted when either the range of entries is exhausted or `proc' returns FALSE. An [unknown, NIL] value for `start' represents the least value, while an [unknown, NIL] value for `end' represents the largest value. Thus, the complete index can be enumerated by specifying start=[unknown, NIL] and end=[unknown, NIL].
GenerateEntries: PROC [index: Index, start: YggRep.TypedPrimitiveElement ← [YggRep.unknown, NIL], end: YggRep.TypedPrimitiveElement ← [YggRep.unknown, NIL]] RETURNS [cursor: Cursor];
Similar to EnumerateEntries, but creates a cursor so that entries in the specified range of key values can be retrieved using NextEntry (defined below). Initially, the cursor points to the start of the sequence. An [unknown, NIL] value for `start' represents the least attribute value, while an [unknown, NIL] value for `end' represents the largest attribute value. Thus, the complete index can be enumerated by specifying start=[unknown, NIL] and end=[unknown, NIL].
NextEntry: PROC [cursor: Cursor] RETURNS [value: YggRep.TypedPrimitiveElement, did: YggDID.DID];
Retrieves the next entry relative to the given cursor. The cursor, and thus the sequence of desired entries, must have been previously created by a call to GenerateEntries. The cursor is automatically updated so that NextEntry may be repeatedly called to enumerate entries. NIL is returned if the cursor is at the end of the sequence and dir=increasing or at the start of the sequence and dir=decreasing.
EndGenerate: PROC [cursor: Cursor];
Releases the cursor; no further operations may be performed using the given cursor. This must be called once for every call to GenerateEntries.
WriteEntry: PROC [index: Index, value: YggRep.TypedPrimitiveElement, did: YggDID.DID, replace: BOOLEANFALSE, trans: YggEnvironment.TransID] RETURNS [indexFound: BOOL];
Adds a new entry to the index.
DeleteEntry: PROC [index: Index, value: YggRep.TypedPrimitiveElement, did: YggDID.DID, trans: YggEnvironment.TransID] RETURNS [found: BOOLEAN];
Deletes the entry that contains the given attribute value for the given key.
Close: PROC [index: Index];
Terminates indexing activity.
END.