Class MultiBinaryLongMap.DelegatingBinaryLongMap

  • All Implemented Interfaces:
    BinaryLongMap
    Enclosing class:
    MultiBinaryLongMap

    public static class MultiBinaryLongMap.DelegatingBinaryLongMap
    extends MultiBinaryLongMap.AbstractDelegateBinaryLongMap
    An implementation of BinaryLongMap that uses another BinaryLongMap to store its keys and one index of a LongStorage to store its values. This allows a number of BinaryLongMap instances to be created that share a single other BinaryLongMap (e.g. BinaryRadixTree) instance.

    This implementation differs substantially from the BinaryLongMap interface's contract in the following ways:

    1. There is a concept of a primary BinaryLongMap instance, which owns the keys in the underlying BinaryRadixTree;
    2. Only the primary can add and remove keys;
    3. Other instances besides the primary will generate exceptions if they attempt to add keys that aren't already in the primary, and will store zero values when they attempt to remove keys (which will have the effect of removing that key from the keys() iterator for the instance);
    4. The key iterator for the non-primary instances will only iterate keys with non-zero values (which is to be expected);
    5. Since the primary instance can remove keys, and since that removal will also remove the same keys from all other dependent instances, consumers of the dependent instances should use a BinaryLongMapListener to listen to changes to the primary instance.
    In each of these cases, it should be apparent that using dependent instances requires some knowledge of the specific implementation behavior of the DelegatingBinaryLongMap, and thus the substitutability of DelegatingBinaryLongMap for BinaryRadixTree cannot be done blindly.

    • Constructor Detail

      • DelegatingBinaryLongMap

        public DelegatingBinaryLongMap​(BinaryLongMap blm,
                                       MultiBinaryLongMap.LongStorage store,
                                       int iIndex)
        Construct a DelegatingBinaryLongMap.
        Parameters:
        blm - the BinaryLongMap that holds the keys for this map
        store - the LongStorage that holds the values for this map
        iIndex - the index into the LongStorage for this map; must be > 0
    • Method Detail

      • put

        public void put​(Binary binKey,
                        long lValue)
        Blindly store the passed value for the specified key, adding the key if it is not already in the map, or replacing the current value if the key is in the map.

        Note that associating the value zero with a key is analogous to removing the key.

        Parameters:
        binKey - the Binary key to add or update
        lValue - the value to associate with the key
      • putIfAbsent

        public boolean putIfAbsent​(Binary binKey,
                                   long lValue)
        Store the passed value for the specified key, only if the key does not currently exist in the map.

        Note that associating the value zero with a key using this method will have no effect, since were that key already present, there would be no change, and were it not present, the value zero is analogous to removing the key, which again is no change (since it is not present).

        Parameters:
        binKey - a Binary key
        lValue - the new value to associate with the passed key
        Returns:
        true iff the key was not present in the map, and now it is present in the map associated with the passed value
      • replace

        public boolean replace​(Binary binKey,
                               long lValueOld,
                               long lValueNew)
        Store the passed "new" value for the specified key, only if the current value associated with the specified key is the same as the specified "old" value.

        Note that replacing the value of zero is analogous to putIfAbsent, and associating the value zero with a key using this method is the same as remove passing the old value to match.

        Parameters:
        binKey - a Binary key
        lValueOld - the assumed old value to replace
        lValueNew - the new value to associate with the passed key
        Returns:
        true iff the key was associated with the passed "old" value, and now it is associated with the passed "new" value
      • remove

        public void remove​(Binary binKey)
        Blindly remove the specified Binary key from the map.
        Parameters:
        binKey - a Binary key
      • remove

        public boolean remove​(Binary binKey,
                              long lValue)
        Remove the specified Binary key from the map iff it exists in the map and is associated with the specified value.

        Note that removing an association whose value is zero has no effect.

        Parameters:
        binKey - a Binary key
        lValue - the value that the key must have in order to be removed
        Returns:
        true iff the map contained the key, it was associated with the specified value, and has now been removed
      • clear

        public void clear()
        Initialize the map to an empty state.
      • size

        public int size()
        Determine the size of the map.
        Returns:
        the number of unique keys stored in the map