Example #1
0
  @SuppressWarnings("unchecked")
  @Override
  public Iterator<V> allPrefixesOf(CharSequence key) {

    int len = key.length() - 1;
    if (len < 0) return AOpenIterator.<V>empty();

    Object[] ary = new Object[len + 1];
    int maxNode = -1;
    IARTNode current = root;
    for (int depth = 0; depth < len; depth++) {
      int index = key.charAt(depth);
      V x = (V) current.getValue(index);
      if (x != null) {
        maxNode = depth;
        ary[depth] = x;
      }

      current = ((IARTNodeN) current).findNode(index);
      if (current == null) return new ValueArrayIterator<V>(ary, maxNode);
    }

    V x = (V) current.getValue(key.charAt(len));
    if (x != null) {
      ary[len] = x;
      maxNode = len;
    }
    return new ValueArrayIterator<V>(ary, maxNode);
  }
Example #2
0
  @SuppressWarnings("unchecked")
  public V get(CharSequence key) {
    int len = key.length() - 1;
    IARTNode current = root;
    for (int depth = 0; depth < len; depth++) {

      current = ((IARTNodeN) current).findNode(key.charAt(depth));
      if (current == null) return null;
    }

    return (V) current.getValue(key.charAt(len));
  }
Example #3
0
  @SuppressWarnings("unchecked")
  @Override
  public V getLongestPrefixValue(CharSequence key) {
    int len = key.length() - 1;
    V ret = null;
    IARTNode current = root;
    for (int depth = 0; depth < len; depth++) {
      int index = key.charAt(depth);
      V x = (V) current.getValue(index);
      if (x != null) ret = x;

      current = ((IARTNodeN) current).findNode(index);
      if (current == null) return ret;
    }

    V x = (V) current.getValue(key.charAt(len));
    return x != null ? x : ret;
  }
Example #4
0
  @Override
  public void put(ISequentialKey key, V value) {
    IARTNode current = root;

    int len = key.length() - 1;

    for (int depth = 0; depth < len; ++depth) {
      int index = key.keyAt(depth);

      IARTNode next = current.findNode(index);
      if (next != null) {
        current = next;
      } else {
        next = new ARTNode1NbVib();
        current.setNode(index, next);
        current = next;
      }
    }
    current.setValue(key.keyAt(len), value);
  }
Example #5
0
 public void compact() {
   root = root.compact();
 }