Package convex.core.data
Class SetTree<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>
convex.core.data.AHashSet<T>
convex.core.data.SetTree<T>
- Type Parameters:
T- Type of set elemets
- All Implemented Interfaces:
IAssociative<T,CVMBool>,IValidated,IWriteable,Iterable<T>,Collection<T>,Set<T>
Persistent Set for large hash sets requiring tree structure.
Internally implemented as a radix tree, indexed by key hash. Uses an array of
child Maps, with a bitmap mask indicating which hex digits are present, i.e.
have non-empty children.
-
Field Summary
FieldsFields inherited from class convex.core.data.AHashSet
MAX_SHIFT, OP_DIFF_LEFT, OP_DIFF_RIGHT, OP_INTERSECTION, OP_UNIONFields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsAll(ASet<T> b)Tests if this set contains all the elements of another setprotected booleancontainsAll(SetTree<T> map)booleancontainsHash(Hash hash)Tests if this Set contains a given hashprotected <R> voidcopyToArray(R[] arr, int offset)Copies the elements of this collection in order to an array at the specified offsetstatic intdigitForIndex(int index, short mask)intencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written firstintencodeRaw(byte[] bs, int pos)Writes this Cell's encoding to a byte array, excluding the tag bytebooleanChecks if another set is exactly equal to this setintEstimate the encoded data size for this Cell.Updates the set to exclude the given elementexcludeRef(Ref<T> keyRef)getElementRef(long i)Gets a Ref to the element at the specified index in this collectiongetRef(int i)Gets a numbered child Ref from within this Cell.getRefByHash(Hash hash)Gets the Ref in the Set for a given hash, or null if not foundintGets 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 elementincludeRef(Ref<T> ref)Adds a value to this set using a Ref to the valueincludeRef(Ref<T> e, int shift)booleanReturns true if this Cell is in a canonical format for message writing.booleanReturns true if this object represents a first class CVM Value.read(ByteBuffer bb, long count)Reads a SetTree from the provided ByteBuffer Assumes the header byte and count is already read.Converts this Cell to its canonical version.updateRefs(IRefFunction func)Updates all Refs in this object using the given function.voidvalidate()Validates the complete structure of this object.voidValidates the local structure and invariants of this cell.protected voidvalidateWithPrefix(Hash base, int digit, int shift)Validates the set with a given hex prefix.Methods inherited from class convex.core.data.AHashSet
applyOp, applySelf, conj, conjAll, contains, disjAll, excludeAll, get, getByHash, includeAll, intersectAll, reverseOp, toArrayMethods inherited from class convex.core.data.ASet
assoc, contains, containsKey, empty, equals, get, get, getTag, getType, isSubset, map, print, toVectorMethods inherited from class convex.core.data.ACollection
add, addAll, clear, containsAll, iterator, remove, removeAll, retainAll, toArray, toCellArrayMethods inherited from class convex.core.data.ADataStructure
count, isEmpty, sizeMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, hashCode, isEmbedded, toString, writeMethods inherited from class convex.core.data.AObject
attachEncoding, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
MAX_ENCODING_LENGTH
public static int MAX_ENCODING_LENGTH
-
-
Method Details
-
create
-
getElementRef
Description copied from class:ACountableGets a Ref to the element at the specified index in this collection- Specified by:
getElementRefin classACountable<T extends ACell>- Parameters:
i- Index of element to get- Returns:
- Element at the specified index
-
getRefByHash
Description copied from class:ASetGets the Ref in the Set for a given hash, or null if not found- Specified by:
getRefByHashin classASet<T extends ACell>- Parameters:
hash- Hash to check for set membership- Returns:
- Ref to value with given Hash, or null
-
exclude
Description copied from class:ASetUpdates the set to exclude the given element -
excludeRef
- Specified by:
excludeRefin classAHashSet<T extends ACell>
-
toCanonical
Description copied from class:ACellConverts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonicalin classAHashSet<T extends ACell>- Returns:
- Canonical version of Cell
-
digitForIndex
public static int digitForIndex(int index, short mask) -
include
Description copied from class:ASetUpdates the set to include the given element -
includeRef
- Specified by:
includeRefin classAHashSet<T extends ACell>
-
includeRef
Description copied from class:ASetAdds a value to this set using a Ref to the value- Specified by:
includeRefin classAHashSet<T extends ACell>- Parameters:
ref- Ref to value to include- Returns:
- Updated set
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACollection<T extends ACell>- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, excluding the tag byte -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
read
public static <V extends ACell> SetTree<V> read(ByteBuffer bb, long count) throws BadFormatExceptionReads a SetTree from the provided ByteBuffer Assumes the header byte and count is already read.- Parameters:
bb- ByteBuffer to read fromcount- Number of elements- Returns:
- TreeMap instance as read from ByteBuffer
- Throws:
BadFormatException- If encoding is invalid
-
isCanonical
public boolean isCanonical()Description copied from class:ACellReturns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Specified by:
isCanonicalin classACell- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACellReturns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValuein classACell- Returns:
- true if the object is a CVM Value, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACellGets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.- Specified by:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. -
updateRefs
Description copied from class:ACellUpdates all Refs in this object using the given function. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Overrides:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
mergeWith
-
mergeWith
-
equals
Description copied from class:ASetChecks if another set is exactly equal to this set -
validate
Description copied from interface:IValidatedValidates the complete structure of this object. It is necessary to ensure all child Refs are validated, so the general contract for validate is:- Call super.validate() - which will indirectly call validateCell()
- Call validate() on any contained cells in this class
- Specified by:
validatein interfaceIValidated- Overrides:
validatein classACell- Throws:
InvalidDataException- If the data Valie is invalid in any way
-
validateWithPrefix
Description copied from class:AHashSetValidates the set with a given hex prefix. This is necessary to ensure that child maps are valid, in particular have the correct shift level and that all hashes start with the correct prefix of hex characters.- Specified by:
validateWithPrefixin classAHashSet<T extends ACell>- Parameters:
base- Hash for earlier prefix valuesdigit- Hex digit expected at position [shift]
-
validateCell
Description copied from class:ACellValidates 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:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
containsAll
Description copied from class:ASetTests if this set contains all the elements of another set- Specified by:
containsAllin classASet<T extends ACell>- Parameters:
b- Set to compare with- Returns:
- True if other set is completely contained within this set, false otherwise
-
containsAll
-
getValueRef
Description copied from class:ASetGets the Ref in the Set for a given value, or null if not found- Specified by:
getValueRefin classASet<T extends ACell>- Parameters:
k- Value to check for set membership- Returns:
- Ref to value, or null
-
copyToArray
protected <R> void copyToArray(R[] arr, int offset)Description copied from class:ACollectionCopies the elements of this collection in order to an array at the specified offset- Specified by:
copyToArrayin classACollection<T extends ACell>- Type Parameters:
R- Type of array elements required
-
containsHash
Description copied from class:AHashSetTests if this Set contains a given hash- Specified by:
containsHashin classAHashSet<T extends ACell>- Parameters:
hash- Hash to test for set membership- Returns:
- True if set contains value for given hash, false otherwise
-