Ejemplo n.º 1
0
  @Override
  public void remove_child(ChildPtr ref, byte c) {
    assert (refcount <= 1);

    // Delete the child, leaving a hole in children. We can't shift children
    // because that would require decrementing many elements of keys
    int pos = to_uint(keys[to_uint(c)]);
    keys[to_uint(c)] = 0;
    children[pos - 1].decrement_refcount();
    children[pos - 1] = null;
    num_children--;

    if (num_children == 12) {
      ArtNode16 result = new ArtNode16(this);
      ref.change(result);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void add_child(ChildPtr ref, byte c, Node child) {
    assert (refcount <= 1);

    if (this.num_children < 48) {
      // Have to do a linear scan because deletion may create holes in
      // children array
      int pos = 0;
      while (children[pos] != null) pos++;

      this.children[pos] = child;
      child.refcount++;
      this.keys[to_uint(c)] = (byte) (pos + 1);
      this.num_children++;
    } else {
      // Copy the node48 into a new node256
      ArtNode256 result = new ArtNode256(this);
      // Update the parent pointer to the node256
      ref.change(result);
      // Insert the element into the node256 instead
      result.add_child(ref, c, child);
    }
  }