net.i2p.router.networkdb.kademlia

## Class LocalHash

- java.lang.Object
- - net.i2p.data.SimpleDataStructure
  - - net.i2p.data.Hash
    - - net.i2p.router.networkdb.kademlia.LocalHash

- All Implemented Interfaces:
    DataStructure

      class LocalHash
      extends Hash

  Pull the caching used only by KBucketImpl out of Hash and put it here.

- - ### Field Summary

    - ### Fields inherited from class net.i2p.data.Hash

      `FAKE_HASH, HASH_LENGTH`

    - ### Fields inherited from class net.i2p.data.SimpleDataStructure

      `_data`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LocalHash(byte[] b)`
    `LocalHash(Hash h)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `cachedXor(Hash key)` Calculate the xor with the current object and the specified hash, caching values where possible.
    `void` | `clearXorCache()`
    `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.

    - ### Methods inherited from class net.i2p.data.Hash

      `clearCache, create, create, create, hashCode, length, readBytes, setData, toBase32, toBase64`

    - ### Methods inherited from class net.i2p.data.SimpleDataStructure

      `calculateHash, equals, fromBase64, fromByteArray, getData, read, toByteArray, toString, writeBytes`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LocalHash

          public LocalHash(byte[] b)

    - #### LocalHash

          public LocalHash(Hash h)

  - ### Method Detail

    - #### 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()

    - #### 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.