system.interfaces.indexing.Index module

Abstract indexing interfaces: Index, key-value store, B-tree, and point/range/predicate query mix-ins.

class system.interfaces.indexing.Index.IndexProperties(attribute: str, operator: str)[source]

Bases: object

A class representing metadata of an index.

attribute: str
operator: str
class system.interfaces.indexing.Index.PutInfo[source]

Bases: object

Optional information returned by Index.put() describing the effect of an insertion.

Placeholder base class carrying no fields; implementations may subclass it to report details such as whether a split occurred or which node was affected.

class system.interfaces.indexing.Index.Index[source]

Bases: ABC, Generic

An API representing an index.

abstractmethod size() → int[source]

Returns the number of keys mapped by this index.

abstractmethod put(key: Key, value: Value) → None | PutInfo[source]

Adds (puts) a new key->value mapping into the store.

Note that the value should be copied in your implementation before it is stored in the store to avoid accidental modifications of the value outside the index.

Parameters:
  • key – the key

  • value – the value to associate with the key

Returns:

None or a PutInfo object

abstractmethod delete(key: Key, value: Value = None) → None[source]

Deletes the key->value mapping from the index.

Parameters:
  • key – the key

  • value – the value to delete

abstractmethod flush(key: Key | None = None) → None[source]

Persists all changes, i.e. any changes done so far in volatile memory only are now made durable.

Parameters:

key – if given, only the key/value pair is flushed, otherwise all key/value-mappings are flushed.

bulkload(input_data: Iterator[tuple[Key, Value]]) → None[source]

Bulkloads the given list of key->value mappings into the index.

Notice that we DO copy the values, so modifying them outside the index will NOT accidentally affect the data in the index.

Parameters:

input_data – an iterator of key-values pairs to be loaded into the index; in this implementation, for each pair (key, value), we simply call put(key, value) to add the key-value pair to the index.

abstractmethod show() → None[source]

Shows the content of the index.

class system.interfaces.indexing.Index.PointQueryMixIn[source]

Bases: ABC, Generic

An interface mixing in point queries.

abstractmethod get(key: Key) → Iterator[source]

Returns the values associated with the given key as in iterator. Note that the iterator is NOT STABLE, i.e. it may change if the underlying data changes concurrently.

Parameters:

key – the key

Returns:

an iterator of the values associated with the given key

class system.interfaces.indexing.Index.RangeQueryMixIn[source]

Bases: ABC, Generic

An interface mixing in range queries.

abstractmethod get_all_in_range(min_key: Key, max_key: Key) → Iterator[source]

Returns all values whose key lies in the range [min_key, max_key] (both bounds inclusive). Note that the iterator is NOT STABLE, i.e. it may change if the underlying data changes concurrently.

Parameters:
  • min_key – the minimum key including

  • max_key – the maximum key including

Returns:

an iterator of values

class system.interfaces.indexing.Index.PredicateQueryMixIn[source]

Bases: ABC, Generic

An interface mixing in predicate queries.

abstractmethod get_all(where: Clause) → Iterator[source]

Returns all values that satisfy the given where clause. Note that the iterator is NOT STABLE, i.e. it may change if the underlying data changes concurrently.

Parameters:

where – the condition

Returns:

an iterator of values

class system.interfaces.indexing.Index.KeyValueStore[source]

Bases: Index, PointQueryMixIn, ABC, Generic

An interface for an index additionally supporting point queries.

class system.interfaces.indexing.Index.AbstractBTree[source]

Bases: KeyValueStore, RangeQueryMixIn, ABC, Generic

An abstract class representing a B-Tree, i.e. an index supporting both point and range queries.