Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2016-2018 Tilmann Zäschke. All Rights Reserved.
* Copyright 2019 Improbable. All rights reserved.
*
* This file is part of the PH-Tree project.
*
* 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 ch.ethz.globis.phtree.v16hd;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.PriorityQueue;
import ch.ethz.globis.phtree.PhDistance;
import ch.ethz.globis.phtree.PhEntryDist;
import ch.ethz.globis.phtree.PhTree.PhKnnQuery;
import ch.ethz.globis.phtree.PhTreeHelperHD;
import ch.ethz.globis.phtree.v16hd.Node.BSTEntry;
import ch.ethz.globis.phtree.v16hd.bst.BSTIteratorAll;
/**
* kNN query implementation that uses preprocessors and distance functions.
*
* Implementation after Hjaltason and Samet (with some deviations: no MinDist or MaxDist used).
* G. R. Hjaltason and H. Samet., "Distance browsing in spatial databases.", ACM TODS 24(2):265--318. 1999
*
* Additional modification by using HC-Address for estimating distance, actual distance is
* calculated only when required.
*
* @param value type
*/
public class PhQueryKnnHSZ implements PhKnnQuery {
private static final PhDEComp COMP = new PhDEComp();
private final int dims;
private PhTree16HD pht;
private PhDistance distance;
private long[] center;
private final ArrayList> results = new ArrayList<>();
private final ArrayList> pool = new ArrayList<>();
private final PriorityQueue> queueEst = new PriorityQueue<>(COMP);
private final PriorityQueue> queueLx = new PriorityQueue<>(COMP);
private final BSTIteratorAll iterNode = new BSTIteratorAll();
private Iterator> iterResult;
//Field, to reduce garbage collection. Gets reset for every loop in the query.
private final long[] relativeQuadrantOfCenter;
/**
* Create a new kNN/NNS search instance.
* @param pht the parent tree
*/
public PhQueryKnnHSZ(PhTree16HD pht) {
this.dims = pht.getDim();
this.pht = pht;
this.relativeQuadrantOfCenter = BitsHD.newArray(dims);
}
@Override
public long[] nextKey() {
return nextEntryReuse().getKey();
}
@Override
public T nextValue() {
return nextEntryReuse().getValue();
}
@Override
public PhEntryDist nextEntry() {
return iterResult.next();
}
@Override
public PhEntryDist nextEntryReuse() {
//Reusing happens only via pooling
return iterResult.next();
}
@Override
public boolean hasNext() {
return iterResult.hasNext();
}
@Override
public T next() {
return nextValue();
}
@Override
public PhKnnQuery reset(int nMin, PhDistance dist, long... center) {
this.distance = dist == null ? this.distance : dist;
this.center = center;
//TODO pool entries??/
this.queueEst.clear();
this.queueLx.clear();
this.results.clear();
if (nMin <= 0 || pht.size() == 0) {
iterResult = Collections.>emptyList().iterator();
return this;
}
//Initialize queue
PhEntryDist