Class ByteArraySet

java.lang.Object
org.eclipse.jgit.treewalk.filter.ByteArraySet

class ByteArraySet extends 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 
    An incremental hash function.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int
     
     
    private int
     
    private int
     
    private byte[][]
     
  • Constructor Summary

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

    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
     
    private void
    initTable(int sz)
     
    private void
    insert(byte[] newValue, int hash)
     
    (package private) boolean
     
    (package private) int
     
    (package private) byte[][]
     

    Methods inherited from class java.lang.Object

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

    • size

      private int size
    • grow

      private int grow
    • mask

      private int mask
    • table

      private byte[][] table
    • hasher

      private ByteArraySet.Hasher hasher
  • Constructor Details

    • ByteArraySet

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

    • 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 String toString()
      Overrides:
      toString in class Object
    • chainlength

      private int chainlength(byte[] b)
    • toArray

      byte[][] toArray()