Class MultiBinaryLongMap.MaskedBinaryLongMap

  • All Implemented Interfaces:
    BinaryLongMap
    Direct Known Subclasses:
    MultiBinaryLongMap.LeftoverLongMapHolder.LeftoverMaskedBinaryLongMap
    Enclosing class:
    MultiBinaryLongMap

    public static class MultiBinaryLongMap.MaskedBinaryLongMap
    extends Object
    implements BinaryLongMap
    MaskedBinaryLongMap is a BinaryLongMap which represents a mapping from a Binary to a fixed-bit-width numeric value (though exposed as a long datatype), based on an underlying BinaryLongMap. Values returned from the resulting map will be sign-extended to the long data-type and it is the responsibility of calling code intending to use this map to store unsigned values to adjust/mask the sign accordingly.

    MaskedBinaryLongMap is not thread-safe, and it is the caller's responsibility to ensure that any concurrent access to the MaskedBinaryLongMap is protected in a manner consistent with the underlying BinaryLongMap.

    • Field Detail

      • f_blm

        protected final BinaryLongMap f_blm
        The underlying BinaryLongMap.
      • m_cShift

        protected int m_cShift
        The number of bits that the logical value represented by this MaskedBinaryLongMap is shifted left in the underlying physical representation.
      • f_cBits

        protected final int f_cBits
        The number of bits that the logical value represented by this MaskedBinaryLongMap is limited to in the underlying physical representation.
      • f_nMask

        protected long f_nMask
        The bit-mask representing the positions used to store values in the underlying physical representation.
    • Constructor Detail

      • MaskedBinaryLongMap

        public MaskedBinaryLongMap​(MultiBinaryLongMap.MaskedLongMapHolder holder,
                                   BinaryLongMap blm,
                                   int cShift,
                                   int cBits)
        Construct a MaskedBinaryLongMap based on the specified binary long map using the specified shift and bit-widths. More formally, the logical value stored by this MaskedBinaryLongMap is represented in the underlying physical BinaryLongMap as: lValueLogical = (lValuePhysical >> cShift) & ((1 << cBits) - 1)
        Parameters:
        holder - the MaskedLongMapHolder associated with this MaskedBinaryLongMap
        blm - the underlying BinaryLongMap
        cShift - the number of positions to left-shift the values stored in this MaskedBinaryLongMap
        cBits - the number of bits in the values stored in this MaskedBinaryLongMap
    • Method Detail

      • getHolder

        public MultiBinaryLongMap.MaskedLongMapHolder getHolder()
        Return the MaskedLongMapHolder used to manage the lifecycle of this MaskedBinaryLongMap.
        Returns:
        the MaskedLongMapHolder
      • get

        public long get​(Binary binKey)
        Find the specified key in the map and return the value associated with it.
        Specified by:
        get in interface BinaryLongMap
        Parameters:
        binKey - a Binary key
        Returns:
        the value associated with the specified key, or 0L if the specified key is not in the map
      • 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.

        Specified by:
        put in interface BinaryLongMap
        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).

        Specified by:
        putIfAbsent in interface BinaryLongMap
        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.

        Specified by:
        replace in interface BinaryLongMap
        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.
        Specified by:
        remove in interface BinaryLongMap
        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.

        Specified by:
        remove in interface BinaryLongMap
        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.
        Specified by:
        clear in interface BinaryLongMap
      • size

        public int size()
        Determine the size of the map.
        Specified by:
        size in interface BinaryLongMap
        Returns:
        the number of unique keys stored in the map
      • keys

        public Iterator<Binary> keys()
        Obtain an iterator of the keys stored in the map.
        Specified by:
        keys in interface BinaryLongMap
        Returns:
        an Iterator of Binary keys
      • visit

        public void visit​(Binary binKey,
                          BinaryLongMap.EntryVisitor visitor)
        Apply the specified visitor to the entry associated with the specified key, if the entry exists or may be added. The visited entry may or may not logically exist in the BinaryLongMap (e.g. it may be associated with a value of 0L) but is guaranteed to be safe to be added or removed (via BinaryLongMap.Entry.setValue(long)).
        Specified by:
        visit in interface BinaryLongMap
        Parameters:
        binKey - the key to visit
        visitor - the visitor to apply
      • internKeys

        public void internKeys​(Object o)
        Internal opaque method: De-duplicate keys.
        Specified by:
        internKeys in interface BinaryLongMap
        Parameters:
        o - some implementation-specific object
      • decode

        protected long decode​(long lEncoded)
        Decode the n-bit value from the specified encoded long value.
        Parameters:
        lEncoded - the 64-bit encoded value to decode
        Returns:
        the decoded value
      • encode

        protected long encode​(long lEncoded,
                              long lValue)
        Encode the specified n-bit value into the possibly already encoded value, preserving any unrelated bits.
        Parameters:
        lEncoded - the 64-bit value to encode into
        lValue - the value to encode
        Returns:
        the new encoded value