Class AMap<K extends ACell,​V extends ACell>

Type Parameters:
K - Type of keys
V - Type of values
All Implemented Interfaces:
IValidated, IWriteable, Map<K,​V>
Direct Known Subclasses:
ABlobMap, AHashMap, ARecord

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.
  • Constructor Details

    • AMap

      protected AMap(long count)
  • Method Details

    • getType

      public AType getType()
      Description copied from class: ACell
      Gets the most specific known runtime Type for this Cell.
      Overrides:
      getType in class ACell
      Returns:
      The Type of this Call
    • values

      public AVector<V> values()
      Gets the values from this map, in map-determined order
      Specified by:
      values in interface Map<K extends ACell,​V extends ACell>
    • assoc

      public abstract AMap<K,​V> assoc(ACell key, ACell value)
      Associates the given key with the specified value.
      Specified by:
      assoc in class ADataStructure<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      key - Map key to associate
      value - Map value
      Returns:
      An updated map with the new association, or null if the association fails
    • dissoc

      public abstract AMap<K,​V> dissoc(ACell key)
      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

      public final boolean containsKeyRef(Ref<ACell> ref)
    • containsKey

      public boolean containsKey(ACell key)
      Description copied from class: ADataStructure
      Checks if the data structure contains the specified key
      Specified by:
      containsKey in class ADataStructure<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

      public final boolean containsKey(Object key)
      Specified by:
      containsKey in interface Map<K extends ACell,​V extends ACell>
    • getKeyRefEntry

      public abstract MapEntry<K,​V> getKeyRefEntry(Ref<ACell> ref)
      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

      protected abstract void accumulateEntrySet(HashSet<Map.Entry<K,​V>> h)
      Accumulate all entries from this map in the given HashSet.
      Parameters:
      h - HashSet in which to accumulate entries
    • accumulateKeySet

      protected abstract void accumulateKeySet(HashSet<K> h)
      Accumulate all keys from this map in the given HashSet.
      Parameters:
      h - HashSet in which to accumulate keys
    • accumulateValues

      protected abstract void accumulateValues(ArrayList<V> al)
      Accumulate all values from this map in the given ArrayList.
      Parameters:
      al - ArrayList in which to accumulate values
    • put

      public final V put(K key, V value)
      Specified by:
      put in interface Map<K extends ACell,​V extends ACell>
    • remove

      public final V remove(Object key)
      Specified by:
      remove in interface Map<K extends ACell,​V extends ACell>
    • putAll

      public final void putAll(Map<? extends K,​? extends V> m)
      Specified by:
      putAll in interface Map<K extends ACell,​V extends ACell>
    • clear

      public final void clear()
      Specified by:
      clear in interface Map<K extends ACell,​V extends ACell>
    • forEach

      public abstract void forEach(BiConsumer<? super K,​? super V> action)
      Specified by:
      forEach in interface Map<K extends ACell,​V extends ACell>
    • print

      public boolean print(BlobBuilder sb, long limit)
      Description copied from class: AObject
      Prints this Object to a readable String Representation. SECURITY: Must halt and return false in O(1) time if limit of printing is exceeded otherwise DoS attacks may be possible.
      Specified by:
      print in class AObject
      Parameters:
      sb - BlobBuilder to append to
      limit - Limit of printing in string bytes
      Returns:
      True if fully printed within limit, false otherwise
    • assocEntry

      public abstract AMap<K,​V> assocEntry(MapEntry<K,​V> e)
      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

      public abstract MapEntry<K,​V> entryAt(long i)
      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

      public Ref<MapEntry<K,​V>> getElementRef(long index)
      Description copied from class: ACountable
      Gets a Ref to the element at the specified element index in this collection
      Specified by:
      getElementRef in class ACountable<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      index - Index of element to get
      Returns:
      Element at the specified index
    • get

      public final MapEntry<K,​V> get(long i)
      Description copied from class: ACountable
      Gets the element at the specified element index in this collection
      Specified by:
      get in class ACountable<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      i - Index of element to get
      Returns:
      Element at the specified index
    • getEntry

      public abstract MapEntry<K,​V> getEntry(ACell k)
      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

      public V get(Object key)
      Specified by:
      get in interface Map<K extends ACell,​V extends ACell>
    • get

      public abstract V get(ACell key)
      Description copied from class: ADataStructure
      Get the value associated with a given key.
      Specified by:
      get in class ADataStructure<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      key - Associative key to look up
      Returns:
      Value from collection, or a falsey value (null or false) if not found
    • get

      public final V get(ACell key, ACell notFound)
      Gets the value at a specified key, or returns the fallback value if not found
      Specified by:
      get in class ADataStructure<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      key - Key to lookup in Map
      notFound - Fallback value to return if key is not present
      Returns:
      Value for the specified key, or the notFound value.
    • reduceValues

      public abstract <R> R reduceValues(BiFunction<? super R,​? super V,​? extends R> func, R initial)
      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 value
      initial - Initial reduction value
      Returns:
      The final reduction value
    • filterValues

      public AMap<K,​V> filterValues(Predicate<V> pred)
      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 entry
      initial - Initial reduction value
      Returns:
      The final reduction value
    • keySet

      public Set<K> keySet()
      Specified by:
      keySet in interface Map<K extends ACell,​V extends ACell>
    • equalsKeys

      public abstract boolean equalsKeys(AMap<K,​V> map)
      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

      public final boolean equals(ACell a)
      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 offer have a more efficient equals implementation. MUST NOT require reads from Store.
      Overrides:
      equals in class ACell
      Parameters:
      a - Cell to compare with. May be null??
      Returns:
      True if this cell is equal to the other object
    • equals

      public abstract boolean equals(AMap<K,​V> a)
      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

      protected abstract MapEntry<K,​V> getEntryByHash(Hash hash)
      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

      public <R extends ACell> ADataStructure<R> conj(R x)
      Adds a new map entry to this map. The argument must be a valid map entry or length 2 vector.
      Specified by:
      conj in class ADataStructure<MapEntry<K extends ACell,​V extends ACell>>
      Type Parameters:
      R - Type of Value added
      Parameters:
      x - An object that can be cast to a MapEntry
      Returns:
      Updated map with the specified entry added, or null if the argument is not a valid map entry
    • entryVector

      public AVector<MapEntry<K,​V>> entryVector()
      Gets a vector of all map entries.
      Returns:
      Vector map entries, in map-defined order.
    • slice

      public AMap slice(long start, long end)
      Description copied from class: ACountable
      Gets a slice of this data structure
      Specified by:
      slice in class ACountable<MapEntry<K extends ACell,​V extends ACell>>
      Parameters:
      start - Start index (inclusive)
      end - end index (exclusive)
      Returns:
      Slice of data structure, or null if invalid slice