Package convex.core.data
Class AMap<K extends ACell,V extends ACell>
- 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
count
Fields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
accumulateEntrySet
(HashSet<Map.Entry<K, V>> h) Accumulate all entries from this map in the given HashSet.protected abstract void
accumulateKeySet
(HashSet<K> h) Accumulate all keys from this map in the given HashSet.protected abstract void
accumulateValues
(ArrayList<V> al) Accumulate all values from this map in the given ArrayList.Associates the given key with the specified value.assocEntry
(MapEntry<K, V> e) Associate the given map entry into the map.final void
clear()
<R extends ACell>
ADataStructure<R>conj
(R x) Adds a new map entry to this map.boolean
containsKey
(ACell key) Checks if the data structure contains the specified keyfinal boolean
containsKey
(Object key) final boolean
containsKeyRef
(Ref<ACell> ref) abstract boolean
containsValue
(ACell value) CHecks if this map contains the given value.final boolean
containsValue
(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.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 void
forEach
(BiConsumer<? super K, ? super V> action) get
(long i) Gets the element at the specified element index in this collectionabstract V
Get the value associated with a given key.final V
Gets the value at a specified key, or returns the fallback value if not foundgetElementRef
(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.boolean
print
(BlobBuilder sb, long limit) Prints this Object to a readable String Representation.final V
final void
abstract <R> R
reduceEntries
(BiFunction<? super R, MapEntry<K, V>, ? extends R> func, R initial) Reduce over all map entries in this mapabstract <R> R
reduceValues
(BiFunction<? super R, ? super V, ? extends R> func, R initial) Reduce over all values in this mapfinal V
slice
(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
conjAll, count, empty, isEmpty, size, toCVMString
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, encodeRaw, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isCompletelyEncoded, isCVMValue, isEmbedded, mark, mark, toCanonical, toString, updateRefs, validate, validateCell, write
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 convex.core.data.IWriteable
estimatedEncodingSize
Methods 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
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
values
Gets the values from this map, in map-determined order -
assoc
Associates the given key with the specified value. -
dissoc
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.- Parameters:
key
- Key to remove.- Returns:
- Updated map
-
containsKeyRef
-
containsKey
Description copied from class:ADataStructure
Checks if the data structure contains the specified key- Specified by:
containsKey
in 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
Accumulate all entries from this map in the given HashSet.- Parameters:
h
- HashSet in which to accumulate entries
-
accumulateKeySet
Accumulate all keys from this map in the given HashSet.- Parameters:
h
- HashSet in which to accumulate keys
-
accumulateValues
Accumulate all values from this map in the given ArrayList.- Parameters:
al
- ArrayList in which to accumulate values
-
put
-
remove
-
putAll
-
clear
public final void clear() -
forEach
-
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. -
assocEntry
Associate the given map entry into the map. May return null if the map entry is not valid for this map type.- Parameters:
e
- A map entry- Returns:
- The updated map
-
entryAt
Gets the entry in this map at a specified index, according to the map-specific order.- Parameters:
i
- Index of entry- Returns:
- MapEntry at the specified index.
- Throws:
IndexOutOfBoundsException
- If this index is not valid
-
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<MapEntry<K extends ACell,
V extends ACell>> - Parameters:
index
- Index of element to get- Returns:
- Element at the specified index
-
get
Description copied from class:ACountable
Gets the element at the specified element index in this collection -
getEntry
Gets the MapEntry for the given key- Parameters:
k
- Key to lookup in Map- Returns:
- The map entry, or null if the key is not found
-
get
-
get
Description copied from class:ADataStructure
Get 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
Filters all values in this map with the given predicate.- Parameters:
pred
- A predicate specifying which elements to retain.- Returns:
- The updated map containing those entries where the predicate returned true.
-
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
Gets the map entry with the specified hash- Parameters:
hash
- Hash of key to lookup- Returns:
- The specified MapEntry, or null if not found.
-
conj
Adds a new map entry to this map. The argument must be a valid map entry or length 2 vector. -
entryVector
Gets a vector of all map entries.- Returns:
- Vector map entries, in map-defined order.
-
merge
Merge another map into this map. Replaces existing entries if they are different. O(n) in size of map to merge. Preserves the type of the current map.- Parameters:
m
- A map to merge into this map- Returns:
- The updated map, or null if convesrion fails
-
slice
Description copied from class:ACountable
Gets a slice of this data structure from start to the end -
slice
Description copied from class:ACountable
Gets a slice of this data structure -
getKeys
Gets a vector of keys for this Map. O(n) in general.- Returns:
- Vector of Keys
-