swim.db.QTreeMapView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swim-db Show documentation
Show all versions of swim-db Show documentation
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 swim.math.Z2Form;
import swim.spatial.BitInterval;
import swim.spatial.SpatialMap;
import swim.spatial.SpatialValueMap;
import swim.structure.Form;
import swim.structure.Value;
import swim.util.Cursor;
public class QTreeMapView implements SpatialMap {
protected final QTree tree;
protected final Z2Form shapeForm;
public QTreeMapView(QTree tree, Z2Form shapeForm) {
this.tree = tree;
this.shapeForm = shapeForm;
}
public QTree getTree() {
return this.tree;
}
public Z2Form shapeForm() {
return this.shapeForm;
}
public QTreeMapView load() {
this.tree.load();
return this;
}
public boolean isResident() {
return this.tree.isResident();
}
public boolean isTransient() {
return this.tree.isTransient();
}
public SpatialValueMap keyForm(Form keyForm) {
return new SpatialValueMap(this, keyForm, Form.forValue());
}
public SpatialValueMap keyClass(Class keyClass) {
return this.keyForm(Form.forClass(keyClass));
}
public SpatialValueMap valueForm(Form valueForm) {
return new SpatialValueMap(this, Form.forValue(), valueForm);
}
public SpatialValueMap 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 containsKey(Value key, S shape) {
final Z2Form shapeForm = this.shapeForm;
final long x = BitInterval.span(shapeForm.getXMin(shape), shapeForm.getXMax(shape));
final long y = BitInterval.span(shapeForm.getYMin(shape), shapeForm.getYMax(shape));
return this.tree.containsKey(key, x, y);
}
@Override
public boolean containsKey(Object value) {
if (value instanceof Value) {
return this.tree.containsKey((Value) value);
}
return false;
}
@Override
public boolean containsValue(Object value) {
if (value instanceof Value) {
return this.tree.containsValue((Value) value);
}
return false;
}
@Override
public Value get(Object key) {
if (key instanceof Value) {
return this.tree.get((Value) key).body();
}
return Value.absent();
}
@Override
public Value get(Value key, S shape) {
final Z2Form shapeForm = this.shapeForm;
final long x = BitInterval.span(shapeForm.getXMin(shape), shapeForm.getXMax(shape));
final long y = BitInterval.span(shapeForm.getYMin(shape), shapeForm.getYMax(shape));
return this.tree.get(key, x, y).body();
}
@Override
public Value put(Value key, S shape, Value newValue) {
throw new UnsupportedOperationException();
}
@Override
public Value move(Value key, S oldShape, S newShape, Value newValue) {
throw new UnsupportedOperationException();
}
@Override
public Value remove(Value key, S shape) {
throw new UnsupportedOperationException();
}
@Override
public void clear() {
throw new UnsupportedOperationException();
}
@Override
public Cursor> iterator(S shape) {
final Z2Form shapeForm = this.shapeForm;
final long x = BitInterval.span(shapeForm.getXMin(shape), shapeForm.getXMax(shape));
final long y = BitInterval.span(shapeForm.getYMin(shape), shapeForm.getYMax(shape));
return new QTreeShapeCursor(this.tree.cursor(x, y), shapeForm, shape);
}
@Override
public Cursor> iterator() {
return new QTreeEntryCursor(this.tree.cursor(), this.shapeForm);
}
@Override
public Cursor keyIterator() {
return Cursor.keys(this.tree.cursor());
}
@Override
public Cursor valueIterator() {
return new QTreeValueCursor(this.tree.cursor());
}
}