Class ExtensibleMap

All Implemented Interfaces:
Iterable<KeyValuePair>, Callable, FunctionItem, GroundedValue, Item, Sequence

public class ExtensibleMap extends MapWithTypeCache implements Iterable<KeyValuePair>
A general-purpose XDM map implementation that is ordered, that holds any kind of key, and that supports incremental modification. Any duplicates added during map construction follow "use-last" semantics - the new value replaces the old. This structure is therefore unsuited to cases where duplicates need custom handling.

The implementation is similar to that of AbstractFixedMap, but the arrays of keys and values are replaced by ZenoChains to allow functional modification, and the map from atomic match keys to integer offsets is replaced by an immutable map (currently from the VAVR library).

Because the integer offset of an entry within the ordered map is held in the index structure and must therefore remain intact, the remove(AtomicValue) operation does not physically remove entries, but instead adds them to a list of "logically removed" entries.

  • Constructor Details

    • ExtensibleMap

      public ExtensibleMap(int specVersion)
  • Method Details

    • copyOf

      public static ExtensibleMap copyOf(MapItem map)
      Construct an ExtensibleMap from the contents of an existing map
      Parameters:
      map - an existing map
    • get

      public GroundedValue get(AtomicValue key)
      Get an entry from the Map
      Specified by:
      get in class MapItem
      Parameters:
      key - the value of the key
      Returns:
      the value associated with the given key, or null if the key is not present in the map.
    • size

      public int size()
      Get the size of the map
      Specified by:
      size in class MapItem
      Returns:
      the number of keys/entries present in this map
    • keyValuePairs

      public Iterable<KeyValuePair> keyValuePairs()
      Get the content as an iterable collection of key value pairs
      Specified by:
      keyValuePairs in class MapItem
      Returns:
      an iterable collection of key value pairs
    • iterator

      public Iterator<KeyValuePair> iterator()
      Return an iterator of key-value pairs.
      Specified by:
      iterator in interface Iterable<KeyValuePair>
      Returns:
      an Iterator of key-value pairs.
    • put

      public MapItem put(AtomicValue key, GroundedValue value)
      Create a new map containing the existing entries in the map plus an additional entry, without modifying the original. If there is already an entry with the specified key, this entry is replaced by the new entry.
      Specified by:
      put in class MapItem
      Parameters:
      key - the key of the new entry
      value - the value associated with the new entry
      Returns:
      the new map containing the additional entry
    • remove

      public MapItem remove(AtomicValue key)
      Remove an entry from the map
      Specified by:
      remove in class MapItem
      Parameters:
      key - the key of the entry to be removed
      Returns:
      a new map in which the requested entry has been removed; or this map unchanged if the specified key was not present
    • getOffset

      public static int getOffset(ImmutableHashTrieMap<AtomicMatchKey,Integer> index, AtomicMatchKey key)
      Get the offset of an entry in the map (that is, its 0-based position in the map ordering
      Parameters:
      key - the required key
      Returns:
      the 0-based position of the relevant entry in the map, or -1 if the key is not present