use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.
the class MTreeSplit method balancedPartition.
/**
* Creates a balanced partition of the entries of the specified node.
*
* @param tree the tree to perform the split in
* @param node the node to be split
* @param routingObject1 the id of the first routing object
* @param routingObject2 the id of the second routing object
* @return an assignment that holds a balanced partition of the entries of the
* specified node
*/
Assignments<E> balancedPartition(AbstractMTree<O, N, E, ?> tree, N node, DBID routingObject1, DBID routingObject2) {
assert (routingObject1 != null && routingObject2 != null);
final int n = node.getNumEntries(), l = n - 2;
int[] idx1 = new int[l], idx2 = new int[l];
double[] dis1 = new double[l], dis2 = new double[l];
Assignments<E> assign = new Assignments<>((n + 1) >> 1);
assign.setFirstRoutingObject(routingObject1);
assign.setSecondRoutingObject(routingObject2);
for (int i = 0, j = 0; i < n; i++) {
final E ent = node.getEntry(i);
final DBID id = ent.getRoutingObjectID();
if (DBIDUtil.equal(id, routingObject1)) {
assign.addToFirst(ent, 0., i);
continue;
}
if (DBIDUtil.equal(id, routingObject2)) {
assign.addToSecond(ent, 0., i);
continue;
}
// determine the distance of o to o1 / o2
dis1[j] = tree.distance(routingObject1, id);
idx1[j] = i;
dis2[j] = tree.distance(routingObject2, id);
idx2[j] = i;
j++;
}
DoubleIntegerArrayQuickSort.sort(dis1, idx1, l);
DoubleIntegerArrayQuickSort.sort(dis2, idx2, l);
long[] assigned = BitsUtil.zero(n);
int p1 = 0, p2 = 0;
for (int i = 0; i < l; ++i) {
p1 = assignBest(assign, assigned, node, dis1, idx1, p1, false);
if (++i < l) {
p2 = assignBest(assign, assigned, node, dis2, idx2, p2, true);
}
}
assert (assign.getFirstAssignments().size() + assign.getSecondAssignments().size() == n) : "Sizes do not sum up: " + assign.getFirstAssignments().size() + " + " + assign.getFirstAssignments().size() + " != " + n;
assert (Math.abs(assign.getFirstAssignments().size() - assign.getSecondAssignments().size()) <= 1) : assign.getFirstAssignments().size() + " " + assign.getSecondAssignments().size();
return assign;
}
use of de.lmu.ifi.dbs.elki.database.ids.DBID in project elki by elki-project.
the class ArrayDBIDStore method put.
@Override
@Deprecated
public DBID put(DBIDRef id, DBID value) {
final int off = idmap.mapDBIDToOffset(id);
DBID ret = data.get(off);
data.set(off, value);
return ret;
}
Aggregations