Package org.pipecraft.infra.math
Class UUIDRangeSplitter
- java.lang.Object
-
- org.pipecraft.infra.math.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 Summary
Constructors Constructor Description UUIDRangeSplitter(int shardsCount)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetShardFor(String uuid)Finds the shard corresponding to a given UUID
-
-
-
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.
-
-