Package convex.core.data
Class AMap<K extends ACell,V extends ACell>
- Type Parameters:
K
- Type of keysV
- Type of values
- All Implemented Interfaces:
IValidated
,IWriteable
,Map<K,V>
public abstract class AMap<K extends ACell,V extends ACell>
extends ADataStructure<MapEntry<K,V>>
implements Map<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.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 keyboolean
containsKey(Object key)
boolean
containsKeyRef(Ref<ACell> ref)
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.boolean
Checks for equality with another object.abstract boolean
Checks this map for equality with another map.abstract boolean
equalsKeys(AMap<K,V> map)
Returns true if this map has exactly the same keys as the other mapfilterValues(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 index in this collectionabstract V
Get the value associated with a given key.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 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.getType()
Gets the most specific known runtime Type for this Cell.keySet()
void
print(StringBuilder sb)
Prints this Object to a readable String Representationvoid
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 mapvalues()
Gets the values from this map, in map-determined orderMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encode, encodeRaw, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isCVMValue, isEmbedded, toCanonical, toString, updateRefs, validate, validateCell, write
Methods inherited from class convex.core.data.AObject
attachEncoding, 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, containsValue, 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
-
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 -
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 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 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
-
equalsKeys
Returns true if this map has exactly the same keys as the other map- Parameters:
map
- Map to compare with- Returns:
- true if maps have the same keys, false otherwise
-
equals
Description copied from class:ACell
Checks for equality with another object. In general, data objects should be 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. -
equals
Checks this map for equality with another map. In general, maps should be considered equal if they have the same canonical representation, i.e. the same hash value. Subclasses may override this this they have a more efficient equals implementation or a more specific definition of equality.- Parameters:
a
- Map to compare with- Returns:
- true if maps are equal, false otherwise.
-
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.
-