HashTree

"HashTree" (single canister CanDB only) - the data structure underlying SingleCanisterCanDB. A HashTree is a stable HashMap, which contains a HashTable storing a mapping of an Partition Key to RangeTree, where the RangeTree contains a mapping of an Entity's Sort Key to its Attributes

type HashTree = HM.StableHashMap<E.PK, RT.RangeTree>

A HashTree is a HashMap with keys being each Entity's Partition Key and Values being RangeTrees containing the Sort Key and Attributes of that particular Entity

public func init() : HashTree

Initializes a StableHashTree with initCapacity and table size zero

public func initPreSized(initCapacity : Nat) : HashTree

public func get(
  ht : HashTree,
  pk : E.PK,
  sk : E.SK
) : ?E.Entity

Gets an entity from the HashTree by pk + sk if that entity exists

public func put(ht : HashTree, entity : E.Entity) : ()

Insert/Replace an entity into the HashTree and returns nothing Mutates the underlying HashTree passed to this function

public func replace(ht : HashTree, entity : E.Entity) : ?E.Entity

Insert/Replace an entity into the HashTree and returns the previous value stored at the pk + sk if existed. Mutates the underlying HashTree passed to this function

public func update(
  ht : HashTree,
  pk : E.PK,
  sk : E.SK,
  updateFunction : (?E.AttributeMap) -> E.AttributeMap
) : ?E.Entity

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

Applies a function that takes null if the entity's pk + sk does not exist, or the current AttributeMap of an existing entity and returns a new AttributeMap that is used to update the attributes of the entity

public func delete(
  ht : HashTree,
  pk : E.PK,
  sk : E.SK
) : ()

Deletes an entity from the HashTree by pk/sk if that entity exists. Does not return any value Mutates the underlying HashTree passed to this function

public func remove(
  ht : HashTree,
  pk : E.PK,
  sk : E.SK
) : ?E.Entity

Deletes an entity from the HashTree by pk/sk if that entity exists, and returns the original value if that entity exists Mutates the underlying HashTree passed to this function

public func scan(
  ht : HashTree,
  pk : E.PK,
  skLowerBound : E.SK,
  skUpperBound : E.SK
) : [E.Entity]

Returns a range of entities that exactly match the provided pk, and are in between the sk lower and upper bounds (inclusive)

public func scanLimit(
  ht : HashTree,
  pk : E.PK,
  skLowerBound : E.SK,
  skUpperBound : E.SK,
  limit : Nat
) : ([E.Entity], ?E.SK)

Returns a limit specified range of entities in ascending order that exactly match the provided pk, and are in between the sk lower and upper bounds (inclusive)

public func scanLimitReverse(
  ht : HashTree,
  pk : E.PK,
  skLowerBound : E.SK,
  skUpperBound : E.SK,
  limit : Nat
) : ([E.Entity], ?E.SK)

Returns a limit specified range of entities in descending order that exactly match the provided pk, and are in between the sk lower and upper bounds (inclusive)

public func equal(ht1 : HashTree, ht2 : HashTree) : Bool

Return a boolean indicating if the two HashTrees are equivalent, ignoring deleted entries in the underlying RangeTree Red-Black Tree