Пример #1
0
 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;
 }
Пример #2
0
 public K lower(K k) {
   Node target = root.lower(k);
   if (target == nullNode) return null;
   if (belongs(target.key)) return target.key;
   return null;
 }
Пример #3
0
 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;
 }