nustack
ReferenceNu STDmem

refs.set

Dict set reference: unordered unique-element container.

Module nustd.mem.refs.set.

Dict set reference: unordered unique-element container.

NameSortCallMeaning
SetRefrefSetRef(address, item_type, parent_ref=None, owner_shape=None)A set slot in the dict substrate, holding one plain set of values.

SetRef

A set slot in the dict substrate, holding one plain set of values.

SetRef(address, item_type, parent_ref=None, owner_shape=None)

Path nustd.mem.SetRef. Kind Ref, sort ref, cardinality scalar.

No descent: a set has no addresses, so there is no child ref to navigate to. Everything happens through the set calls - membership, the algebra (union, difference, ...), and the in-place mutations.

Notes

  • The stored value is an ordinary set and a read hands back that live object, so elements must be hashable and iteration order is whatever Python gives.
  • In-place calls read the container first and do nothing when the slot is absent, so set an empty set before the first add.
  • The declared element type is metadata; nothing coerces or rejects what is written.

Example

class Port(nu.Shape):
    members = nustd.mem.SetRef.slot(str)
ctx = nu.Context().bind(dict, {"members": {"a"}}, Port)
_ = nu.run(Port.members.add("b"), ctx)
sorted(nu.run(Port.members, ctx)[0])
['a', 'b']

Inherited methods

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.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