Class HashTableUtils


  • public class HashTableUtils
    extends Object
    • Method Detail

      • previousPowerOfTwo

        public static int previousPowerOfTwo​(int n)
        Computes the previous power of two less than or equal to a given "n". The integer should be between 1 (inclusive) and Integer.MAX_VALUE for best results. Other parameters will return Integer.MIN_VALUE.
      • hashMemory

        public static int hashMemory​(org.apache.datasketches.memory.Memory memory,
                                     long position,
                                     int length)
        Compute a simple, fast hash code of some memory range.
        Parameters:
        memory - a region of memory
        position - position within the memory region
        length - length of memory to hash, starting at the position
      • memoryEquals

        public static boolean memoryEquals​(org.apache.datasketches.memory.Memory memory1,
                                           long offset1,
                                           org.apache.datasketches.memory.Memory memory2,
                                           long offset2,
                                           int length)
        Compare two memory ranges for equality. The purpose of this function is to be faster than BaseState.equalTo(long, java.lang.Object, long, long) for the small memory ranges that typically comprise keys in hash tables. As of this writing, it is. See "MemoryBenchmark" in the druid-benchmarks module for performance evaluation code.
        Parameters:
        memory1 - a region of memory
        offset1 - position within the first memory region
        memory2 - another region of memory
        offset2 - position within the second memory region
        length - length of memory to compare, starting at the positions