Class PSortedMap

java.lang.Object
ai.badmonkey.agentspaces.pdt.values.PSortedMap
All Implemented Interfaces:
Iterable<Datom>

public final class PSortedMap extends Object implements Iterable<Datom>
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.

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.

  • 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 to
      loader - the loader of cold nodes
      index - the x every node carries
      order - the comparator of the keys
      root - 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 of branching elements each (one leaf when fewer), then branches over them the same way.
      Parameters:
      store - the store root writes to
      index - the x every node carries
      order - the comparator the elements follow
      branching - the most keys a node holds, at least 2
      sorted - the elements
      Returns:
      the map; its nodes reach the store at root
      Throws:
      IllegalArgumentException - when the elements are out of order or repeat
    • root

      public String root()
      The root CID, writing the nodes of a build first.
      Returns:
      the root
    • iterator

      public Iterator<Datom> iterator()
      Every element in order.
      Specified by:
      iterator in interface Iterable<Datom>
    • seek

      public Iterator<Datom> seek(Datom from)
      The elements from the first one not below from, in order; the walk reads the nodes on the path to it and then each next leaf as the iteration reaches it.
      Parameters:
      from - the lower bound, or null for the first element
      Returns:
      the iterator
    • contains

      public boolean contains(Datom key)
      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

      public PSortedMap.Delta 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.
      Parameters:
      other - the other map
      Returns:
      what this map holds alone and what the other holds alone