DecimalStringSplit implements org.apache.hadoop.hbase.util.RegionSplitter.SplitAlgorithm { @VisibleForTesting static int splitPoint(int numRegions, int cardinality, int index) { if (numRegions < index + 2) throw new IndexOutOfBoundsException("numRegions < index + 2"); if (numRegions > cardinality) throw new IllegalArgumentException("numRegions > cardinality"); return (int) (Math.floor((double) cardinality / (double) numRegions * (double)(index + 1))); } DecimalStringSplit(int cardinality); @Override byte[] split(byte[] start, byte[] end); @Override byte[][] split(int numRegions); @Override byte[] firstRow(); @Override byte[] lastRow(); @Override void setFirstRow(String userInput); @Override void setLastRow(String userInput); @Override byte[] strToRow(String input); @Override String rowToStr(byte[] row); @Override String separator(); void setFirstRow(byte[] userInput); void setLastRow(byte[] userInput);  }
@Test public void testSplitPoint() throws Exception { assertEquals(1, DecimalStringSplit.splitPoint(10, 10, 0)); assertEquals(9, DecimalStringSplit.splitPoint(10, 10, 8)); try { assertEquals(1, DecimalStringSplit.splitPoint(10, 10, 9)); fail(); } catch (IndexOutOfBoundsException ignore) { } assertEquals(10, DecimalStringSplit.splitPoint(10, 100, 0)); assertEquals(90, DecimalStringSplit.splitPoint(10, 100, 8)); try { assertEquals(10, DecimalStringSplit.splitPoint(10, 100, 9)); fail(); } catch (IndexOutOfBoundsException ignore) { } assertEquals(3, DecimalStringSplit.splitPoint(30, 100, 0)); assertEquals(6, DecimalStringSplit.splitPoint(30, 100, 1)); assertEquals(10, DecimalStringSplit.splitPoint(30, 100, 2)); assertEquals(13, DecimalStringSplit.splitPoint(30, 100, 3)); assertEquals(3, DecimalStringSplit.splitPoint(333, 1000, 0)); assertEquals(6, DecimalStringSplit.splitPoint(333, 1000, 1)); assertEquals(9, DecimalStringSplit.splitPoint(333, 1000, 2)); assertEquals(12, DecimalStringSplit.splitPoint(333, 1000, 3)); assertEquals(996, DecimalStringSplit.splitPoint(333, 1000, 331)); assertEquals(33, DecimalStringSplit.splitPoint(3, 100, 0)); assertEquals(66, DecimalStringSplit.splitPoint(3, 100, 1)); assertEquals(33, DecimalStringSplit.splitPoint(30, 1000, 0)); assertEquals(66, DecimalStringSplit.splitPoint(30, 1000, 1)); assertEquals(100, DecimalStringSplit.splitPoint(30, 1000, 2)); assertEquals(133, DecimalStringSplit.splitPoint(30, 1000, 3)); assertEquals(166, DecimalStringSplit.splitPoint(30, 1000, 4)); assertEquals(200, DecimalStringSplit.splitPoint(30, 1000, 5)); assertEquals(2, DecimalStringSplit.splitPoint(50, 100, 0)); assertEquals(4, DecimalStringSplit.splitPoint(50, 100, 1)); }