public int size() { if (from == null && to == null) return root.size; if (from == null) { Node to = toInclusive ? root.floor(this.to) : root.lower(this.to); if (to == nullNode) return 0; return root.indexOf(to) + 1; } if (to == null) { Node from = fromInclusive ? root.ceil(this.from) : root.higher(this.from); if (from == nullNode) return 0; return root.size - root.indexOf(from); } Node from = fromInclusive ? root.ceil(this.from) : root.higher(this.from); if (from == nullNode || !belongs(from.key)) return 0; Node to = toInclusive ? root.floor(this.to) : root.lower(this.to); return root.indexOf(to) - root.indexOf(from) + 1; }
public K higher(K k) { Node target = root.higher(k); if (target == nullNode) return null; if (belongs(target.key)) return target.key; return null; }
protected Node higher(K key) { if (compare(key, this.key) >= 0) return right.higher(key); Node result = left.higher(key); if (result == nullNode) return this; return result; }