Sharded IPLD Array
The Sharray is an IPLD tree structure used to store an array of items. It is designed for usecases that know all items at the time of creation and do not need insertion or deletion.
IPLD Representation
Each sharray node is represented by an IPLD node of the following schema:
Item
may be either a direct value, if height == 0
, or the Cid of a child node if height > 0
.
(For details on IPLD Schemas, see the IPLD Schema Spec (draft))
We use DAG-CBOR for serialization, and blake2b-256 for hashing.
Construction
The tree must not be sparse. Given an array of size N
and a fixed width of W
:
The left
floor(N/W)
leaves contain the firstN
items.If
N % W != 0
the final leaf contains the final remainder.The tree is perfectly balanced.
The height is the distance from the leaves, not the root.
Leaves (nodes with a height of 0) contain array values.
Inner nodes (nodes with height greater than zero) contain the cids of their child nodes.
Operations
create(items)
create(items)
Create a sharray from a given set of items
get(i)
get(i)
Get the element at index
i
Last updated