Collections API Reference
This page documents the public API of openzeppelin_collections for OpenZeppelin Contracts for Sui v1.x.
use openzeppelin_collections::sorted_map;A generic, ordered key-value map with O(log N) lookup and ordered navigation (head/tail, floor/ceiling, next key, sorted pages). Every operation loads exactly one stored object, so capacity is bounded by Sui's object size limit (~250 KB), not by any per-transaction dynamic-field cap. SortedMap<K, V> is a UID-less value shaped like sui::vec_map::VecMap, with no identity of its own or dynamic fields, so you embed it in your own has key object and gate access with your own entry functions. The module emits no events.
The API splits into bare and _by forms. Bare macros (upsert!, borrow!, ...) assume the built-in integer < and compile only for integer keys; _by macros take a strict less-than comparator lambda and are required for address, struct, or any other non-integer key. Values only need store, so a resource V like Coin<T> is supported. Such a map cannot be dropped; drain every value via remove!/pop_front/pop_back, then call destroy_empty.
The map stores no comparator. Ordering is defined per call by the strict less-than lambda you supply, and it MUST be a strict total order threaded consistently to every call on a given map. The library cannot detect a violation, and the failure is silent: a non-strict <= causes duplicate inserts and missed lookups/removes, and mixing < with > across calls corrupts order. In tests, call is_well_formed_by! after a _by sequence to catch comparator mistakes.
Types
Functions
new()singleton(key, value)destroy_empty(map)length(map)is_empty(map)head(map)tail(map)pop_front(map)pop_back(map)keys(map)
Macros
from_sorted_keys_values_by!(keys, values, lt)from_sorted_keys_values!(keys, values)contains_by!(map, key, lt)contains!(map, key)borrow_by!(map, key, lt)borrow!(map, key)borrow_mut_by!(map, key, lt)borrow_mut!(map, key)add_by!(map, key, value, lt)add!(map, key, value)upsert_by!(map, key, value, lt)upsert!(map, key, value)remove_by!(map, key, lt)remove!(map, key)find_next_by!(map, key, include, lt)find_next!(map, key, include)find_prev_by!(map, key, include, lt)find_prev!(map, key, include)next_key_by!(map, key, lt)next_key!(map, key)prev_key_by!(map, key, lt)prev_key!(map, key)keys_from_by!(map, from, include, limit, lt)keys_from!(map, from, include, limit)is_well_formed_by!(map, lt)is_well_formed!(map)
Errors
Types
struct Entry<K, V>
struct
#One key-value pair, stored inline in the map's vector. Its fields are private; read them through the forced-public key/value accessors if a macro body requires it.
Abilities materialize jointly over K and V: Entry<u64, u64> is copy + drop + store, while Entry<u64, Coin<T>> is store-only.
struct SortedMap<K, V>
struct
#A map kept sorted by key. Every operation loads exactly one stored object, so it is bounded by object size (~250 KB), not by any per-transaction dynamic-field cap; lookup is O(log N) and writes are O(N).
A pure value with no UID or dynamic fields, so it embeds directly in an integrator's object, exactly like sui::vec_map::VecMap. copy/drop materialize only when both K and V allow them: SortedMap<u64, u64> is copy + drop + store; SortedMap<u64, Coin<T>> is store-only and must be drained then destroy_empty'd.
Across the supported (macro) API the backing vector is strictly increasing under the consistently supplied comparator: sorted, with no duplicate keys.
Functions
new<K, V>() -> SortedMap<K, V>
public
#Creates a new, empty map. Takes no &mut TxContext: a SortedMap is a value, not an object.
singleton<K, V>(key: K, value: V) -> SortedMap<K, V>
public
#Creates a map holding a single key/value entry. O(1); needs no comparator, since one entry is trivially sorted. For more than one entry from pre-sorted data, use from_sorted_keys_values!.
destroy_empty<K, V>(map: SortedMap<K, V>)
public
#Destroys an empty map. This is the only terminal for a map whose value type lacks drop (e.g. SortedMap<K, Coin<T>>): drain every value via remove!/pop_front/pop_back first, then call this.
Aborts with ENotEmpty if the map still holds entries.
length<K, V>(map: &SortedMap<K, V>) -> u64
public
#Returns the number of entries.
is_empty<K, V>(map: &SortedMap<K, V>) -> bool
public
#Returns true iff the map holds no entries.
head<K: copy, V>(map: &SortedMap<K, V>) -> Option<K>
public
#Returns the smallest key under the comparator, or none if the map is empty. O(1). With a reverse comparator this returns the largest numeric key.
tail<K: copy, V>(map: &SortedMap<K, V>) -> Option<K>
public
#Returns the largest key under the comparator, or none if the map is empty. O(1).
pop_front<K, V>(map: &mut SortedMap<K, V>) -> (K, V)
public
#Removes and returns the smallest entry as a (key, value) pair. O(N), as it shifts every remaining entry; prefer pop_back for bulk drains, which is O(1).
Aborts with EEmpty if the map is empty.
pop_back<K, V>(map: &mut SortedMap<K, V>) -> (K, V)
public
#Removes and returns the largest entry as a (key, value) pair. O(1) (no shift).
Aborts with EEmpty if the map is empty.
keys<K: copy, V>(map: &SortedMap<K, V>) -> vector<K>
public
#Returns all keys in ascending comparator order as an owned vector<K>. O(N) in output size with no limit; for large or near-ceiling maps prefer the paged keys_from!. Loads exactly one stored object regardless of N.
Macros
from_sorted_keys_values_by!<$K, $V>(keys: vector<$K>, values: vector<$V>, lt: |&$K, &$K| -> bool) -> SortedMap<$K, $V>
macro
#Builds a map from parallel keys/values that MUST already be strictly increasing under lt (sorted, no duplicate keys). O(n): one pass validates each adjacent pair, then appends at the back without a per-element search. Prefer this to a loop of upsert_by!, which is O(n^2) for unsorted input. If your keys are not yet ordered, sort them under the same comparator first, then call this.
Unlike sorted_set::from_keys! (which de-duplicates), this aborts on any out-of-order or duplicate key: values are conserved (a resource V can never be silently displaced), so a duplicate cannot be collapsed away.
Aborts with EUnequalLengths if keys and values differ in length.
Aborts with EKeysNotStrictlyIncreasing if keys is not strictly increasing under lt.
from_sorted_keys_values!<$K, $V>(keys: vector<$K>, values: vector<$V>) -> SortedMap<$K, $V>
macro
#from_sorted_keys_values_by! with the built-in integer <.
Aborts with EUnequalLengths or EKeysNotStrictlyIncreasing; see from_sorted_keys_values_by!.
contains_by!<$K, $V>(map: &SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> bool
macro
#Returns true iff key is present, under lt. Pure, total read: agrees exactly with borrow_by! succeeding, since both route through the same binary search.
contains!<$K, $V>(map: &SortedMap<$K, $V>, key: &$K) -> bool
macro
#contains_by! with the built-in integer <.
borrow_by!<$K, $V>(map: &SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> &$V
macro
#Immutably borrows key's value, under lt. There is deliberately no non-aborting Option<&V> variant (Move cannot put a reference in an Option); use contains_by! first when the key may be absent.
Aborts with EKeyNotFound if key is absent.
borrow!<$K, $V>(map: &SortedMap<$K, $V>, key: &$K) -> &$V
macro
#borrow_by! with the built-in integer <.
Aborts with EKeyNotFound if key is absent.
borrow_mut_by!<$K, $V>(map: &mut SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> &mut $V
macro
#Mutably borrows key's value, under lt. Yields &mut V, never a mutable entry reference, so the key cannot be desynced from its sorted position.
Aborts with EKeyNotFound if key is absent.
borrow_mut!<$K, $V>(map: &mut SortedMap<$K, $V>, key: &$K) -> &mut $V
macro
#borrow_mut_by! with the built-in integer <.
Aborts with EKeyNotFound if key is absent.
add_by!<$K, $V>(map: &mut SortedMap<$K, $V>, key: $K, value: $V, lt: |&$K, &$K| -> bool)
macro
#Inserts key/value under lt, aborting if key is already present (length + 1). key is taken by value and moved into storage; nothing is returned.
Matches sui::vec_map::insert: a strict insert that refuses to touch an existing entry, so a duplicate is always a caller bug rather than a silent overwrite. Use upsert_by! instead when replacing an existing value is the intended behavior; it returns the displaced value rather than aborting.
Aborts with EKeyAlreadyExists if key is already present.
add!<$K, $V>(map: &mut SortedMap<$K, $V>, key: $K, value: $V)
macro
#add_by! with the built-in integer <.
Aborts with EKeyAlreadyExists if key is already present.
upsert_by!<$K: drop, $V>(map: &mut SortedMap<$K, $V>, key: $K, value: $V, lt: |&$K, &$K| -> bool) -> Option<$V>
macro
#Inserts key/value, or replaces the value if key is already present, under lt. Returns some(old_value) on replace (length unchanged), none on a fresh insert (length + 1). The displaced value is returned and never dropped, so a resource V is safe; K must be drop only because the previously stored key is dropped on replace (last-write-wins for the key bytes, observable only under a coarse comparator).
This is a deliberate divergence from sui::vec_map::insert, which aborts on a duplicate key: upsert_by! is a total upsert. For abort-on-duplicate, prefer add! (a strict insert); or, when V has drop, assert on the returned option (assert!(m.upsert!(k, v).is_none(), E)). For a resource V the returned option cannot be dropped, so bind it, assert is_none(), and consume it with destroy_none().
upsert!<$K: drop, $V>(map: &mut SortedMap<$K, $V>, key: $K, value: $V) -> Option<$V>
macro
#upsert_by! with the built-in integer <. Returns some(old) on replace, none on a fresh insert.
remove_by!<$K, $V>(map: &mut SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> ($K, $V)
macro
#Removes key's entry and returns the removed (key, value) tuple, under lt (length - 1, order preserved). Both the key and the value are returned, so a non-drop key or resource value is conserved, not destroyed.
Aborts with EKeyNotFound if key is absent.
remove!<$K, $V>(map: &mut SortedMap<$K, $V>, key: &$K) -> ($K, $V)
macro
#remove_by! with the built-in integer <.
Aborts with EKeyNotFound if key is absent.
find_next_by!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, include: bool, lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the smallest key >= key when include (the ceiling), else the smallest key > key (strict next); none if there is no such key. Pure, total read. Any returned key satisfies contains_by!.
find_next!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, include: bool) -> Option<$K>
macro
#find_next_by! with the built-in integer <.
find_prev_by!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, include: bool, lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the largest key <= key when include (the floor), else the largest key < key (strict prev); none if there is no such key. Pure, total read. Any returned key satisfies contains_by!.
find_prev!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, include: bool) -> Option<$K>
macro
#find_prev_by! with the built-in integer <.
next_key_by!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the smallest key strictly greater than key, or none. Sugar for find_next_by! with include = false. next_key! of the tail returning none is the forward-cursor termination signal.
next_key!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K) -> Option<$K>
macro
#next_key_by! with the built-in integer <.
prev_key_by!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K, lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the largest key strictly less than key, or none. Sugar for find_prev_by! with include = false. prev_key! of the head returning none is the backward-cursor termination signal.
prev_key!<$K: copy, $V>(map: &SortedMap<$K, $V>, key: &$K) -> Option<$K>
macro
#prev_key_by! with the built-in integer <.
keys_from_by!<$K: copy, $V>(map: &SortedMap<$K, $V>, from: &$K, include: bool, limit: u64, lt: |&$K, &$K| -> bool) -> vector<$K>
macro
#Returns up to limit keys in strict ascending order: a contiguous run starting at the first key >= from (when include) or > from (strict). Returns at most limit keys; fewer if the tail is reached.
Resume a page by passing the last returned key back as from with include == false: successive pages have no overlap and no gap, so concatenating them reconstructs the tail exactly. limit == 0, an empty map, or from past the tail all yield the empty vector. There is no descending pagination; use a reverse comparator.
keys_from!<$K: copy, $V>(map: &SortedMap<$K, $V>, from: &$K, include: bool, limit: u64) -> vector<$K>
macro
#keys_from_by! with the built-in integer <.
is_well_formed_by!<$K, $V>(map: &SortedMap<$K, $V>, lt: |&$K, &$K| -> bool) -> bool
macro
#Returns true iff the map's entries are strictly increasing under lt, meaning sorted with no duplicate keys. This is the order check for tests, directly re-verifying the sorted-order property that production code maintains by construction but never re-validates. Call it after a _by sequence to catch a comparator mistake. Returns bool rather than asserting, so callers compose it into their own assertions.
#[test_only]: absent from published bytecode and not callable from production consumer code, but visible to a dependent's test code.
is_well_formed!<$K, $V>(map: &SortedMap<$K, $V>) -> bool
macro
#is_well_formed_by! with the built-in integer <. #[test_only].
Errors
EKeyNotFound
error
#A key was not present in the map. Raised by borrow!/borrow_mut!/remove! (and their _by forms) on an absent key.
ENotEmpty
error
#destroy_empty was called on a non-empty map.
EEmpty
error
#pop_front/pop_back was called on an empty map.
EKeysNotStrictlyIncreasing
error
#A bulk constructor (from_sorted_keys_values!/_by) received keys that are not strictly increasing under the comparator (out of order, or a duplicate).
EUnequalLengths
error
#A bulk constructor (from_sorted_keys_values!/_by) received keys and values of different lengths.
EKeyAlreadyExists
error
#A key was already present in the map. Raised by add!/add_by! on a duplicate key.
Internal helpers
Move 2024 macro hygiene requires every symbol a macro body references to be public at the consumer's expansion site, so the following helpers are public but are NOT part of the supported API. In particular, insert_at/remove_at write at a caller-given index with no ordering check, so calling them directly can silently corrupt sorted order and invalidate every subsequent lookup, insertion, and removal. Use the macro API instead.
Forced-public internals: search!, entries, key, value, insert_at, remove_at, value_at, value_at_mut, assert_key_found, assert_key_absent, assert_equal_lengths, assert_strictly_increasing.
use openzeppelin_collections::sorted_set;A generic, ordered set of unique keys that iterates in comparator order, filling the gap sui::vec_set leaves. SortedSet<K> is a thin wrapper over SortedMap<K, Unit> (a set is a map whose values carry no information, exactly as BTreeSet<K> = BTreeMap<K, ()> in Rust). It is a UID-less value with every key inline in one vector; a bare set is not key, so embed it in your own has key object. Because the value is always the trivial copy + drop + store Unit, SortedSet<K> has exactly the abilities K does.
The set stores no comparator. Order is defined per call by a strict less-than lambda lt you supply, and it must be the same strict total order on every call for a given set. The library cannot detect a violation. An inconsistent or non-strict comparator desorts the set (wrong membership answers, though no key's bytes are lost and all keys remain recoverable via keys); a coarse (non-injective) comparator collapses byte-distinct compare-equal keys into one element, keeping the last-written key's bytes. The bare (non-_by) macros use the built-in integer < and remove the footgun for integer keys.
upsert! returns bool and never aborts on a duplicate (diverging from sui::vec_set::insert); add! is the strict counterpart that aborts on a duplicate, and remove! aborts on an absent key, matching vec_set. Costs mirror the wrapped map: O(log N) membership, O(N) insert/remove, exactly one stored-object access per operation, and the same ~250 KB object-size ceiling. The module emits no events. A UID-less value has no on-chain identity, so emit events from your own entry functions.
Types
Functions
new()singleton(key)destroy_empty(set)length(set)is_empty(set)head(set)tail(set)pop_front(set)pop_back(set)keys(set)
Macros
from_keys_by!(keys, lt)from_keys!(keys)from_sorted_keys_by!(keys, lt)from_sorted_keys!(keys)contains_by!(set, key, lt)contains!(set, key)add_by!(set, key, lt)add!(set, key)upsert_by!(set, key, lt)upsert!(set, key)remove_by!(set, key, lt)remove!(set, key)find_next_by!(set, key, include, lt)find_next!(set, key, include)find_prev_by!(set, key, include, lt)find_prev!(set, key, include)next_key_by!(set, key, lt)next_key!(set, key)prev_key_by!(set, key, lt)prev_key!(set, key)keys_from_by!(set, from, include, limit, lt)keys_from!(set, from, include, limit)
Errors
Types
struct Unit
struct
#Internal membership marker so a set can reuse SortedMap<K, Unit>. A zero-field empty struct carrying no data; it serializes to 1 BCS byte and has nothing to read or destructure.
Declared copy, drop, store so SortedSet<K> has exactly the abilities K does. It is public only because it appears in the forced-public accessors' signatures (macro hygiene); consumers never construct it or read it. Its layout is frozen at first publish and must stay a zero-field empty struct.
struct SortedSet<K>
struct
#An ordered set of unique keys, backed by one sorted vector via SortedMap<K, Unit>.
A pure value with no UID or dynamic fields, so it embeds directly in an integrator's object, exactly like sui::vec_set::VecSet. Because the value is always the copy + drop + store Unit, SortedSet<K> has exactly the abilities K does: with a copy + drop + store key it is copy + drop + store; with a non-drop (e.g. resource) key it is store-only and must be drained then destroy_empty'd.
Across every public operation, the keys are strictly increasing under the (consistently supplied) comparator: sorted, no duplicates.
Functions
new<K>() -> SortedSet<K>
public
#Creates a new, empty set. Takes no &mut TxContext: a SortedSet is a value, not an object. length is 0 and is_empty is true.
singleton<K>(key: K) -> SortedSet<K>
public
#Returns a set containing exactly the one given key.
destroy_empty<K>(set: SortedSet<K>)
public
#Destroys an empty set.
Only needed when K lacks drop (e.g. a resource key): such a SortedSet<K> is itself non-drop and cannot fall out of scope, so drain every key via remove!/pop_front/pop_back first, then call this. A set of droppable keys never needs it.
Aborts with ENotEmpty if the set still holds keys. The abort fires at this module's location, not the wrapped map's.
length<K>(set: &SortedSet<K>) -> u64
public
#Returns the number of distinct keys.
is_empty<K>(set: &SortedSet<K>) -> bool
public
#Returns true iff the set holds no keys.
head<K: copy>(set: &SortedSet<K>) -> Option<K>
public
#Returns the smallest key under the comparator, or none if the set is empty. O(1). With a reverse comparator this is the largest numeric key.
tail<K: copy>(set: &SortedSet<K>) -> Option<K>
public
#Returns the largest key under the comparator, or none if the set is empty. O(1).
pop_front<K>(set: &mut SortedSet<K>) -> K
public
#Removes and returns the smallest key. Length decreases by 1. O(N): it shifts every remaining entry (pop_back is O(1)), so a front-heavy drain loop is quadratic.
Aborts with EEmpty if the set is empty, at this module's location (the wrapped map's EEmpty is never reached through here).
pop_back<K>(set: &mut SortedSet<K>) -> K
public
#Removes and returns the largest key. Length decreases by 1. O(1).
Aborts with EEmpty if the set is empty, at this module's location (the wrapped map's EEmpty is never reached through here).
keys<K: copy>(set: &SortedSet<K>) -> vector<K>
public
#Returns all keys in strict ascending (comparator) order as an owned, sorted, and duplicate-free vector<K>. Not a reference: the set stores Entry<K, Unit> internally, so there is no vector<K> to borrow (contrast vec_set::keys).
O(N) in output size with no limit; this is the one read whose result scales with N. For large or near-ceiling sets, prefer the paged keys_from!.
Macros
from_keys_by!<$K: drop>($keys: vector<$K>, $lt: |&$K, &$K| -> bool) -> SortedSet<$K>
macro
#Builds a set from a vector of keys by idempotent insertion, under $lt. O(N^2) (one search per key). Duplicates are silently collapsed; the result holds each distinct key once, in comparator order, so the result's length is the number of distinct keys, not the input length. This diverges from sui::vec_set::from_keys, which aborts on a duplicate; to reject duplicates instead, build then assert length equals the input length.
Under a coarse (non-injective) comparator, byte-distinct compare-equal keys collapse to one element keeping the last one's bytes (each re-insert is a last-write-wins upsert).
from_keys!<$K: drop>($keys: vector<$K>) -> SortedSet<$K>
macro
#from_keys_by! with the built-in integer <. De-duplicates; see from_keys_by!. Returns a set of the distinct keys, in ascending order.
from_sorted_keys_by!<$K: copy + drop>($keys: vector<$K>, $lt: |&$K, &$K| -> bool) -> SortedSet<$K>
macro
#Builds a set from keys that are already sorted (non-decreasing) under $lt. O(N): one pass validates each adjacent pair and appends at the back without a per-element search, so prefer this over the O(N^2) from_keys! when the input is pre-sorted.
De-duplicates exactly like from_keys!: a run of compare-equal keys collapses to one element, keeping the last key's bytes (observable only under a coarse, non-injective comparator), matching upsert!'s last-write-wins rule. A set has no value to lose, so a duplicate collapses rather than aborts, diverging from the map's from_sorted_keys_values!, which aborts on a duplicate to conserve values. The only rejection is genuinely unsorted input; if your keys are not yet ordered, use from_keys! or sort them first.
Aborts with EKeysNotSorted if keys has an adjacent pair not sorted under lt (a strictly decreasing pair), at this module's location.
from_sorted_keys!<$K: copy + drop>($keys: vector<$K>) -> SortedSet<$K>
macro
#from_sorted_keys_by! with the built-in integer <. De-duplicates; see from_sorted_keys_by!. Returns a set of the distinct keys, in ascending order.
Aborts with EKeysNotSorted if keys is not ascending.
contains_by!<$K>($set: &SortedSet<$K>, $key: &$K, $lt: |&$K, &$K| -> bool) -> bool
macro
#Returns true iff key is present, under $lt. Pure, total read (never aborts). O(log N).
contains!<$K>($set: &SortedSet<$K>, $key: &$K) -> bool
macro
#contains_by! with the built-in integer <. Returns true iff key is present.
add_by!<$K>($set: &mut SortedSet<$K>, $key: $K, $lt: |&$K, &$K| -> bool)
macro
#Inserts key, under $lt, aborting if it is already present (length + 1; contains!(key) flips false to true). Nothing is returned. The strict counterpart to the total upsert_by!: this matches sui::vec_set::insert, which also aborts on a duplicate, so a duplicate is a caller bug rather than a silent no-op. Use upsert!/upsert_by! when a duplicate should be absorbed silently (and reported via the returned bool) instead of aborting.
Aborts with sorted_map::EKeyAlreadyExists if key is already present (delegated: the abort fires at the wrapped map's location).
add!<$K>($set: &mut SortedSet<$K>, $key: $K)
macro
#add_by! with the built-in integer <.
Aborts with sorted_map::EKeyAlreadyExists if key is already present.
upsert_by!<$K: drop>($set: &mut SortedSet<$K>, $key: $K, $lt: |&$K, &$K| -> bool) -> bool
macro
#Inserts key, under $lt. Idempotent and total (never aborts); key is taken by value. On a fresh insert: length + 1 and contains!(key) flips false to true. On a duplicate: length unchanged, but the stored key is overwritten with this one (last-write-wins for the key bytes, observable only under a coarse comparator). Returns true iff the key was newly added, false if it was already present.
Diverges from vec_set::insert (which aborts on a duplicate); for that behavior call add!, or assert on the returned bool.
upsert!<$K: drop>($set: &mut SortedSet<$K>, $key: $K) -> bool
macro
#upsert_by! with the built-in integer <. Returns true iff the key was newly added.
remove_by!<$K>($set: &mut SortedSet<$K>, $key: &$K, $lt: |&$K, &$K| -> bool) -> $K
macro
#Removes key, under $lt, and returns the removed key. On success: length - 1 and contains!(key) flips true to false. Matches vec_set::remove, which also aborts when the key is absent.
Aborts with sorted_map::EKeyNotFound if key is absent (delegated: the abort fires at the wrapped map's location).
remove!<$K>($set: &mut SortedSet<$K>, $key: &$K) -> $K
macro
#remove_by! with the built-in integer <. Returns the removed key.
Aborts with sorted_map::EKeyNotFound if key is absent.
find_next_by!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $include: bool, $lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the smallest key >= key when include is true (the ceiling), else the smallest key > key (strict next); none if there is no such key. Pure, total read; any returned key satisfies contains!.
find_next!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $include: bool) -> Option<$K>
macro
#find_next_by! with the built-in integer <. Returns the ceiling/strict-next key, or none.
find_prev_by!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $include: bool, $lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the largest key <= key when include is true (the floor), else the largest key < key (strict prev); none if there is no such key. Pure, total read; any returned key satisfies contains!.
find_prev!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $include: bool) -> Option<$K>
macro
#find_prev_by! with the built-in integer <. Returns the floor/strict-prev key, or none.
next_key_by!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the smallest key strictly greater than key, or none. Sugar for find_next_by! with include == false. next_key! of the tail returning none is the forward-cursor termination signal.
next_key!<$K: copy>($set: &SortedSet<$K>, $key: &$K) -> Option<$K>
macro
#next_key_by! with the built-in integer <. Returns the strict-next key, or none.
prev_key_by!<$K: copy>($set: &SortedSet<$K>, $key: &$K, $lt: |&$K, &$K| -> bool) -> Option<$K>
macro
#Returns the largest key strictly less than key, or none. Sugar for find_prev_by! with include == false. prev_key! of the head returning none is the backward-cursor termination signal.
prev_key!<$K: copy>($set: &SortedSet<$K>, $key: &$K) -> Option<$K>
macro
#prev_key_by! with the built-in integer <. Returns the strict-prev key, or none.
keys_from_by!<$K: copy>($set: &SortedSet<$K>, $from: &$K, $include: bool, $limit: u64, $lt: |&$K, &$K| -> bool) -> vector<$K>
macro
#Returns up to limit keys in strict ascending order: a contiguous run starting at the first key >= from (when include) or > from (strict); fewer than limit only at the tail. Resume a page by passing the last returned key back as from with include == false: successive pages have no overlap and no gap. limit == 0, an empty set, or from past the tail all yield the empty vector.
keys_from!<$K: copy>($set: &SortedSet<$K>, $from: &$K, $include: bool, $limit: u64) -> vector<$K>
macro
#keys_from_by! with the built-in integer <. Returns up to limit keys in ascending order.
Errors
EEmpty
error
#Raised when pop_front/pop_back is called on an empty set. Asserted at this module's location, distinct from the wrapped map's EEmpty.
EKeysNotSorted
error
#Raised when a sorted constructor (from_sorted_keys!/from_sorted_keys_by!) receives keys that are not sorted under the comparator, meaning a strictly decreasing adjacent pair. Asserted at this module's location.
ENotEmpty
error
#Raised when destroy_empty is called on a set that still holds keys. Asserted at this module's location, distinct from the wrapped map's ENotEmpty.
Internal helpers
The functions inner, inner_mut, unit, and assert_sorted are public only because Move 2024 macro hygiene requires every symbol a macro body references to be public at the consumer's expansion site. They are not part of the supported API. In particular, inner_mut hands out &mut SortedMap<K, Unit>: driving map operations on it directly with an inconsistent comparator (or insert_at/remove_at at a wrong index) can desort the set and invalidate every subsequent lookup, insertion, and removal. The corruption is order-only and local to that one set; no value is ever lost. Use the macro API instead.