in Java/core/src/main/java/com/amazon/randomcutforest/store/PointStore.java [689:750]
public PointStore(PointStore.Builder builder) {
checkArgument(builder.dimensions > 0, "dimensions must be greater than 0");
checkArgument(builder.capacity > 0, "capacity must be greater than 0");
checkArgument(builder.shingleSize == 1 || builder.dimensions == builder.shingleSize
|| builder.dimensions % builder.shingleSize == 0, "incorrect use of shingle size");
/**
* the following checks are due to mappers (kept for future)
*/
if (builder.refCount != null || builder.locationList != null || builder.knownShingle != null) {
checkArgument(builder.refCount != null, "reference count must be present");
checkArgument(builder.locationList != null, "location list must be present");
checkArgument(builder.refCount.length == builder.indexCapacity, "incorrect reference count length");
// following may change if IndexManager is dynamically resized as well
checkArgument(builder.locationList.length == builder.indexCapacity, " incorrect length of locations");
checkArgument(
builder.knownShingle == null
|| builder.internalShinglingEnabled && builder.knownShingle.length == builder.dimensions,
"incorrect shingling information");
}
this.shingleSize = builder.shingleSize;
this.dimensions = builder.dimensions;
this.internalShinglingEnabled = builder.internalShinglingEnabled;
this.rotationEnabled = builder.internalRotationEnabled;
this.baseDimension = this.dimensions / this.shingleSize;
this.capacity = builder.capacity;
this.refCountMap = new HashMap<>();
if (builder.refCount == null) {
int size = (int) builder.initialPointStoreSize.orElse(builder.capacity);
currentStoreCapacity = size;
this.indexManager = new IndexIntervalManager(size);
startOfFreeSegment = 0;
refCount = new byte[size];
if (internalShinglingEnabled) {
nextSequenceIndex = 0;
internalShingle = new float[dimensions];
}
store = new float[currentStoreCapacity * dimensions];
} else {
this.refCount = new byte[builder.refCount.length];
for (int i = 0; i < refCount.length; i++) {
if (builder.refCount[i] >= 0 && builder.refCount[i] <= 255) {
refCount[i] = (byte) builder.refCount[i];
} else if (builder.refCount[i] > 255) {
refCount[i] = (byte) 255;
refCountMap.put(i, builder.refCount[i] - 255);
}
}
this.startOfFreeSegment = builder.startOfFreeSegment;
this.nextSequenceIndex = builder.nextTimeStamp;
this.currentStoreCapacity = builder.currentStoreCapacity;
if (internalShinglingEnabled) {
this.internalShingle = (builder.knownShingle != null)
? Arrays.copyOf(toFloatArray(builder.knownShingle), dimensions)
: new float[dimensions];
}
indexManager = new IndexIntervalManager(builder.refCount, builder.indexCapacity);
store = (builder.store == null) ? new float[currentStoreCapacity * dimensions] : builder.store;
}
}