Package convex.core.data
Class AMap<K extends ACell,V extends ACell>
java.lang.Object
- Type Parameters:
K- Type of keysV- Type of values
- All Implemented Interfaces:
IAssociative<K,,V> IValidated,IWriteable,Map<K,V>
public abstract class AMap<K extends ACell,V extends ACell>
extends ADataStructure<MapEntry<K,V>>
implements Map<K,V>, IAssociative<K,V>
Abstract base class for maps.
Maps are Smart Data Structures that represent an immutable mapping of keys to
values. The can also be seen as a data structure where the elements are map entries
(equivalent to length 2 vectors)
Ordering of map entries (as seen through iterators etc.) depends on map type.
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidaccumulateEntrySet(Set<Map.Entry<K, V>> h) Accumulate all entries from this map in the given mutable Set.protected abstract voidaccumulateKeySet(Set<K> h) Accumulate all keys from this map in the given mutable Set.protected abstract voidaccumulateValues(List<V> al) Accumulate all values from this map in the given mutable list.Associates the given key with the specified value.assocEntry(MapEntry<K, V> e) Associate the given map entry into the map.final voidclear()Adds a new map entry to this map.booleancontainsKey(ACell key) Checks if the data structure contains the specified keyfinal booleancontainsKey(Object key) final booleancontainsKeyRef(Ref<ACell> ref) abstract booleancontainsValue(ACell value) CHecks if this map contains the given value.final booleancontainsValue(Object value) Dissociates a key from this map, returning an updated map if the key was removed, or the same unchanged map if the key is not present.empty()Returns an empty instance of the same Type as this data structure.entryAt(long i) Gets the entry in this map at a specified index, according to the map-specific order.Gets a vector of all map entries.filterValues(Predicate<V> pred) Filters all values in this map with the given predicate.abstract voidforEach(BiConsumer<? super K, ? super V> action) get(long i) Gets the map entry at the specified position in this Mapabstract VGet the value associated with a given key.final VGets the value at a specified key, or returns the fallback value if not foundfinal VgetElementRef(long index) Gets a Ref to the element at the specified element index in this collectionGets the MapEntry for the given keygetEntryByHash(Hash hash) Gets the map entry with the specified hashgetKeyRefEntry(Ref<ACell> ref) Get an entry given a Ref to the key value.getKeys()Gets a vector of keys for this Map.getType()Gets the most specific known runtime Type for this Cell.keySet()Merge another map into this map.booleanprint(BlobBuilder sb, long limit) Prints this Object to a readable String Representation.final Vfinal voidabstract <R> RreduceEntries(BiFunction<? super R, MapEntry<K, V>, ? extends R> func, R initial) Reduce over all map entries in this mapabstract <R> RreduceValues(BiFunction<? super R, ? super V, ? extends R> func, R initial) Reduce over all values in this mapfinal Vslice(long start) Gets a slice of this data structure from start to the endslice(long start, long end) Gets a slice of this data structurevalues()Gets the values from this map, in map-determined orderMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, encode, encodeRaw, equals, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toString, updateRefs, validate, validateCellMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface convex.core.data.IWriteable
estimatedEncodingSizeMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, entrySet, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Constructor Details
-
AMap
protected AMap(long count)
-
-
Method Details
-
getType
-
values
-
assoc
Associates the given key with the specified value. -
dissoc
-
containsKeyRef
-
containsKey
Description copied from class:ADataStructureChecks if the data structure contains the specified key- Specified by:
containsKeyin classADataStructure<MapEntry<K extends ACell,V extends ACell>> - Parameters:
key- Associative key to look up- Returns:
- true if the data structure contains the key, false otherwise
-
containsKey
-
containsValue
-
containsValue
CHecks if this map contains the given value. WARNING: probably O(n)- Parameters:
value- Value to check- Returns:
- true if map contains value, false otherwise
-
getKeyRefEntry
Get an entry given a Ref to the key value. This is more efficient than directly looking up using the key for some map types, and should be preferred if the caller already has a Ref available.- Parameters:
ref- Ref to Map key- Returns:
- MapEntry for the given key ref
-
accumulateEntrySet
-
accumulateKeySet
-
accumulateValues
-
put
-
remove
-
putAll
-
clear
-
forEach
-
print
Description copied from class:AObjectPrints 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. -
assocEntry
-
entryAt
-
getElementRef
Description copied from class:ACountableGets a Ref to the element at the specified element index in this collection- Specified by:
getElementRefin classACountable<MapEntry<K extends ACell,V extends ACell>> - Parameters:
index- Index of element to get- Returns:
- Element at the specified index
-
get
-
getEntry
-
get
-
get
Description copied from class:ADataStructureGet the value associated with a given key. -
get
Gets the value at a specified key, or returns the fallback value if not found -
reduceValues
Reduce over all values in this map- Type Parameters:
R- Type of reduction return value- Parameters:
func- A function taking the reduction value and a map valueinitial- Initial reduction value- Returns:
- The final reduction value
-
filterValues
-
reduceEntries
public abstract <R> R reduceEntries(BiFunction<? super R, MapEntry<K, V>, ? extends R> func, R initial) Reduce over all map entries in this map- Type Parameters:
R- Type of reduction return value- Parameters:
func- A function taking the reduction value and a map entryinitial- Initial reduction value- Returns:
- The final reduction value
-
keySet
-
getEntryByHash
-
conj
Adds a new map entry to this map. The argument must be a valid map entry or length 2 vector. -
entryVector
-
merge
-
slice
Description copied from class:ACountableGets a slice of this data structure from start to the end -
empty
-
slice
Description copied from class:ACountableGets a slice of this data structure -
getKeys
-