Class ByteArraySet


  • class ByteArraySet
    extends java.lang.Object
    Specialized set for byte arrays, interpreted as strings for use in PathFilterGroup.Group. Most methods assume the hash is already know and therefore requires the caller to supply it beforehand. The implementation is a loose derivative of ObjectIdSubclassMap.

    The class is only intended for use by PathFilterGroup.

    The arrays stored may not be changed after adding.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  ByteArraySet.Hasher
      An incremental hash function.
    • Constructor Summary

      Constructors 
      Constructor Description
      ByteArraySet​(int capacity)
      Create an empty set.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) byte[] addIfAbsent​(byte[] newValue, int length, int hash)
      Store a byte array for future lookup.
      private int chainlength​(byte[] b)  
      (package private) boolean contains​(byte[] toFind, int length, int hash)
      Returns true if this set contains the specified array.
      private static byte[] copyIfNotSameSize​(byte[] newValue, int length)  
      private static boolean equals​(byte[] storedObj, byte[] toFind, int length)  
      private byte[] get​(byte[] toFind, int length, int hash)  
      private void grow()  
      private void initTable​(int sz)  
      private void insert​(byte[] newValue, int hash)  
      (package private) boolean isEmpty()  
      (package private) int size()  
      (package private) byte[][] toArray()  
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • size

        private int size
      • grow

        private int grow
      • mask

        private int mask
      • table

        private byte[][] table
    • Constructor Detail

      • ByteArraySet

        ByteArraySet​(int capacity)
        Create an empty set.
        Parameters:
        capacity -
    • Method Detail

      • get

        private byte[] get​(byte[] toFind,
                           int length,
                           int hash)
      • equals

        private static boolean equals​(byte[] storedObj,
                                      byte[] toFind,
                                      int length)
      • contains

        boolean contains​(byte[] toFind,
                         int length,
                         int hash)
        Returns true if this set contains the specified array.
        Parameters:
        toFind - array to find.
        length - The number of bytes in toFind that are used
        hash - pre-computed hash of toFind
        Returns:
        true if the mapping exists for this byte array; false otherwise.
      • addIfAbsent

        byte[] addIfAbsent​(byte[] newValue,
                           int length,
                           int hash)
        Store a byte array for future lookup.

        Stores newValue, but only if it does not already exist in the set. Callers can tell if the value is new by checking the return value with reference equality:

         byte[] obj = ...;
         boolean wasNew = map.addIfAbsent(array, length, hash) == array;
         
        Parameters:
        newValue - the array to store by reference if the length is the same as the length parameter
        length - The number of bytes in newValue that are used
        hash - pre-computed hash of toFind
        Returns:
        newValue if stored, or the prior value already stored and that would have been returned had the caller used get(newValue) first.
      • copyIfNotSameSize

        private static byte[] copyIfNotSameSize​(byte[] newValue,
                                                int length)
      • size

        int size()
        Returns:
        number of arrays in the set
      • isEmpty

        boolean isEmpty()
        Returns:
        true if size() is 0.
      • insert

        private void insert​(byte[] newValue,
                            int hash)
      • grow

        private void grow()
      • initTable

        private void initTable​(int sz)
      • toString

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

        private int chainlength​(byte[] b)
      • toArray

        byte[][] toArray()