refs.set
Virtuals set reference: unordered unique-element container backed by a View.
Module nustd.kv.refs.set.
Virtuals set reference: unordered unique-element container backed by a View.
| Name | Sort | Call | Meaning |
|---|---|---|---|
| SetRef | ref | SetRef(address, item_type, view_type, parent_ref=None, owner_shape=None) | A set slot in KV storage: unordered, unique elements, stored decomposed. |
SetRef
A set slot in KV storage: unordered, unique elements, stored decomposed.
SetRef(address, item_type, view_type, parent_ref=None, owner_shape=None)Path nustd.kv.SetRef. Kind Ref, sort ref, cardinality scalar.
Notes
- Ops run against the live View, so membership and size are answered by storage rather than by reading the set out.
- Elements have no addresses of their own to descend into: a set has no keys, so there is no element ref and no subscript.
- The set algebra (
union,intersection, ...) yields values; the in-place variants (update,difference_update, ...) are the ones that write. - Change observation covers the child, the children and the whole subtree, each with its own hook.
- PrimitiveSetRef is the other choice: one opaque blob written whole.
Example
class Portfolio(Shape):
members = SetRef.slot(str)
run(Portfolio.members.add("gor"), ctx)
run(Portfolio.members.contains("gor"), ctx)Inherited methods
From nu.forms.collections.abc.set_.ReactiveSetForm:
| Call | Builds | Meaning |
|---|---|---|
.on_change() | object | Subscribe to any change on this set slot. |
From nu.forms.collections.abc.set_.MutableSetForm:
| Call | Builds | Meaning |
|---|---|---|
.add(value) | Any | Add value to self. |
.remove(value) | Any | Remove value from self. |
.discard(value) | Any | Remove value from self if present. |
.pop() | ElementResultT | Remove and return an arbitrary element from self. |
.clear() | Any | Remove every element from self. |
.update(other) | Any | Add every element of other to self. |
.intersection_update(other) | Any | Keep only the elements of self also found in other. |
.difference_update(other) | Any | Remove every element of other from self. |
.symmetric_difference_update(other) | Any | Keep the elements in exactly one of self and other. |
From nu.forms.collections.abc.set_.SetLikeForm:
| Call | Builds | Meaning |
|---|---|---|
.union(other) | CollectionResultT | Union of self and other. |
.intersection(other) | CollectionResultT | Intersection of self and other. |
.difference(other) | CollectionResultT | Elements of self that are not in other. |
.symmetric_difference(other) | CollectionResultT | Elements in exactly one of self and other, not both. |
.issubset(other) | Bool | Whether every element of self is in other. |
.issuperset(other) | Bool | Whether every element of other is in self. |
.isdisjoint(other) | Bool | Whether self and other share no elements. |
.copy() | CollectionResultT | Shallow copy of self. |
a | b | CollectionResultT | Union: self | other. |
a & b | CollectionResultT | Intersection: self & other. |
a - b | CollectionResultT | Difference: self - other. |
a ^ b | CollectionResultT | Symmetric difference: self ^ other. |
From nu.forms.collections.abc.collection.CollectionForm:
| Call | Builds | Meaning |
|---|---|---|
.extract() | object | Materialise the full subtree rooted at self. |
From nu.forms.collections.abc.sized.SizedForm:
| Call | Builds | Meaning |
|---|---|---|
.len() | Int | Length of self. |
From nu.forms.collections.abc.iterable.IterableForm:
| Call | Builds | Meaning |
|---|---|---|
iter(a) | Iterator[ElementT] | Open self into a lazy iterator stream (Python's iter). |
From nu.forms.collections.abc.container.ContainerForm:
| Call | Builds | Meaning |
|---|---|---|
.contains(item) | Bool | Whether item is a member of self. |
From nu.domains.shape.forms.collection.ReactiveCollectionForm:
| Call | Builds | Meaning |
|---|---|---|
.on_child_change(address) | OnChildChange | Observe changes at a specific child address. |
.on_children_change() | OnChildrenChange | Observe changes across all direct children. |
.on_descendants_change() | OnDescendantsChange | Observe changes across descendants matching pattern. |
From nu.domains.shape.forms.collection.MutableCollectionForm:
| Call | Builds | Meaning |
|---|---|---|
.set(value) | SetCmd | Build a SetCmd. |
.erase() | Erase | Build an Erase. |
.init(value) | IfDo | Set value iff the collection is currently missing. |
From nu.domains.shape.forms.collection.CollectionForm:
| Call | Builds | Meaning |
|---|---|---|
.exists() | Exists | Build an Exists query. |
.missing() | Missing | Build a Missing query. |
From nu.lang.forms.Form:
| Call | Builds | Meaning |
|---|---|---|
.is_empty() | Bool | True if this Form yields the EMPTY sentinel. |
.is_invalid() | Bool | True if this Form yields the INVALID sentinel. |
.is_sentinel() | Bool | True if this Form yields either sentinel (EMPTY or INVALID). |
.not_empty() | Bool | True if this Form does not yield EMPTY. |
.not_invalid() | Bool | True if this Form does not yield INVALID. |