Beispiel #1
0
  private void insert(CharacterRange range, Node<T> parent, Node<T> newNode) {

    if (root == null) {
      root = newNode;
      countNodes++;
      return;
    }

    if (range.getStart() < parent.start) {
      if (parent.left == null) {
        addToLeft(parent, newNode);
        updateHeight(newNode);
        if (parent.parent != null) balance(parent.parent, parent);
      } else {
        insert(range, parent.left, newNode);
      }
    } else if (range.getEnd() > parent.end) {
      if (parent.right == null) {
        addToRight(parent, newNode);
        updateHeight(newNode);
        if (parent.parent != null) balance(parent.parent, parent);
      } else {
        insert(range, parent.right, newNode);
      }
    }
  }
 public static Matcher characterRangeBackwardsMatcher(CharacterRange range) {
   return (input, i) ->
       i == 0
           ? -1
           : (input.charAt(i - 1) >= range.getStart() && input.charAt(i - 1) <= range.getEnd()
               ? 1
               : -1);
 }
 public static Matcher characterRangeMatcher(CharacterRange range) {
   return (input, i) ->
       input.charAt(i) >= range.getStart() && input.charAt(i) <= range.getEnd() ? 1 : -1;
 }
Beispiel #4
0
 public void insert(CharacterRange range, T val) {
   insert(range, root, new Node<T>(range.getStart(), range.getEnd(), val));
 }