RangeTreeV2

"RangeTreeV2" - a wrapper around a stable BTree that stores the relationship between an Entity's Sort Key and its Attributes

type RangeTree = BT.BTree<E.SK, E.AttributeMap>

A RangeTree data structure is a BTree mapping of a Sort Key (Text) to an AttributeMap

public func init() : RangeTree

Initializes an empty RangeTree

public func get(rt : RangeTree, sk : E.SK) : ?E.AttributeMap

Returns an entry from the RangeTree based on the sk provided that sk exists in the RangeTree with a non-null AttributeMap

public func put(rt : RangeTree, entity : E.Entity) : ()

Creates or replaces an entry in the RangeTree based upon if the sk of the entity provided exists. Returns the new RangeTree

public func replace(rt : RangeTree, entity : E.Entity) : ?E.AttributeMap

Creates or replaces an entry in the RangeTree based upon if the sk of the entity provided exists. Returns the old AttributeMap if the sk existed and the new RangeTree

public func substituteKey(
  rt : RangeTree,
  oldKey : E.SK,
  newKey : E.SK
) : ?E.AttributeMap

public func update(
  rt : RangeTree,
  sk : E.SK,
  updateFunction : (?E.AttributeMap) -> E.AttributeMap
) : ?E.AttributeMap

Creates or updates an entry in the RangeTree based upon if the sk of the entity provided exists.

The updateFunction parameter applies a function that takes null if the entry does not exist, or the current AttributeMap of an existing entry and returns a new AttributeMap that is used to update the attributeMap entry.

public func delete(rt : RangeTree, sk : E.SK) : ()

Deletes an entry from the RangeTree based upon if the sk of the entity provided exists. Returns the new RangeTree

public func remove(rt : RangeTree, sk : E.SK) : ?E.AttributeMap

Deletes an entry from the RangeTree based upon if the sk of the entity provided exists. Returns the deleted AttributeMap if the sk existed and the new RangeTree

public func scanLimit(
  rt : RangeTree,
  skLowerBound : E.SK,
  skUpperBound : E.SK,
  limit : Nat,
  dir : Direction
) : BT.ScanLimitResult<E.SK, E.AttributeMap>

Performs a in-order scan of the RangeTree between the provided SortKey bounds, returning a number of matching entries in the direction specified, limited by the limit parameter specified in an array formatted as (SK, AttributeMap) for each entry

public func scan(
  rt : RangeTree,
  skLowerBound : E.SK,
  skUpperBound : E.SK
) : [(E.SK, E.AttributeMap)]

Not recommended that this is used because it's then more likely that a developer will run into the 2MB egress limit. A limit should therefore be enforced Performs a full scan of the RangeTree between the provided Sort Key bounds, returning an array of the matching (SK, AttributeMap) for each entry

public func entries(rt : RangeTree) : I.Iter<(E.SK, E.AttributeMap)>

Returns an iterator of all entries in the RangeTree

public func equal(rt1 : RangeTree, rt2 : RangeTree) : Bool

Performs an equality check between two RangeTrees

public func toText(rt : RangeTree) : Text.Text

Mostly for testing/debugging purposes, generates a textual representation of the RangeTree