Class UUIDRangeSplitter


  • public class UUIDRangeSplitter
    extends Object
    Splits the UUID value range into K equal sized continuous shards, and returns the thresholds. Also allows determining the shard index given a UUID. The UUID space is assumed to have all letter case representations, but a single UUID is assumed to be consistent with regards to letter case. We assume plain string ordering, as defined by Java's String comparator. This class is useful for sharding.
    Author:
    Eyal Schneider
    • Constructor Detail

      • UUIDRangeSplitter

        public UUIDRangeSplitter​(int shardsCount)
        Constructor
        Parameters:
        shardsCount - The required number of shards. Must be positive.
    • Method Detail

      • getShardFor

        public int getShardFor​(String uuid)
        Finds the shard corresponding to a given UUID
        Parameters:
        uuid - The UUID. Must have a valid format, otherwise results are unpredictable.
        Returns:
        The shard index, as an integer between 0 and shardsCount-1.