Exemple #1
0
  public BPlusTree(int nodeSize, Comparator<K> comparator) {
    this.nodeSize = nodeSize;
    this.comparator = comparator;

    firstNode = Leaf.newInstance(nodeSize);
    this.root = firstNode;
  }
Exemple #2
0
    public Object put(Comparator comparator, Object key, Object val) {
      Object oldVal;

      int search = binarySearch(this, 0, size, key, comparator);
      if (search > -1) {
        Entry entry = get(search);
        oldVal = entry.getValue();
        entry.setValue(val);
      } else if (size < capacity) {
        oldVal = null;

        search = -(search + 1);
        insert(search, key, val);

      } else {
        Leaf next = Leaf.newInstance(capacity);

        int halfSize = size / 2;

        shallowCopy(this, halfSize, next, 0, halfSize);
        clear(halfSize, size);

        size = halfSize;
        next.size = halfSize;

        if (compare(comparator, key, next.firstKey()) < 0) {
          put(comparator, key, val);
        } else {
          next.put(comparator, key, val);
        }

        next.next = this.next;
        this.next = next;

        oldVal = Node.Sentinal.SPLIT;
      }

      return oldVal;
    }