Class HashTrieMap

    • Constructor Detail

      • HashTrieMap

        public HashTrieMap()
        Create an empty map
      • HashTrieMap

        public HashTrieMap​(ImmutableMap<AtomicMatchKey,​KeyValuePair> imap)
        Create a map whose contents are a copy of an existing immutable map
        Parameters:
        imap - the map to be copied
    • Method Detail

      • singleton

        public static HashTrieMap singleton​(AtomicValue key,
                                            GroundedValue value)
        Create a singleton map with a single key and value
        Parameters:
        key - the key value
        value - the associated value
        Returns:
        a singleton map
      • copy

        public static HashTrieMap copy​(MapItem map)
        Create a map whose entries are copies of the entries in an existing MapItem
        Parameters:
        map - the existing map to be copied
        Returns:
        the new map
      • size

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

        public boolean isEmpty()
        Ask whether the map is empty
        Specified by:
        isEmpty in interface MapItem
        Returns:
        true if and only if the size of the map is zero
      • conforms

        public boolean conforms​(AtomicType requiredKeyType,
                                SequenceType requiredValueType,
                                TypeHierarchy th)
        Ask whether the map conforms to a given map type
        Specified by:
        conforms in interface MapItem
        Parameters:
        requiredKeyType - the required keyType
        requiredValueType - the required valueType
        th - the type hierarchy cache for the configuration
        Returns:
        true if the map conforms to the required type
      • getItemType

        public MapType 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. This method has the side-effect of updating the internal type information held within the map.
        Specified by:
        getItemType in interface MapItem
        Parameters:
        th - The type hierarchy cache for the configuration
        Returns:
        the type of this map
      • getKeyUType

        public UType getKeyUType()
        Get the lowest common item type of the keys in the map
        Specified by:
        getKeyUType in interface MapItem
        Returns:
        the most specific type to which all the keys belong. If the map is empty, return UType.VOID (the type with no instances)
      • addEntry

        public HashTrieMap addEntry​(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:
        addEntry in interface 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
      • initialPut

        public boolean initialPut​(AtomicValue key,
                                  GroundedValue value)
        Add a new entry to this map. Since the map is supposed to be immutable, this method must only be called while initially populating the map, and must not be called if anyone else might already be using the map.
        Parameters:
        key - the key of the new entry. Any existing entry with this key is replaced.
        value - the value associated with the new entry
        Returns:
        true if an existing entry with the same key was replaced
      • remove

        public HashTrieMap remove​(AtomicValue key)
        Remove an entry from the map
        Specified by:
        remove in interface 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
      • get

        public GroundedValue get​(AtomicValue key)
        Get an entry from the Map
        Specified by:
        get in interface 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
      • getKeyValuePair

        public KeyValuePair getKeyValuePair​(AtomicValue key)
        Get an key/value pair from the Map
        Parameters:
        key - the value of the key
        Returns:
        the key-value-pair associated with the given key, or null if the key is not present in the map
      • keys

        public AtomicIterator<? extends AtomicValue> keys()
        Get the set of all key values in the map
        Specified by:
        keys in interface MapItem
        Returns:
        an iterator over the keys, in undefined order
      • keyValuePairs

        public java.lang.Iterable<KeyValuePair> keyValuePairs()
        Get the set of all key-value pairs in the map
        Specified by:
        keyValuePairs in interface MapItem
        Returns:
        an iterable whose iterator delivers the key-value pairs
      • diagnosticDump

        public void diagnosticDump()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object