convex.core.data.AIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of convex-core Show documentation
Show all versions of convex-core Show documentation
Convex core libraries and common utilities
The newest version!
package convex.core.data;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import convex.core.data.type.AType;
import convex.core.data.type.Types;
/**
* Abstract base class for Indexes: a sorted radix-tree map of Blobs to Values.
*
* Primary benefits: - Provide sorted orderings for indexes - Support Schedule
* data structure
*
* @param Type of Index keys
* @param Type of Index values
*/
public abstract class AIndex, V extends ACell> extends AMap {
protected AIndex(long count) {
super(count);
}
@SuppressWarnings("unchecked")
@Override
public final V get(ACell key) {
if (!(key instanceof ABlobLike)) return null;
return get((K) key);
}
@SuppressWarnings("unchecked")
@Override
public boolean containsKey(ACell key) {
if (!(key instanceof ABlobLike)) return false;
return (getEntry((K) key) != null);
}
/**
* Gets the map entry for a given Blob
*
* @param key Key to lookup up
* @return The value specified by the given blob key or null if not present.
*/
public abstract V get(K key);
@Override
public Set> entrySet() {
HashSet> hs=new HashSet<>(size());
long n=count();
for (long i=0; i me=entryAt(i);
hs.add(me);
}
return Collections.unmodifiableSet(hs);
}
@Override
public abstract int getRefCount();
@Override
public abstract Ref getRef(int i);
@Override
public boolean isCanonical() {
return true;
}
@Override
public AType getType() {
return Types.INDEX;
}
/**
* Associates a blob key with a value in this data structure.
*
* Returns null if the key is not a valid Index key
*/
@Override
public abstract AIndex assoc(ACell key, ACell value);
@SuppressWarnings("unchecked")
@Override
public final AIndex dissoc(ACell key) {
if (key instanceof ABlobLike) {
return dissoc((K)key);
}
return this;
}
public abstract AIndex dissoc(K key);
@Override
public MapEntry getKeyRefEntry(Ref ref) {
return getEntry(ref.getValue());
}
@Override
public abstract MapEntry entryAt(long i);
@SuppressWarnings("unchecked")
public MapEntry getEntry(ACell key) {
if (key instanceof ABlobLike) return getEntry((K)key);
return null;
}
public abstract MapEntry getEntry(K key);
@Override
public abstract int estimatedEncodingSize();
}