Class RankedSet

java.lang.Object
com.apple.foundationdb.async.RankedSet

@API(UNSTABLE) public class RankedSet extends Object
RankedSet supports the efficient retrieval of elements by their rank as defined by lexicographic order.

Elements are added or removed from the set as byte-array keys.

The fundamental operations are:

The set is implemented as a skip-list with a specified number of levels. Level zero has one entry for each element. Coarser levels have a sampling of values, determined by bits the hash code of their key.

The skip-list is stored as key-value pairs within a given subspace, where the key is a tuple of the form [level, key] and the value is the number of elements between this key and the previous key at the same level, encoded as a little-endian long.

  • Field Details

    • JDK_ARRAY_HASH

      public static final RankedSet.HashFunction JDK_ARRAY_HASH
      Hash using the JDK's default byte array hash. This hash does not have great distribution for certain values with low entropy.
    • CRC_HASH

      public static final RankedSet.HashFunction CRC_HASH
      Hash using 32-bit CRC. Although not designed for hashing, this does often give better distribution than JDK_ARRAY_HASH.
    • RANDOM_HASH

      public static final RankedSet.HashFunction RANDOM_HASH
      Hash using a random number. The result is actually independent of the key.
    • DEFAULT_HASH_FUNCTION

      public static final RankedSet.HashFunction DEFAULT_HASH_FUNCTION
      The default hash function to use. For reasons of compatibility with existing data, this defaults to the JDK's array hash.
    • MAX_LEVELS

      public static final int MAX_LEVELS
      See Also:
    • DEFAULT_LEVELS

      public static final int DEFAULT_LEVELS
      See Also:
    • DEFAULT_CONFIG

      public static final RankedSet.Config DEFAULT_CONFIG
    • subspace

      protected final Subspace subspace
    • executor

      protected final Executor executor
    • config

      protected final RankedSet.Config config
  • Constructor Details

    • RankedSet

      public RankedSet(Subspace subspace, Executor executor, RankedSet.Config config)
      Initialize a new ranked set.
      Parameters:
      subspace - the subspace where the ranked set is stored
      executor - an executor to use when running asynchronous tasks
      config - configuration to use
    • RankedSet

      public RankedSet(Subspace subspace, Executor executor, RankedSet.HashFunction hashFunction, int nlevels)
      Initialize a new ranked set. Although not (yet) deprecated, this constructor is mainly for compatibility and RankedSet(Subspace, Executor, Config) may be superior in new code.
      Parameters:
      subspace - the subspace where the ranked set is stored
      executor - an executor to use when running asynchronous tasks
      hashFunction - hash function for new ranked set
      nlevels - number of skip list levels for new ranked set
    • RankedSet

      public RankedSet(Subspace subspace, Executor executor, int nlevels)
      Initialize a new ranked set. Although not (yet) deprecated, this constructor is mainly for compatibility and RankedSet(Subspace, Executor, Config) may be superior in new code.
      Parameters:
      subspace - the subspace where the ranked set is stored
      executor - an executor to use when running asynchronous tasks
      nlevels - number of skip list levels for new ranked set
    • RankedSet

      public RankedSet(Subspace subspace, Executor executor)
      Initialize a new ranked set with the default configuration.
      Parameters:
      subspace - the subspace where the ranked set is stored
      executor - an executor to use when running asynchronous tasks
  • Method Details