Package convex.core.data
Class ASet<T extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<T>
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:
ADerivedSet
,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, memorySize
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAssociates a key with a value in this associative data structure.Adds an element to this collection, according to the natural semantics of the collectionconjAll
(ACollection<? extends T> 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 valuefinal boolean
abstract boolean
containsAll
(ASet<?> 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 Type as this data structure.Updates 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 element index in this valueGet 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 foundfinal byte
getTag()
Gets the tag byte for this cell.final AType
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 foundUpdates the set to include the given elementincludeAll
(ASet<? extends T> 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.boolean
print
(BlobBuilder sb, long limit) Prints this Object to a readable String Representation.slice
(long start) Gets a slice of this Set from start to the endslice
(long start, long end) Gets a slice of this SettoVector()
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, toArray, toCellArray
Methods inherited from class convex.core.data.ADataStructure
checkIndex, count, isDataValue, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACountable
getElementRef
Methods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toString, updateRefs, validate, validateCell
Methods inherited from class convex.core.data.AObject
attachEncoding, print, 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
-
getTag
public final byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte is always equal to the first byte of the Cell's canonical Encoding, and is sufficient to distinguish how to read the rest of the encoding. -
include
-
exclude
-
includeAll
-
excludeAll
-
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>
- Parameters:
xs
- New elements to add- Returns:
- The updated data structure, or null if a failure occurred due to invalid element types
-
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
-
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 element index in this value- 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
-
includeRef
-
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>
- Parameters:
a
- Value to add, should be the element type of the data structure- 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 Type as this data structure.- Specified by:
empty
in classADataStructure<T extends ACell>
- Returns:
- An empty data structure
-
getValueRef
-
getRefByHash
-
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
-
print
Description copied from class:AObject
Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time when limit of printing is exceeded otherwise DoS attacks may be possible. -
slice
-
slice
-