Class FixedMap

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

public class FixedMap extends AbstractFixedMap
A general-purpose XDM map implementation that is ordered, that holds any kind of key, and that supports incremental modification only by copying the whole map to a different structure.

The implementation is based on an array of keys, an array of corresponding values, and a mutable Java java.util.HashMap (but encapsulated so no mutation can take place after the map has been built) that maps atomic match keys to integer positions in the array. If put or remove operations are subsequently attempted, the map is copied to a different implementation structure that supports functional modification.

The underlying implementation uses an instance of HashMap<AtomicMatchKey, KeyValuePair> For many data types this means that the key is held twice, once as the key, and once as part of the value. The reason for this is that the keys() function needs to return the original keys as supplied, complete with type annotation, which would not (always) have the same equality semantics. The AtomicMatchKey is computed from the actual key and in some cases is simply a wrapper with a different equals() method.

  • Constructor Details

    • FixedMap

      protected FixedMap(AtomicValue[] keys, GroundedValue[] values, HashMap<AtomicMatchKey,Integer> index, int specVersion)
      Construct a FixedMap supplying the entries as an array of keys and a corresponding array of value. The caller is responsible for ensuring that there are no duplicate keys. The two arrays (of keys and values) must have the same length. The content of the arrays must not be subsequently modified.
      Parameters:
      keys - an array of keys
      values - a corresponding array of values
      index - a hash map indexing the values
  • Method Details

    • getKey

      protected AtomicValue getKey(int position)
      Description copied from class: AbstractFixedMap
      Get the key at a given offset. This method is provided for use by subclasses, which can store the actual key in different ways.
      Specified by:
      getKey in class AbstractFixedMap
      Parameters:
      position - the offset (sibling position within the ordered map) of the required key
      Returns:
      the key at the specified position