Package convex.core.data.impl
Class KeySet<K extends ACell,V extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<K>
convex.core.data.ADataStructure<K>
convex.core.data.ACollection<K>
convex.core.data.ASet<K>
convex.core.data.impl.ADerivedSet<K,K,V>
convex.core.data.impl.KeySet<K,V>
- All Implemented Interfaces:
IAssociative<K,
,CVMBool> IValidated
,IWriteable
,Iterable<K>
,Collection<K>
,Set<K>
-
Field Summary
Fields inherited from class convex.core.data.impl.ADerivedSet
map
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 TypeMethodDescriptionAdds an element to this collection, according to the natural semantics of the collectionconjAll
(ACollection<? extends K> xs) Adds multiple elements to this data structure, in the natural manner defined by the general data structure type.boolean
Tests if this Set contains a given valueboolean
containsAll
(ASet<?> b) Tests if this set contains all the elements of another setprotected <R> void
copyToArray
(R[] arr, int offset) Copies the elements of this collection in order to an array at the specified offsetdisjAll
(ACollection<K> xs) Removes all elements from this set, returning a new set.int
encode
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.protected int
encodeRaw
(byte[] bs, int pos) Writes this Cell's encoding to a byte array, excluding the tag byte.boolean
Checks for equality with another Cell.int
Estimate the encoded data size for this Cell.Updates the set to exclude the given elementexcludeAll
(ASet<K> elements) Updates the set to exclude all the given elements.getElementRef
(long index) Gets a Ref to the element at the specified element index in this collectiongetRefByHash
(Hash hash) Gets the Ref in the Set for a given hash, or null if not foundint
Gets the number of Refs contained within 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 K> elements) Updates the set to include all the given elements.includeRef
(Ref<K> ref) Adds a value to this set using a Ref to the valueintersectAll
(ASet<K> xs) Returns the intersection of two setsboolean
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false.slice
(long start, long end) Gets a slice of this SetConverts this Cell to a canonical version.void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.impl.ADerivedSet
isCanonical
Methods inherited from class convex.core.data.ASet
assoc, contains, containsKey, empty, get, get, get, getTag, getType, isSubset, map, print, slice, toVector
Methods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, 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.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, hashCode, isEmbedded, toString, updateRefs, validate
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
-
Constructor Details
-
KeySet
-
-
Method Details
-
create
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Returns:
- The estimated size for the binary representation of this object.
-
include
-
getCanonicalSet
-
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. -
disjAll
-
intersectAll
-
contains
-
includeRef
-
conj
Description copied from class:ACollection
Adds an element to this collection, according to the natural semantics of the collection -
getValueRef
-
getRefByHash
-
containsAll
Description copied from class:ASet
Tests if this set contains all the elements of another set- Specified by:
containsAll
in classASet<K extends ACell>
- Parameters:
b
- Set to compare with- Returns:
- True if other set is completely contained within this set, false otherwise
-
slice
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACollection<K extends ACell>
- Parameters:
bs
- A byte array to which to write the encodingpos
- The offset into the byte array- Returns:
- New position after writing
-
copyToArray
protected <R> void copyToArray(R[] arr, int offset) Description copied from class:ACollection
Copies the elements of this collection in order to an array at the specified offset- Specified by:
copyToArray
in classACollection<K extends ACell>
- Type Parameters:
R
- Type of array elements required- Parameters:
arr
-offset
-
-
getElementRef
Description copied from class:ACountable
Gets a Ref to the element at the specified element index in this collection- Specified by:
getElementRef
in classACountable<K extends ACell>
- Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
equals
Description copied from class:ACell
Checks for equality with another Cell. In general, Cells are 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. MUST NOT require reads from Store. -
encodeRaw
protected int encodeRaw(byte[] bs, int pos) Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte. -
toCanonical
Description copied from class:ACell
Converts this Cell to a canonical version. Must return this Cell if already canonical, may be O(n) in size of value otherwise. Callers should usually use getCanonical(), which caches canonical instances once created- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-
isCVMValue
public boolean isCVMValue()Description copied from class:ACell
Returns true if this cell is a first class CVM Value allowable in the CVM state Sub-structural cells that are not themselves first class values should return false Records and types that are not permissible on the CVM should return false. Pretty much everything else should return true. Note: CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Overrides:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-