Пример #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);
      }
    }
  }
Пример #2
0
 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);
 }
Пример #3
0
 public static Matcher characterRangeMatcher(CharacterRange range) {
   return (input, i) ->
       input.charAt(i) >= range.getStart() && input.charAt(i) <= range.getEnd() ? 1 : -1;
 }
Пример #4
0
 public void insert(CharacterRange range, T val) {
   insert(range, root, new Node<T>(range.getStart(), range.getEnd(), val));
 }