Example #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;
 }
Example #2
0
 public int indexOf(Node node) {
   if (this == node) return left.size;
   if (compare(node.key, this.key) > 0) return left.size + 1 + right.indexOf(node);
   return left.indexOf(node);
 }