Package convex.core.data
Class ASet<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<E>
convex.core.data.ADataStructure<T>
convex.core.data.ACollection<T>
convex.core.data.ASet<T>
- Type Parameters:
T
- Type of set elements
- All Implemented Interfaces:
IAssociative<T,CVMBool>
,IValidated
,IWriteable
,Iterable<T>
,Collection<T>
,Set<T>
- Direct Known Subclasses:
AHashSet
public abstract class ASet<T extends ACell>
extends ACollection<T>
implements Set<T>, IAssociative<T,CVMBool>
Abstract based class for sets.
Sets are immutable Smart Data Structures representing an unordered
collection of distinct values.
Iteration order is dependent on the Set implementation. In general, it
is bad practice to depend on any specific ordering for sets.
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAssociates a key with a value in this associative data structure.conj(R a)
Adds an element to this collection, according to the natural semantics of the collectionconjAll(ACollection<R> xs)
Adds multiple elements to this data structure, in the natural manner defined by the general data structure type.abstract boolean
Tests if this Set contains a given valueboolean
abstract boolean
containsAll(ASet<T> b)
Tests if this set contains all the elements of another setboolean
containsKey(ACell key)
Checks if the data structure contains the specified keydisjAll(ACollection<T> xs)
Removes all elements from this set, returning a new set.empty()
Returns an empty instance of the same general type as this data structure.boolean
Checks for equality with another object.abstract boolean
Checks if another set is exactly equal to this setUpdates the set to exclude the given elementexcludeAll(ASet<T> elements)
Updates the set to exclude all the given elements.get(long index)
Gets the element at the specified index in this collectionGet the value associated with a given key.Get the value associated with a given key.getRefByHash(Hash hash)
Gets the Ref in the Set for a given hash, or null if not foundbyte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.getValueRef(ACell k)
Gets the Ref in the Set for a given value, or null if not foundinclude(R a)
Updates the set to include the given elementincludeAll(ASet<R> elements)
Updates the set to include all the given elements.includeRef(Ref<T> ref)
Adds a value to this set using a Ref to the valueintersectAll(ASet<T> xs)
Returns the intersection of two setsboolean
Tests if this set is a (non-strict) subset of another SetMaps a function over a collection, applying it to each element in turn.void
print(StringBuilder sb)
Prints this Object to a readable String RepresentationtoVector()
Converts this collection to a canonical vector of elementsMethods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, copyToArray, encode, iterator, remove, removeAll, retainAll, toArray, toCellArray
Methods inherited from class convex.core.data.ADataStructure
count, isEmpty, size
Methods inherited from class convex.core.data.ACountable
getElementRef
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encodeRaw, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toString, updateRefs, validate, validateCell, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Constructor Details
-
ASet
protected ASet(long count)
-
-
Method Details
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell.- Specified by:
getType
in classACollection<T extends ACell>
- Returns:
- The Type of this Call
-
getTag
public final byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
include
Updates the set to include the given element- Parameters:
a
- Value to include- Returns:
- Updated set
-
exclude
Updates the set to exclude the given element- Parameters:
a
- Value to exclude- Returns:
- Updated set
-
includeAll
Updates the set to include all the given elements. Can be used to implement union of sets- Parameters:
elements
- Elements to include- Returns:
- Updated set
-
excludeAll
Updates the set to exclude all the given elements.- Parameters:
elements
- Elements to exclude- Returns:
- Updated set
-
conjAll
Description copied from class:ADataStructure
Adds multiple elements to this data structure, in the natural manner defined by the general data structure type. e.g. append at the end of a vector. This may be more efficient than using 'conj' for individual items.- Overrides:
conjAll
in classADataStructure<T extends ACell>
- Type Parameters:
R
- Type of Value added- Parameters:
xs
- New elements to add- Returns:
- The updated data structure, or null if a failure occurred due to invalid elementtypes
-
disjAll
Removes all elements from this set, returning a new set.- Parameters:
xs
- Collection of elements to remove- Returns:
- Set with specified element(s) removed
-
toVector
Description copied from class:ACollection
Converts this collection to a canonical vector of elements- Specified by:
toVector
in classACollection<T extends ACell>
- Returns:
- This collection coerced to a vector
-
map
Description copied from class:ACollection
Maps a function over a collection, applying it to each element in turn.- Specified by:
map
in classACollection<T extends ACell>
- Type Parameters:
R
- Type of element in resulting collection- Parameters:
mapper
- Function to map over collection- Returns:
- Collection after function applied to each element
-
intersectAll
Returns the intersection of two sets- Parameters:
xs
- Set to intersect with- Returns:
- Intersection of the two sets
-
get
Description copied from class:ADataStructure
Get the value associated with a given key.- Specified by:
get
in classADataStructure<T extends ACell>
- Parameters:
key
- Associative key to look up- Returns:
- Value from collection, or a falsey value (null or false) if not found
-
get
Description copied from class:ADataStructure
Get the value associated with a given key.- Specified by:
get
in classADataStructure<T extends ACell>
- Parameters:
key
- Key to look up in data structurenotFound
- Value to return if key is not found- Returns:
- Value from collection, or notFound value if not found
-
get
Description copied from class:ACountable
Gets the element at the specified index in this collection- Specified by:
get
in classACountable<T extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
contains
Tests if this Set contains a given value- Parameters:
o
- Value to test for set membership- Returns:
- True if set contains value, false otherwise
-
contains
-
equals
Description copied from class:ACell
Checks for equality with another object. In general, data objects should be considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses should override this if they have a more efficient equals implementation. -
equals
Checks if another set is exactly equal to this set- Parameters:
other
- Set to compare with this set- Returns:
- true if sets are equal, false otherwise
-
includeRef
Adds a value to this set using a Ref to the value- Parameters:
ref
- Ref to value to include- Returns:
- Updated set
-
conj
Description copied from class:ACollection
Adds an element to this collection, according to the natural semantics of the collection- Specified by:
conj
in classACollection<T extends ACell>
- Type Parameters:
R
- Type of Value added- Parameters:
a
- Value to add- Returns:
- The updated collection
-
assoc
Description copied from class:ADataStructure
Associates a key with a value in this associative data structure. May return null if the Key or Value is incompatible with the data structure.- Specified by:
assoc
in classADataStructure<T extends ACell>
- Parameters:
key
- Associative keyvalue
- Value to associate with key- Returns:
- Updates data structure, or null if data types are invalid
-
containsKey
Description copied from class:ADataStructure
Checks if the data structure contains the specified key- Specified by:
containsKey
in classADataStructure<T extends ACell>
- Parameters:
key
- Associative key to look up- Returns:
- true if the data structure contains the key, false otherwise
-
empty
Description copied from class:ADataStructure
Returns an empty instance of the same general type as this data structure.- Specified by:
empty
in classADataStructure<T extends ACell>
- Returns:
- An empty data structure
-
getValueRef
Gets the Ref in the Set for a given value, or null if not found- Parameters:
k
- Value to check for set membership- Returns:
- Ref to value, or null
-
getRefByHash
Gets the Ref in the Set for a given hash, or null if not found- Parameters:
hash
- Hash to check for set membership- Returns:
- Ref to value with given Hash, or null
-
containsAll
Tests if this set contains all the elements of another set- Parameters:
b
- Set to compare with- Returns:
- True if other set is completely contained within this set, false otherwise
-
isSubset
Tests if this set is a (non-strict) subset of another Set- Parameters:
b
- Set to test against- Returns:
- True if this is a subset of the other set, false otherwise.
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation
-