Class LocalHash

  • All Implemented Interfaces:
    DataStructure

    class LocalHash
    extends Hash
    Pull the caching used only by KBucketImpl out of Hash and put it here.
    Since:
    0.7.14
    Author:
    jrandom, moved from Hash.java by zzz
    • Constructor Detail

      • LocalHash

        public LocalHash​(Hash h)
      • LocalHash

        public LocalHash​(byte[] b)
    • Method Detail

      • prepareCache

        public void prepareCache()
        Prepare this hash's cache for xor values - very few hashes will need it, so we don't want to waste the memory, and lazy initialization would incur online overhead to verify the initialization.
      • cachedXor

        public byte[] cachedXor​(Hash key)
                         throws IllegalStateException
        Calculate the xor with the current object and the specified hash, caching values where possible. Currently this keeps up to MAX_CACHED_XOR (1024) entries, and uses an essentially random ejection policy. Later perhaps go for an LRU or FIFO?
        Throws:
        IllegalStateException - if you try to use the cache without first preparing this object's cache via .prepareCache()
      • clearXorCache

        public void clearXorCache()