Class PSortedMap
java.lang.Object
ai.badmonkey.agentspaces.pdt.values.PSortedMap
The persistent sorted map of PD-V-10 (PDT 2 phase 2, P2-D-11; srad/agentspaces-pdt2.md §3.1.1):
a B+ tree over the
dn node layout with a pluggable comparator, read lazily through a
NodeLoader. An element is its own key, as a datom is in a DataScript index, so the
three indexes of a db root are instances of this map under the orders of
DatomOrder. A branch holds the largest key of each child in the order of its links, the
shape DataScript's sorted set writes, so a map written by either side reads on the other.
of(NodeStore, String, Comparator, int, List)builds a map from sorted elements with even leaves of at most the branching factor, so equal contents give equal roots;rootwrites the new nodes.seek(Datom)andcontains(Datom)read only the nodes on the path to their key.diff(PSortedMap)prunes every subtree whose CID both maps share, the walk-delta of §3.1.4, so its cost follows the change.
Values above 1 KiB leave their node as PDT 1 spills them (Spill); a read resolves
them, so an element in memory always holds its value. Edits stay with DataScript's own sorted
set in this release (decision 17); the kind s of a general key-value layout stays
reserved.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe elements one map holds and another does not. -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether an element equal under the comparator is in the map.longcount()The number of elements; reads every leaf.diff(PSortedMap other) The difference to another map of the same index and order (§3.1.4): both frontiers expand from the roots, the highest level first, and drop every CID they share, so a shared subtree is never read; the leaves left hold every changed element.iterator()Every element in order.static PSortedMapload(NodeStore store, NodeLoader loader, String index, Comparator<Datom> order, String root) A stored map, read on demand.static PSortedMapBuilds a map from elements in strictly increasing order: leaves of between half and all ofbranchingelements each (one leaf when fewer), then branches over them the same way.root()The root CID, writing the nodes of a build first.The elements from the first one not belowfrom, in order; the walk reads the nodes on the path to it and then each next leaf as the iteration reaches it.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
load
public static PSortedMap load(NodeStore store, NodeLoader loader, String index, Comparator<Datom> order, String root) A stored map, read on demand.- Parameters:
store- the store a later write goes toloader- the loader of cold nodesindex- thexevery node carriesorder- the comparator of the keysroot- the root CID- Returns:
- the map
-
of
public static PSortedMap of(NodeStore store, String index, Comparator<Datom> order, int branching, List<Datom> sorted) Builds a map from elements in strictly increasing order: leaves of between half and all ofbranchingelements each (one leaf when fewer), then branches over them the same way.- Parameters:
store- the storerootwrites toindex- thexevery node carriesorder- the comparator the elements followbranching- the most keys a node holds, at least 2sorted- the elements- Returns:
- the map; its nodes reach the store at
root - Throws:
IllegalArgumentException- when the elements are out of order or repeat
-
root
-
iterator
-
seek
-
contains
Whether an element equal under the comparator is in the map.- Parameters:
key- the element- Returns:
- true when held
-
count
public long count()The number of elements; reads every leaf. -
diff
The difference to another map of the same index and order (§3.1.4): both frontiers expand from the roots, the highest level first, and drop every CID they share, so a shared subtree is never read; the leaves left hold every changed element.- Parameters:
other- the other map- Returns:
- what this map holds alone and what the other holds alone
-