ch.ethz.globis.phtree.v16.bst.BSTIteratorToArray Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phtree Show documentation
Show all versions of phtree Show documentation
The PH-Tree is a multi-dimensional index
/*
* Copyright 2016-2018 Tilmann Zäschke. All Rights Reserved.
*
* This software is the proprietary information of Tilmann Zäschke.
* Use is subject to license terms.
*/
package ch.ethz.globis.phtree.v16.bst;
import ch.ethz.globis.phtree.v16.Node.BSTEntry;
/**
*
* @author Tilmann Zaeschke
*
*/
public class BSTIteratorToArray {
private BSTEntry[] entries;
private int nEntries;
public BSTIteratorToArray() {
//nothing
}
public BSTIteratorToArray reset(BSTreePage root, BSTEntry[] entries) {
this.entries = entries;
this.nEntries = 0;
//find first page
BSTreePage page = findFirstLeafPage(root);
readLeafPages(page);
return this;
}
private BSTreePage findFirstLeafPage(BSTreePage currentPage) {
while (!currentPage.isLeaf()) {
//the following is only for the initial search.
//The stored key[i] is the min-key of the according page[i+1}
if (currentPage.getNKeys() == -1) {
return null;
}
currentPage = currentPage.getPageByPos(0);
}
return currentPage;
}
private void readLeafPages(BSTreePage currentPage) {
while (currentPage != null) {
BSTEntry[] values = currentPage.getValues();
System.arraycopy(values, 0, entries, nEntries, currentPage.getNKeys());
nEntries += currentPage.getNKeys();
currentPage = currentPage.getNextLeaf();
}
}
public int getNEntries() {
return nEntries;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy