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

io.permazen.core.CoreIndex Maven / Gradle / Ivy


/*
 * Copyright (C) 2015 Archie L. Cobbs. All rights reserved.
 */

package io.permazen.core;

import io.permazen.core.type.Tuple2FieldType;
import io.permazen.index.Index;
import io.permazen.kv.KVStore;
import io.permazen.kv.KeyFilter;
import io.permazen.tuple.Tuple2;
import io.permazen.util.Bounds;

import java.util.NavigableMap;
import java.util.NavigableSet;

/**
 * Core API {@link Index} implementation representing a index on a single field.
 *
 * 

* Instances are immutable. * * @param index value type * @param index target type */ public class CoreIndex extends AbstractCoreIndex implements Index { // Constructors CoreIndex(KVStore kv, IndexView indexView) { super(kv, 2, indexView); } // Methods @Override public CoreIndex filter(int index, KeyFilter filter) { return new CoreIndex<>(this.kv, this.getIndexView().filter(index, filter)); } @SuppressWarnings("unchecked") IndexView getIndexView() { return (IndexView)this.indexView; } // Index @Override public NavigableSet> asSet() { // Get index view final IndexView iv = this.getIndexView(); // Create tuple field type final Tuple2FieldType tupleFieldType = new Tuple2FieldType<>(iv.getValueType(), iv.getTargetType()); // Build set and apply filtering IndexSet> indexSet = new IndexSet<>(this.kv, tupleFieldType, iv.prefixMode, iv.prefix); if (iv.hasFilters()) indexSet = indexSet.filterKeys(new IndexKeyFilter(this.kv, iv, 2)); // Done return indexSet; } @Override public NavigableMap> asMap() { // Get index view final IndexView iv = this.getIndexView(); // Build map and apply filtering IndexMap> indexMap = new IndexMap.OfValues<>(this.kv, iv); if (this.indexView.hasFilters()) indexMap = indexMap.filterKeys(new IndexKeyFilter(this.kv, iv, 1)); // Done return indexMap; } @Override @SuppressWarnings("unchecked") public CoreIndex withValueBounds(Bounds bounds) { return (CoreIndex)this.filter(0, this.getIndexView().getValueType(), bounds); } @Override @SuppressWarnings("unchecked") public CoreIndex withTargetBounds(Bounds bounds) { return (CoreIndex)this.filter(1, this.getIndexView().getTargetType(), bounds); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy