nustack
ReferenceNu STDkv

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.

NameSortCallMeaning
SetRefrefSetRef(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:

CallBuildsMeaning
.on_change()objectSubscribe to any change on this set slot.

From nu.forms.collections.abc.set_.MutableSetForm:

CallBuildsMeaning
.add(value)AnyAdd value to self.
.remove(value)AnyRemove value from self.
.discard(value)AnyRemove value from self if present.
.pop()ElementResultTRemove and return an arbitrary element from self.
.clear()AnyRemove every element from self.
.update(other)AnyAdd every element of other to self.
.intersection_update(other)AnyKeep only the elements of self also found in other.
.difference_update(other)AnyRemove every element of other from self.
.symmetric_difference_update(other)AnyKeep the elements in exactly one of self and other.

From nu.forms.collections.abc.set_.SetLikeForm:

CallBuildsMeaning
.union(other)CollectionResultTUnion of self and other.
.intersection(other)CollectionResultTIntersection of self and other.
.difference(other)CollectionResultTElements of self that are not in other.
.symmetric_difference(other)CollectionResultTElements in exactly one of self and other, not both.
.issubset(other)BoolWhether every element of self is in other.
.issuperset(other)BoolWhether every element of other is in self.
.isdisjoint(other)BoolWhether self and other share no elements.
.copy()CollectionResultTShallow copy of self.
a | bCollectionResultTUnion: self | other.
a & bCollectionResultTIntersection: self & other.
a - bCollectionResultTDifference: self - other.
a ^ bCollectionResultTSymmetric difference: self ^ other.

From nu.forms.collections.abc.collection.CollectionForm:

CallBuildsMeaning
.extract()objectMaterialise the full subtree rooted at self.

From nu.forms.collections.abc.sized.SizedForm:

CallBuildsMeaning
.len()IntLength of self.

From nu.forms.collections.abc.iterable.IterableForm:

CallBuildsMeaning
iter(a)Iterator[ElementT]Open self into a lazy iterator stream (Python's iter).

From nu.forms.collections.abc.container.ContainerForm:

CallBuildsMeaning
.contains(item)BoolWhether item is a member of self.

From nu.domains.shape.forms.collection.ReactiveCollectionForm:

CallBuildsMeaning
.on_child_change(address)OnChildChangeObserve changes at a specific child address.
.on_children_change()OnChildrenChangeObserve changes across all direct children.
.on_descendants_change()OnDescendantsChangeObserve changes across descendants matching pattern.

From nu.domains.shape.forms.collection.MutableCollectionForm:

CallBuildsMeaning
.set(value)SetCmdBuild a SetCmd.
.erase()EraseBuild an Erase.
.init(value)IfDoSet value iff the collection is currently missing.

From nu.domains.shape.forms.collection.CollectionForm:

CallBuildsMeaning
.exists()ExistsBuild an Exists query.
.missing()MissingBuild a Missing query.

From nu.lang.forms.Form:

CallBuildsMeaning
.is_empty()BoolTrue if this Form yields the EMPTY sentinel.
.is_invalid()BoolTrue if this Form yields the INVALID sentinel.
.is_sentinel()BoolTrue if this Form yields either sentinel (EMPTY or INVALID).
.not_empty()BoolTrue if this Form does not yield EMPTY.
.not_invalid()BoolTrue if this Form does not yield INVALID.

On this page