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

swim.db.STreeListView Maven / Gradle / Ivy

Go to download

Lock-free document store—optimized for high rate atomic state changes—that concurrently commits and compacts on-disk log-structured storage files without blocking parallel in-memory updates to associative B-tree maps, spatial Q-tree maps, sequential S-tree lists, and singleton U-tree values

The newest version!
// Copyright 2015-2024 Nstream, 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.db;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.List;
import swim.structure.Form;
import swim.structure.Slot;
import swim.structure.Value;
import swim.structure.collections.ValueList;
import swim.util.Cursor;

public class STreeListView implements List {

  protected final STree tree;

  public STreeListView(STree tree) {
    this.tree = tree;
  }

  public STree getTree() {
    return this.tree;
  }

  public STreeListView load() {
    this.tree.load();
    return this;
  }

  public boolean isResident() {
    return this.tree.isResident();
  }

  public boolean isTransient() {
    return this.tree.isTransient();
  }

  public  ValueList valueForm(Form valueForm) {
    return new ValueList(this, valueForm);
  }

  public  ValueList valueClass(Class valueClass) {
    return this.valueForm(Form.forClass(valueClass));
  }

  @Override
  public boolean isEmpty() {
    return this.tree.isEmpty();
  }

  @Override
  public int size() {
    return (int) this.tree.span();
  }

  @Override
  public boolean contains(Object value) {
    if (value instanceof Value) {
      return this.tree.contains((Value) value);
    }
    return false;
  }

  @Override
  public boolean containsAll(Collection values) {
    for (Object value : values) {
      if (!(value instanceof Value && this.contains((Value) value))) {
        return false;
      }
    }
    return true;
  }

  @Override
  public int indexOf(Object object) {
    final long k = this.tree.indexOf(object);
    final int i = (int) k;
    if (i != k) {
      throw new IndexOutOfBoundsException("index overflow");
    }
    return i;
  }

  @Override
  public int lastIndexOf(Object object) {
    final long k = this.tree.lastIndexOf(object);
    final int i = (int) k;
    if (i != k) {
      throw new IndexOutOfBoundsException("index overflow");
    }
    return i;
  }

  @Override
  public Value get(int index) {
    return this.tree.get(index);
  }

  @Override
  public Value set(int index, Value newValue) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean add(Value newValue) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean addAll(Collection newValues) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void add(int index, Value newValue) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean addAll(int index, Collection newValues) {
    throw new UnsupportedOperationException();
  }

  @Override
  public Value remove(int index) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean remove(Object value) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean removeAll(Collection values) {
    throw new UnsupportedOperationException();
  }

  @Override
  public boolean retainAll(Collection values) {
    throw new UnsupportedOperationException();
  }

  @Override
  public void clear() {
    throw new UnsupportedOperationException();
  }

  @Override
  public Object[] toArray() {
    final STree tree = this.tree;
    final long k = tree.span();
    final int n = (int) k;
    if (n != k) {
      throw new IndexOutOfBoundsException("length overflow");
    }
    final Object[] array = new Object[n];
    tree.copyToArray(array, 0);
    return array;
  }

  @SuppressWarnings("unchecked")
  @Override
  public  T[] toArray(T[] array) {
    final STree tree = this.tree;
    final long k = tree.span();
    final int n = (int) k;
    if (n != k) {
      throw new IndexOutOfBoundsException("length overflow");
    }
    if (array.length < n) {
      array = (T[]) Array.newInstance(array.getClass().getComponentType(), n);
    }
    tree.copyToArray(array, 0);
    if (array.length > n) {
      array[n] = null;
    }
    return array;
  }

  @Override
  public Cursor iterator() {
    return Cursor.values(this.tree.cursor());
  }

  @Override
  public Cursor listIterator() {
    return Cursor.values(this.tree.cursor());
  }

  @Override
  public Cursor listIterator(int index) {
    final Cursor cursor = this.tree.cursor();
    cursor.skip(index);
    return Cursor.values(cursor);
  }

  @Override
  public List subList(int fromIndex, int toIndex) {
    if (fromIndex > toIndex) {
      throw new IllegalArgumentException();
    }
    return new STreeSubListView(this, fromIndex, toIndex);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy