Class MappedCompressedString

All Implemented Interfaces:
StringAlike<MappedCompressedString>, StringCompatible, Serializable, CharSequence, Comparable<CharSequence>

public final class MappedCompressedString extends AbstractCompressedString<MappedCompressedString>
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 Details

  • Constructor Details

    • MappedCompressedString

      public MappedCompressedString(String data)
    • MappedCompressedString

      public MappedCompressedString(char[] data, int offset, int length)
    • MappedCompressedString

      public MappedCompressedString(char[] data)
    • MappedCompressedString

      public MappedCompressedString(ByteBuffer data, int offset, int length)
    • MappedCompressedString

      public MappedCompressedString(ByteBuffer data)
    • MappedCompressedString

      public MappedCompressedString(byte[] data, int offset, int length)
    • MappedCompressedString

      public MappedCompressedString(byte[] data)
  • Method Details

    • toCompressedString

      @NotNull public @NotNull CompressedString 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

      @NotNull public @NotNull MappedCompressedString 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

      protected final MappedCompressedString convertValue(String string)
      Description copied from class: AbstractCompressedString
      Convert a String to this type.
      Specified by:
      convertValue in class AbstractCompressedString<MappedCompressedString>
      Parameters:
      string - The String to convert
      Returns:
      A new TYPE with the same contents as String, assuming ISO-8859-1 encoding
    • convertValue

      protected final MappedCompressedString convertValue(byte[] data, int offset, int length)
      Description copied from class: AbstractCompressedString
      Convert a byte array to this type, assuming ISO-8859-1
      Specified by:
      convertValue in class AbstractCompressedString<MappedCompressedString>
      Parameters:
      data - The data to convert
      offset - The starting index from data to convert
      length - 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

      public final int putIfAbsent(SimpleReference<?> key, int potentialValue)
      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.