@thi.ng/geom-accel
Version:
n-D spatial indexing data structures with a shared ES6 Map/Set-like API
67 lines (66 loc) • 1.38 kB
JavaScript
import { KdTreeMap } from "./kd-tree-map.js";
class KdTreeSet {
tree;
constructor(dim, keys, distanceFn) {
this.tree = new KdTreeMap(dim, void 0, distanceFn);
keys && this.into(keys);
}
[Symbol.iterator]() {
return this.tree.keys();
}
keys() {
return this.tree.keys();
}
values() {
return this.tree.keys();
}
get size() {
return this.tree.size;
}
get height() {
return this.tree.height;
}
get ratio() {
return this.tree.ratio;
}
copy() {
return new KdTreeSet(this.tree.dim, this, this.tree.distanceFn);
}
clear() {
this.tree.clear();
}
empty() {
return new KdTreeSet(this.tree.dim, void 0, this.tree.distanceFn);
}
add(key, eps) {
return this.tree.set(key, key, eps);
}
into(ks, eps) {
let ok = true;
for (const k of ks) {
ok = this.tree.set(k, k, eps) && ok;
}
return ok;
}
remove(key) {
return this.tree.remove(key);
}
has(key, eps) {
return this.tree.has(key, eps);
}
get(key, eps) {
return this.tree.get(key, eps);
}
query(q, maxDist, limit, acc) {
return this.tree.query(q, maxDist, limit, acc);
}
queryKeys(q, maxDist, limit, acc) {
return this.tree.queryKeys(q, maxDist, limit, acc);
}
queryValues(q, maxDist, limit, acc) {
return this.tree.queryKeys(q, maxDist, limit, acc);
}
}
export {
KdTreeSet
};