"RangeTree" - a stable Red-Black Tree for storing the relationship between an Entity's Sort Key and its Attributes
A RangeTree data structure is a Red-Black Tree 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) : RangeTree
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, RangeTree)
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 update(
rt : RangeTree,
sk : E.SK,
updateFunction : (?E.AttributeMap) -> E.AttributeMap
) : (?E.AttributeMap, RangeTree)
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) : RangeTree
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, RangeTree)
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
) : ([(E.SK, E.AttributeMap)], ?E.SK)
Performs a in-order scan of the RangeTree between the provided SortKey bounds, returning a number of matching entries in ascending order limited by the limit parameter specified in an array formatted as (SK, AttributeMap) for each entry
public func scanLimitReverse(
rt : RangeTree,
skLowerBound : E.SK,
skUpperBound : E.SK,
limit : Nat
) : ([(E.SK, E.AttributeMap)], ?E.SK)
Performs a reverse-order scan of the RangeTree between the provided SortKey bounds, returning a number of matching entries in descending order 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