Package io.deephaven.base.string.cache
Class MappedCompressedString
java.lang.Object
io.deephaven.base.string.cache.AbstractCompressedString<MappedCompressedString>
io.deephaven.base.string.cache.MappedCompressedString
- All Implemented Interfaces:
StringAlike<MappedCompressedString>
,StringCompatible
,Serializable
,CharSequence
,Comparable<CharSequence>
This is a ridiculously simple, light-as-I-can-make-it, but decidedly single-purpose data structure. Specifically,
it's a CompressedString with an embedded (to avoid reference or Object instance overhead) open-addressed
SimpleReference<Object>-identity -> int hash map with load factor 1 (100%) and no public operations other
than "putIfAbsent".
The reason for requiring that key objects be SimpleReferences is to allow for O(1) automatic slot reclamation across
many MappedCompressedString instances at the same time. A given source of mappings creates a single SimpleReference
to use as a key, and may invalidate mappings (creating a deleted slot) simply by clearing the SimpleReference. In
practice, a WeakSimpleReference to the source itself is used, in order to also allow garbage collection of the
mapping source object to invalidate all of its mappings.
Unfortunately, I haven't figured out a way to make this allow concurrent gets.
The intended use is in Deephaven import code, for storing SymbolManager -> SymbolId mappings on the
CompressedString that represents the Symbol itself, typically inside of a (bounded) StringCache of
MappedCompressedString instances.
Note that this uses io.deephaven.base.reference.SimpleReference instead of java.lang.ref.Reference so that unit tests
can avoid being required to use the concrete sub-classes of Reference, which all come with GC-related side-effects.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMappedCompressedString
(byte[] data) MappedCompressedString
(byte[] data, int offset, int length) MappedCompressedString
(char[] data) MappedCompressedString
(char[] data, int offset, int length) MappedCompressedString
(String data) MappedCompressedString
(ByteBuffer data, int offset, int length) -
Method Summary
Modifier and TypeMethodDescriptionfinal int
capacity()
protected final MappedCompressedString
convertValue
(byte[] data, int offset, int length) Convert a byte array to this type, assuming ISO-8859-1protected final MappedCompressedString
convertValue
(String string) Convert a String to this type.final int
putIfAbsent
(SimpleReference<?> key, int potentialValue) Add the specified <key, value> pair if no mapping already exists for key.@NotNull CompressedString
Convert this StringCompatible into a CompressedString.@NotNull MappedCompressedString
Convert this StringCompatible into a MappedCompressedString.Methods inherited from class io.deephaven.base.string.cache.AbstractCompressedString
charAt, codePointAt, codePointBefore, codePointCount, compareTo, compareToIgnoreCase, concat, concat, contains, contentEquals, endsWith, equals, equalsIgnoreCase, getBytes, getChars, getData, hashCode, indexOf, indexOf, indexOf, indexOf, intern, isEmpty, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, length, matches, regionMatches, replace, replace, replaceAll, replaceFirst, split, split, startsWith, startsWith, subSequence, substring, substring, toCharArray, toLowerCase, toLowerCase, toString, toUpperCase, toUpperCase, trim
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
NULL_MAPPING_VALUE
public static final int NULL_MAPPING_VALUE- See Also:
-
-
Constructor Details
-
MappedCompressedString
-
MappedCompressedString
public MappedCompressedString(char[] data, int offset, int length) -
MappedCompressedString
public MappedCompressedString(char[] data) -
MappedCompressedString
-
MappedCompressedString
-
MappedCompressedString
public MappedCompressedString(byte[] data, int offset, int length) -
MappedCompressedString
public MappedCompressedString(byte[] data)
-
-
Method Details
-
toCompressedString
Description copied from interface:StringCompatible
Convert this StringCompatible into a CompressedString. Implementations should not cache result CompressedStrings, in order to avoid inadvertently allowing promotion of short-lived objects under generational garbage collection.- Returns:
- A newly constructed CompressedString representing the same sequence of characters as this StringCompatible (or this object, if appropriate).
-
toMappedCompressedString
Description copied from interface:StringCompatible
Convert this StringCompatible into a MappedCompressedString. Implementations should not cache result CompressedStrings, in order to avoid inadvertently allowing promotion of short-lived objects under generational garbage collection.- Returns:
- A newly constructed MappedCompressedString representing the same sequence of characters as this StringCompatible (or this object, if appropriate).
-
convertValue
Description copied from class:AbstractCompressedString
Convert a String to this type.- Specified by:
convertValue
in classAbstractCompressedString<MappedCompressedString>
- Parameters:
string
- The String to convert- Returns:
- A new TYPE with the same contents as String, assuming ISO-8859-1 encoding
-
convertValue
Description copied from class:AbstractCompressedString
Convert a byte array to this type, assuming ISO-8859-1- Specified by:
convertValue
in classAbstractCompressedString<MappedCompressedString>
- Parameters:
data
- The data to convertoffset
- The starting index from data to convertlength
- The length to convert- Returns:
- A new TYPE with the same contents as the specified region of data, assuming ISO-8859-1 encoding
-
capacity
public final int capacity() -
putIfAbsent
Add the specified <key, value> pair if no mapping already exists for key.- Parameters:
key
- A non-null Reference to an arbitrary object whose reachability determines mapping validity.potentialValue
- The value to insert if none already exists. Must not equal NULL_MAPPING_VALUE.- Returns:
- The existing mapped value, if present, or NULL_MAPPING_VALUE if potentialValue was used.
-