Search in sources :

Example 1 with IndexTreePath

use of de.lmu.ifi.dbs.elki.index.tree.IndexTreePath in project elki by elki-project.

the class DeLiClu method reinsertExpanded.

/**
 * Reinserts the objects of the already expanded nodes.
 *
 * @param distFunction the spatial distance function of this algorithm
 * @param index the index storing the objects
 * @param path the path of the object inserted last
 * @param knns the knn list
 */
private void reinsertExpanded(SpatialPrimitiveDistanceFunction<NV> distFunction, DeLiCluTree index, IndexTreePath<DeLiCluEntry> path, Relation<KNNList> knns) {
    // Count the number of components.
    int l = 0;
    for (IndexTreePath<DeLiCluEntry> it = path; it != null; it = it.getParentPath()) {
        l++;
    }
    ArrayList<IndexTreePath<DeLiCluEntry>> p = new ArrayList<>(l - 1);
    // All except the last (= root).
    IndexTreePath<DeLiCluEntry> it = path;
    for (; it.getParentPath() != null; it = it.getParentPath()) {
        p.add(it);
    }
    assert (p.size() == l - 1);
    DeLiCluEntry rootEntry = it.getEntry();
    reinsertExpanded(distFunction, index, p, l - 2, rootEntry, knns);
}
Also used : DeLiCluEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry) IndexTreePath(de.lmu.ifi.dbs.elki.index.tree.IndexTreePath) ArrayList(java.util.ArrayList)

Example 2 with IndexTreePath

use of de.lmu.ifi.dbs.elki.index.tree.IndexTreePath in project elki by elki-project.

the class AbstractXTree method createNewRoot.

/**
 * Creates a new root node that points to the two specified child nodes and
 * return the path to the new root.
 *
 * @param oldRoot the old root of this RTree
 * @param newNode the new split node
 * @param splitAxis the split axis used for the split causing this new root
 * @return the path to the new root node that points to the two specified
 *         child nodes
 */
protected IndexTreePath<SpatialEntry> createNewRoot(final N oldRoot, final N newNode, int splitAxis) {
    N root = createNewDirectoryNode();
    writeNode(root);
    // get split history
    SplitHistory sh = null;
    // TODO: see whether root entry is ALWAYS a directory entry .. it SHOULD!
    sh = ((XTreeDirectoryEntry) getRootEntry()).getSplitHistory();
    if (sh == null) {
        sh = new SplitHistory(getDimensionality());
    }
    sh.setDim(splitAxis);
    // switch the ids
    oldRoot.setPageID(root.getPageID());
    if (!oldRoot.isLeaf()) {
        // TODO: test whether this is neccessary
        for (int i = 0; i < oldRoot.getNumEntries(); i++) {
            N node = getNode(oldRoot.getEntry(i));
            writeNode(node);
        }
    }
    // adjust supernode id
    if (oldRoot.isSuperNode()) {
        supernodes.remove(new Long(getRootID()));
        supernodes.put(new Long(oldRoot.getPageID()), oldRoot);
    }
    root.setPageID(getRootID());
    SpatialEntry oldRootEntry = createNewDirectoryEntry(oldRoot);
    SpatialEntry newNodeEntry = createNewDirectoryEntry(newNode);
    ((SplitHistorySpatialEntry) oldRootEntry).setSplitHistory(sh);
    try {
        ((SplitHistorySpatialEntry) newNodeEntry).setSplitHistory((SplitHistory) sh.clone());
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException("Clone of a split history should not throw an Exception", e);
    }
    root.addDirectoryEntry(oldRootEntry);
    root.addDirectoryEntry(newNodeEntry);
    writeNode(root);
    writeNode(oldRoot);
    writeNode(newNode);
    if (getLogger().isDebugging()) {
        getLogger().debugFine(// 
        new StringBuilder(1000).append("Create new Root: ID=").append(root.getPageID()).append("\nchild1 ").append(oldRoot).append(' ').append(// 
        new HyperBoundingBox(oldRootEntry)).append("\nchild2 ").append(newNode).append(' ').append(new HyperBoundingBox(newNodeEntry)));
    }
    // the root entry still needs to be set to the new root node's MBR
    return new IndexTreePath<>(null, getRootEntry(), 0);
}
Also used : IndexTreePath(de.lmu.ifi.dbs.elki.index.tree.IndexTreePath) ModifiableHyperBoundingBox(de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox) HyperBoundingBox(de.lmu.ifi.dbs.elki.data.HyperBoundingBox) SplitHistory(de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.util.SplitHistory) SpatialEntry(de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)

Aggregations

IndexTreePath (de.lmu.ifi.dbs.elki.index.tree.IndexTreePath)2 HyperBoundingBox (de.lmu.ifi.dbs.elki.data.HyperBoundingBox)1 ModifiableHyperBoundingBox (de.lmu.ifi.dbs.elki.data.ModifiableHyperBoundingBox)1 SpatialEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.SpatialEntry)1 DeLiCluEntry (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.deliclu.DeLiCluEntry)1 SplitHistory (de.lmu.ifi.dbs.elki.index.tree.spatial.rstarvariants.xtree.util.SplitHistory)1 ArrayList (java.util.ArrayList)1