All Downloads are FREE. Search and download functionalities are using the official Maven repository.

swim.collections.STreePage Maven / Gradle / Ivy

Go to download

Immutable, structure sharing collections, including hash array mapped tries, finger tries, B-trees, and S-trees (sequence trees)

There is a newer version: 4.3.15
Show newest version
// Copyright 2015-2019 SWIM.AI inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package swim.collections;

import java.util.Map;
import swim.util.Cursor;

public abstract class STreePage {
  public abstract boolean isEmpty();

  public abstract int size();

  public abstract int arity();

  public abstract boolean contains(Object value);

  public abstract int indexOf(Object value);

  public abstract int lastIndexOf(Object value);

  public abstract T get(int index);

  public abstract Map.Entry getEntry(int index);

  public abstract STreePage updated(int index, T newValue, STreeContext tree);

  public abstract STreePage inserted(int index, T newValue, Object id, STreeContext tree);

  public STreePage appended(T newValue, Object id, STreeContext tree) {
    return inserted(size(), newValue, id, tree);
  }

  public STreePage prepended(T newValue, Object id, STreeContext tree) {
    return inserted(0, newValue, id, tree);
  }

  public abstract STreePage removed(int index, STreeContext tree);

  public abstract STreePage removed(Object value, STreeContext tree);

  public abstract STreePage drop(int lower, STreeContext tree);

  public abstract STreePage take(int upper, STreeContext tree);

  public abstract STreePage balanced(STreeContext tree);

  public abstract STreePage split(int index);

  public abstract STreePage splitLeft(int index);

  public abstract STreePage splitRight(int index);

  public abstract void copyToArray(Object[] array, int offset);

  public Cursor iterator() {
    return Cursor.values(this.entryIterator());
  }

  public Cursor keyIterator() {
    return Cursor.keys(this.entryIterator());
  }

  public abstract Cursor> entryIterator();

  public Cursor reverseIterator() {
    return Cursor.values(this.reverseEntryIterator());
  }

  public Cursor reverseKeyIterator() {
    return Cursor.keys(this.reverseEntryIterator());
  }

  public abstract Cursor> reverseEntryIterator();

  public static  STreePage empty() {
    return STreeLeaf.empty();
  }
}