Class SparseShapedMap

All Implemented Interfaces:
Callable, FunctionItem, GroundedValue, Item, Sequence

public class SparseShapedMap extends ShapedMap
A FlexibleShapedMap is an implementation of XDM maps optimised for the case where many maps have the same set of string-valued keys. This is a variant of ShapedMap which extends the capability by allowing entries to be optional (these are represented by nulls in the values array)

The keys() method delivers the keys in a consistent order.

The class implements the method ShapedMap.getWithPlan(AtomicValue, Stack) so that a lookup expression such as $record?field using a statically-known lookup key is able to use the slot number established on a previous call of the same expression, avoiding the cost of a hash lookup.

An entry in the map may be absent; this is indicated by the value in the relevant slot being a Java null.

  • Constructor Details

    • SparseShapedMap

      public SparseShapedMap(Shape shape, GroundedValue... values)
      Create an instance of a ShapedMap whose structure is defined by the supplied Shape
      Parameters:
      shape - the shape of the map, identifying the keys that are present
      values - the values to appear in the map, corresponding one-to-one with the keys that are defined in the Shape. A value may be null to indicate that the entry is absent.
  • Method Details

    • get

      public GroundedValue get(AtomicValue key)
      Get an entry from the Map
      Overrides:
      get in class ShapedMap
      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
      Overrides:
      size in class ShapedMap
      Returns:
      the number of keys/entries present in this map
    • keys

      public AtomicIterator keys()
      Get the set of all key values in the map.
      Overrides:
      keys in class ShapedMap
      Returns:
      a set containing all the key values present in the map. Normally the order is unpredictable, but for a ShapedMap the order is defined by the Shape.
    • keyValuePairs

      public Iterable<KeyValuePair> keyValuePairs()
      Get the set of all key-value pairs in the map
      Overrides:
      keyValuePairs in class ShapedMap
      Returns:
      an iterable containing all the key-value pairs
    • getItemType

      public ItemType getItemType(TypeHierarchy th)
      Get the type of the map. This method is used largely for diagnostics, to report the type of a map when it differs from the required type.
      Overrides:
      getItemType in class ShapedMap
      Parameters:
      th - the type hierarchy cache
      Returns:
      the type of this map