public class HashInterner<T> extends Object implements Interner<T>
Interner.
Identity is determined via Object.equals(Object) and Object.hashCode(), thus stored instances
must guarantee that hashCode is consistent with equals. This implementation can return different object
references in the case of two concurrent get(Object) calls
Speed: The implementation is twice as fast as Guavas Interner, and 5 times as fast as String.intern(). Measurement via bb Microbenchmark tool (ticket SRT-6053). Time in microseconds (us) for 1000 interns:
| Constructor and Description |
|---|
HashInterner()
Creates an Interner with 100 expected elements as sizing hint for the underlying Map.
|
HashInterner(int expectedElements)
Creates an Interner with expectedElements as sizing hint for the underlying Map.
|
| Modifier and Type | Method and Description |
|---|---|
T |
get(T value)
Returns a shared instance for the given value.
|
int |
size() |
String |
toString() |
public HashInterner()
public HashInterner(int expectedElements)
expectedElements - The expected number of elementspublic T get(T value)
InternerString.intern(), if it is not found. Identity is determined in an implementation specific way,
which is documented by the implementation.
Further calls with the same value will typically return the interned value, but this interface does not mandate that the same shared instance is returned under under all circumstances. The implementing class should clearly document exemptions. Typical reasons are values that are only stored for a limited lifetime, or tradeoffs during concurrent writes for the sake of speed.
Implementations must be thread-safe.
public int size()
Copyright © 2018 trivago. All rights reserved.