Module Simantics/BTree

This module is undocumented. This is a list of its definitions.

bTreeOf :: Resource -> <ReadGraph> BTree

Opens a handle to the B-tree stored at the given resource, the resource that rootOfBTree returned when the tree was created. Requires a read transaction.

cachedBTreeOf :: Resource -> <ReadGraph> BTree

Like bTreeOf, but the handle keeps the nodes it touches in memory. Changes made through it reach the graph only when flushCachedBTree is called.

createBTree :: Integer -> Resource -> <WriteGraph> BTree

Creates a new empty B-tree in the graph and returns a handle to it. The integer is the minimum degree of the tree: every node other than the root holds between that many keys minus one and twice that many minus one, so a larger degree means fewer and larger nodes. The resource is the relation by which the tree attaches its nodes and the inserted values to their parent node.

Requires a write transaction. Use rootOfBTree to get the resource that has to be stored to find the tree again later.

createCachedBTree :: Integer -> Resource -> <WriteGraph> BTree

Like createBTree, but the tree keeps the nodes it touches in memory instead of writing each change out. This is much faster when many entries are inserted at once, but nothing reaches the graph until flushCachedBTree is called, and the handle must be kept for that call.

entriesOfBTree :: BTree -> <ReadGraph> [(Variant, Resource)]

All entries of the tree as key-value pairs, in ascending key order. Requires a read transaction.

flushCachedBTree :: BTree -> <WriteGraph> ()

Writes the pending changes of a cached tree into the graph. A tree opened with createCachedBTree or cachedBTreeOf keeps the nodes it touches in memory, so nothing it was told is in the database until this is called. Only call this for a cached tree. Requires a write transaction.

insertBTree :: BTree -> Variant -> Resource -> <WriteGraph> ()

Adds an entry mapping the given key to the given resource. Requires a write transaction.

Inserting does not replace: a key that is already in the tree gets a second entry, and both stay there. searchBTree then returns one of them and removeBTree deletes one of them, so a tree used as a map has to be kept free of duplicates by the caller.

removeBTree :: BTree -> Variant -> <WriteGraph> ()

Removes one entry with the given key. Does nothing if the tree has no such entry. Only the entry is removed; the resource it pointed to is left in the graph. Requires a write transaction.

rootOfBTree :: BTree -> Resource

The resource that represents the whole tree, the one bTreeOf takes. This is not the root node of the tree, despite the name.

searchBTree :: BTree -> Variant -> <ReadGraph> Maybe Resource

The resource stored under the given key, or Nothing if the tree has no entry with that key. If the key was inserted more than once, which of the entries is returned is not defined. Requires a read transaction.

searchRangeBTree :: BTree -> Maybe Variant -> Maybe Variant -> <ReadGraph> [(Variant, Resource)]

The entries whose key lies between the given bounds, in ascending key order. Both bounds are inclusive, and Nothing leaves that end unbounded. Requires a read transaction.