@Test public void testSizeBasic() { RangeSearchBST<Integer, Integer> test = new RangeSearchBST<>(); Assert.assertEquals(0, test.size(Integer.MIN_VALUE, Integer.MAX_VALUE)); test.put(1, 1); Assert.assertEquals(1, test.size(Integer.MIN_VALUE, Integer.MAX_VALUE)); Assert.assertEquals(1, test.size(Integer.MIN_VALUE, 1)); Assert.assertEquals(1, test.size(1, Integer.MAX_VALUE)); Assert.assertEquals(1, test.size(1, 1)); Assert.assertEquals(0, test.size(0, 0)); }
public int size(Key lo, Key hi) { if (lo == null || hi == null || lo.compareTo(hi) > 0) throw new IllegalArgumentException("input is not valid"); if (contains(hi)) return rank(hi) - rank(lo) + 1; return rank(hi) - rank(lo); }
RangeSearchBST extends RedBlackBSTWithNoExtraMemory<Key, Val> { public int size(Key lo, Key hi) { if (lo == null || hi == null || lo.compareTo(hi) > 0) throw new IllegalArgumentException("input is not valid"); if (contains(hi)) return rank(hi) - rank(lo) + 1; return rank(hi) - rank(lo); } }
RangeSearchBST extends RedBlackBSTWithNoExtraMemory<Key, Val> { public int size(Key lo, Key hi) { if (lo == null || hi == null || lo.compareTo(hi) > 0) throw new IllegalArgumentException("input is not valid"); if (contains(hi)) return rank(hi) - rank(lo) + 1; return rank(hi) - rank(lo); }  }
RangeSearchBST extends RedBlackBSTWithNoExtraMemory<Key, Val> { public int size(Key lo, Key hi) { if (lo == null || hi == null || lo.compareTo(hi) > 0) throw new IllegalArgumentException("input is not valid"); if (contains(hi)) return rank(hi) - rank(lo) + 1; return rank(hi) - rank(lo); }  int size(Key lo, Key hi); List<Key> search(Key lo, Key hi); }
RangeSearchBST extends RedBlackBSTWithNoExtraMemory<Key, Val> { public int size(Key lo, Key hi) { if (lo == null || hi == null || lo.compareTo(hi) > 0) throw new IllegalArgumentException("input is not valid"); if (contains(hi)) return rank(hi) - rank(lo) + 1; return rank(hi) - rank(lo); }  int size(Key lo, Key hi); List<Key> search(Key lo, Key hi);  }