func NewReadonlySet
NewReadonlySet returns a read-only view of s.
Package addrset provides a set of blockchain addresses backed by a B+ tree, with a read-only view type for safe cross...
Package addrset provides a set of blockchain addresses backed by a B+ tree, with a read-only view type for safe cross-realm exposure.
It mirrors the gno.land/p/moul/addrset API on a gno.land/p/nt/bptree/v0 backing: a B+ tree packs many entries per persisted node, so a stored address costs ~0.9 KB vs the one-node-per-entry AVL backing's ~2.0 KB (2.2x asymptotically, 1.6x at 10 entries; insert gas ~2.1x less). Prefer this package when sets are part of persisted realm state; the omitted Tree() escape hatch is deliberate, so the backing store never leaks.
Two behavioral differences from the AVL-backed moul package, both consequences of the in-place-mutating backing:
Example:
NewReadonlySet returns a read-only view of s.
ReadonlySet is a read-only view of a *Set. Cross-package callers cannot mutate the underlying set through this type: it exposes no mutator methods and holds the *Set in an unexported field, so a foreign realm can neither reach the set nor invoke Add/Remove on it.
A ReadonlySet is a thin handle over the live Set (it does not copy or snapshot), so reads through it always reflect the Set's current contents.
Has reports whether addr is in the underlying set.
1func (r ReadonlySet) IterateByOffset(offset, count int, fn func(addr address) bool) (stopped bool)IterateByOffset walks the underlying set in sorted order, starting at offset and visiting up to count addresses. fn returns true to stop early; IterateByOffset returns true if iteration was stopped that way.
The wrapped Set.IterateByOffset has no return value, so the "stopped" result is synthesized from the last callback return via a closure-captured local.
1func (r ReadonlySet) ReverseIterateByOffset(offset, count int, fn func(addr address) bool) (stopped bool)ReverseIterateByOffset is IterateByOffset in reverse (descending) order.
Size returns the number of addresses in the underlying set.
Set stores a set of addresses in sorted order. The zero value is an empty, usable set.
Add inserts an address into the set. Returns true if the address was newly added, false if it already existed.
Has checks if an address exists in the set.
IterateByOffset walks through addresses in sorted order, starting at the given offset and visiting up to count addresses. The callback returns true to stop iteration. The set must not be modified during iteration (no Add or Remove from the callback).
Readonly returns a read-only view of the set.
Remove deletes an address from the set. Returns true if the address was found and removed, false if it didn't exist.
ReverseIterateByOffset walks through addresses in reverse (descending) order, starting at the given offset (counted from the end) and visiting up to count addresses. The callback returns true to stop iteration. The set must not be modified during iteration (no Add or Remove from the callback).
Size returns the number of addresses in the set.