Package convex.core.data
Class AHashMap<K extends ACell,V extends ACell>
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ACountable<E>
convex.core.data.ADataStructure<MapEntry<K,V>>
convex.core.data.AMap<K,V>
convex.core.data.AHashMap<K,V>
- All Implemented Interfaces:
IValidated
,IWriteable
,Map<K,V>
-
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 TypeMethodDescriptionAssociates the given key with the specified value.assocEntry(MapEntry<K,V> e)
Associate the given map entry into the map.assocEntry(MapEntry<K,V> e, int shift)
abstract boolean
containsAllKeys(AHashMap<K,V> map)
Returns true if this map contains all the same keys as another mapDissociates 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.Dissoc given a Ref to the key value.empty()
Returns an empty instance of the same general type as this data structure.abstract int
encode(byte[] bs, int pos)
Writes this HashMap to a byte array.boolean
Checks this map for equality with another map.filterValues(Predicate<V> pred)
Filters all values in this map with the given predicate.getKeys()
Maps a function over all entries in this Map to produce updated entries.Merge another map into this map.mergeDifferences(AHashMap<K,V> b, MergeFunction<V> func)
Merge this map with another map, using the given function for each key that is present in either map and has a different value The function is passed null for missing values in either map, and must return type V.mergeDifferences(AHashMap<K,V> b, MergeFunction<V> func, int shift)
Merge this map with another map, using the given function for each key that is present in either map.updateRefs(IRefFunction func)
Updates all Refs in this object using the given function.protected abstract void
validateWithPrefix(String string)
Validates the map with a given hex prefix.Methods inherited from class convex.core.data.AMap
accumulateEntrySet, accumulateKeySet, accumulateValues, clear, conj, containsKey, containsKey, containsKeyRef, entryAt, entryVector, equals, equalsKeys, forEach, get, get, get, get, getElementRef, getEntry, getEntryByHash, getKeyRefEntry, getType, keySet, print, put, putAll, reduceEntries, reduceValues, remove, values
Methods inherited from class convex.core.data.ADataStructure
conjAll, count, isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, encodeRaw, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, getTag, hashCode, isCanonical, isCVMValue, isEmbedded, mark, mark, toCanonical, toString, 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
-
AHashMap
protected AHashMap(long count)
-
-
Method Details
-
empty
Description copied from class:ADataStructure
Returns an empty instance of the same general type as this data structure. -
dissocRef
Dissoc given a Ref to the key value.- Parameters:
key
- Ref of key to remove- Returns:
- Map with specified key removed.
-
assocRef
-
assoc
Description copied from class:AMap
Associates the given key with the specified value. -
dissoc
Description copied from class:AMap
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. -
assocRef
-
assocEntry
Description copied from class:AMap
Associate the given map entry into the map. May return null if the map entry is not valid for this map type. -
assocEntry
-
merge
Merge another map into this map. Replaces existing entries if they are different O(n) in size of map to merge.- Parameters:
m
- HashMap to merge into this HashMap- Returns:
- Merged HashMap
-
mergeDifferences
Merge this map with another map, using the given function for each key that is present in either map and has a different value The function is passed null for missing values in either map, and must return type V. If the function returns null, the entry is removed. Returns the same map if no changes occurred.- Parameters:
b
- Other map to merge withfunc
- Merge function, returning a new value for each key- Returns:
- A merged map, or this map if no changes occurred
-
mergeDifferences
-
mergeWith
Merge this map with another map, using the given function for each key that is present in either map. The function is applied to the corresponding values with the same key. The function is passed null for missing values in either map, and must return type V. If the function returns null, the entry is removed. Returns the same map if no changes occurred. PERF WARNING: This method's contract requires calling the function on all values in both sets, which will cause a full data structure traversal. If the function will only return one or other of the compared values consider using mergeDifferences instead.- Parameters:
b
- Other map to merge withfunc
- Merge function, returning a new value for each key- Returns:
- A merged map, or this map if no changes occurred
-
mergeWith
-
filterValues
Description copied from class:AMap
Filters all values in this map with the given predicate. -
equals
Description copied from class:AMap
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. -
mapEntries
Maps a function over all entries in this Map to produce updated entries. May not change keys, but may return null to remove an entry.- Parameters:
func
- A function that maps old map entries to updated map entries.- Returns:
- The updated Map, or this Map if no changes
-
validateWithPrefix
Validates the map 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 key hashes start with the correct prefix of hex characters. TODO: consider faster way of passing prefix than hex string, probably a byte[] stack.- Parameters:
string
-- Throws:
InvalidDataException
-
updateRefs
Description copied from class:ACell
Updates 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:
updateRefs
in classACell
- Parameters:
func
- Ref update function- Returns:
- Cell with updated Refs
-
containsAllKeys
Returns true if this map contains all the same keys as another map- Parameters:
map
- Map to compare with- Returns:
- True if this map contains all the keys of the other
-
encode
public abstract int encode(byte[] bs, int pos)Writes this HashMap to a byte array. Will include values by default.- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in classACell
- Parameters:
bs
- Byte array to encode intopos
- Start position to encode at- Returns:
- Updated position
-
getKeys
-