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 lower(K k) { Node target = root.lower(k); if (target == nullNode) return null; if (belongs(target.key)) return target.key; return null; }
protected Node lower(K key) { if (compare(key, this.key) <= 0) return left.lower(key); Node result = right.lower(key); if (result == nullNode) return this; return result; }