本文整理汇总了C++中GiSTpath::Page方法的典型用法代码示例。如果您正苦于以下问题:C++ GiSTpath::Page方法的具体用法?C++ GiSTpath::Page怎么用?C++ GiSTpath::Page使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GiSTpath
的用法示例。
在下文中一共展示了GiSTpath::Page方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Path
void
MTnode::InvalidateEntry (BOOL bNew)
{
GiSTpath path = Path ();
if (path.Level() > 1) { // len>=3
MTnode *parentNode = ((MT *)Tree())->ParentNode((MTnode *)this);
for (int i=0; i<parentNode->NumEntries(); i++) { // search the entry in the parent's node
MTentry *entry = (MTentry *) (*parentNode)[i].Ptr();
if (entry->Ptr() == path.Page()) {
if (bNew) {
entry->Key()->distance = -MaxDist();
}
entry->Key()->splitted = TRUE;
break;
}
}
path.MakeParent ();
MTnode *grandNode = ((MT *)Tree())->ParentNode(parentNode);
for (int i=0; i<grandNode->NumEntries(); i++) { // search the entry in the grandparent's node
MTentry *entry = (MTentry *) (*grandNode)[i].Ptr();
if (entry->Ptr() == path.Page()) {
entry->SetMaxRadius(-1);
break;
}
}
((MT *)Tree())->WriteNode(parentNode); // write parent node (in inconsistent state)
((MT *)Tree())->WriteNode(grandNode); // write grandparent node (to invalidate the parent's entry)
delete parentNode;
delete grandNode;
}
}
示例2:
void
GiST::ShortenTree()
{
GiSTpath path;
// Shorten the tree if necessary (This should only be done if root actually changed!)
path.MakeRoot();
GiSTnode *root=ReadNode(path);
if(!root->IsLeaf()&&root->NumEntries()==1) {
path.MakeChild((*root)[0]->Ptr());
GiSTnode *child=ReadNode(path);
store->Deallocate(path.Page());
child->SetSibling(0);
child->Path().MakeRoot();
WriteNode(child);
delete child;
}
delete root;
}
示例3: Split
void MXTree::Split(GiSTnode **node, const GiSTentry& entry)
{
double radii[2], dist, *dists = new double[(*node)->NumEntries()*2];
int pageNums[2], cands[2];
vector<vector<int>> vec(2);
((MXTnode *)(*node))->TestPromotion(radii, &dist, pageNums, cands, dists, vec);
if (Trade((*node)->Path().IsRoot(), radii, dist, pageNums, ((MXTnode *)(*node))->GetPageNum()+1, (*node)->NumEntries())) {
// don't split now
delete[] dists;
GiSTpath oldPath = (*node)->Path();
int startPage = ((*node)->Path().IsRoot() ? rootPage : (*node)->Path().Page());
int pageNum = ((MXTnode *)(*node))->GetPageNum();
((MXTfile *)store)->Deallocate(startPage, pageNum);
startPage = ((MXTfile *)store)->Allocate(++pageNum);
(*node)->Path().MakeSibling(startPage);
rootPage = ((*node)->Path().IsRoot() ? startPage : rootPage);
((MXTnode *)(*node))->SetPageNum(pageNum);
WriteNode(*node);
if (!(*node)->Path().IsRoot() && startPage != oldPath.Page()) {
GiSTpath parentPath = oldPath;
parentPath.MakeParent();
GiSTnode *parentNode = ReadNode(parentPath);
GiSTentry *e = parentNode->SearchPtr(oldPath.Page());
assert(e != NULL);
int pos = e->Position();
e->SetPtr(startPage);
parentNode->DeleteEntry(pos);
parentNode->InsertBefore(*e, pos);
WriteNode(parentNode);
delete parentNode;
delete e;
}
} else {
// split now
bool bLeft = false, bNewRoot = false;
if ((*node)->Path().IsRoot()) {
bNewRoot = true;
(*node)->Path().MakeChild(rootPage);
rootPage = store->Allocate();
}
int oldPageNum = ((MXTnode *)(*node))->GetPageNum();
GiSTnode *node2 = ((MXTnode *)(*node))->PickSplit(cands, dists, vec);
delete[] dists;
int curPageNum = ((MXTnode *)(*node))->GetPageNum();
assert(oldPageNum >= curPageNum);
if (oldPageNum > curPageNum) {
((MXTfile *)store)->Deallocate((*node)->Path().Page()+curPageNum, oldPageNum-curPageNum);
}
node2->Path().MakeSibling(((MXTfile *)store)->Allocate(((MXTnode *)node2)->GetPageNum()));
WriteNode(*node);
WriteNode(node2);
GiSTentry *e = (*node)->SearchPtr(entry.Ptr());
if (e != NULL) {
bLeft = true;
delete e;
}
GiSTentry *e1 = (*node)->Union();
GiSTentry *e2 = node2->Union();
e1->SetPtr((*node)->Path().Page());
e2->SetPtr(node2->Path().Page());
// Create new root if root is being split
if (bNewRoot) {
GiSTnode *root = NewNode(this);
root->SetLevel((*node)->Level() + 1);
root->InsertBefore(*e1, 0);
root->InsertBefore(*e2, 1);
root->Path().MakeRoot();
WriteNode(root);
delete root;
} else {
// Insert entry for N' in parent
GiSTpath parentPath = (*node)->Path();
parentPath.MakeParent();
GiSTnode *parent = ReadNode(parentPath);
// Find the entry for N in parent
GiSTentry *e = parent->SearchPtr((*node)->Path().Page());
assert(e != NULL);
// Insert the new entry right after it
int pos = e->Position();
parent->DeleteEntry(pos);
parent->InsertBefore(*e1, pos);
parent->InsertBefore(*e2, pos+1);
delete e;
if (!parent->IsOverFull(*store)) {
WriteNode(parent);
} else {
Split(&parent, bLeft? *e1: *e2); // parent is the node which contains the entry inserted
GiSTpage page = (*node)->Path().Page();
(*node)->Path() = parent->Path(); // parent's path may change
(*node)->Path().MakeChild(page);
page = node2->Path().Page();
node2->Path() = (*node)->Path();
//.........这里部分代码省略.........
示例4: EntrySize
// load this M-tree with n data using the BulkLoad algorithm [CP98]
// data is an array of n entries
// padFactor is the maximum node utilization (use 1)
// name is the name of the tree
void
MT::BulkLoad (MTentry **data, int n, double padFactor, const char *name)
{
int size = 0;
if (EntrySize()) {
size = n * (sizeof(GiSTpage) + EntrySize()); // (only valid if we've fixed size entries)
} else {
for (int i=0; i<n; i++) {
size += sizeof(GiSTlte) + sizeof(GiSTpage) + data[i]->CompressedLength();
}
}
int totSize = size + GIST_PAGE_HEADER_SIZE + sizeof(GiSTlte);
if (totSize > Store()->PageSize()) { // we need to split the entries into several sub-trees
int numEntries = (int)(Store()->PageSize()*padFactor*n) / totSize;
int s = (int) MAX (MIN (numEntries, ceil(((float)n)/numEntries)), numEntries*MIN_UTIL); // initial number of samples
int nSamples, *samples = new int[s], *sizes = NULL, *ns = NULL, iter = 0, MAXITER = s * s;
GiSTlist<double *> *distm = (GiSTlist<double *> *) calloc (s, sizeof(GiSTlist<double *>)); // relative distances between samples
int MINSIZE = (int) (Store()->PageSize()*MIN_UTIL), addEntrySize = EntrySize() ? sizeof(GiSTpage) : sizeof(GiSTlte)+sizeof(GiSTpage);
GiSTlist<int> *lists = NULL; // set for each sample set
GiSTlist<double> *dists = NULL; // set for distance between each sample and its members
BOOL *bSampled = new BOOL[n]; // is this entry in the samples set?
// sampling phase
do {
iter++;
if (iter > 1) { // this is a new sampling phase
while (!lists[0].IsEmpty()) {
lists[0].RemoveFront ();
dists[0].RemoveFront ();
}
delete []lists;
delete []dists;
delete []sizes;
delete []ns;
while (!distm[0].IsEmpty()) {
delete []distm[0].RemoveFront(); // empty the distance list
}
for (int i=1; i<s; i++) {
distm[i].front = distm[i].rear = NULL;
}
}
if (iter >= MAXITER) {
cout << "Too many loops in BulkLoad!"<<endl<<"Please select a lower minimum node utilization or a bigger node size."<<endl;
exit(1);
}
for (int i=0; i<n; i++) {
bSampled[i] = FALSE;
}
nSamples = 0;
// pick s samples to create parents
while (nSamples < s) {
int i;
do {
i = PickRandom (0, n);
} while (bSampled[i]);
bSampled[i] = TRUE;
samples[nSamples++] = i;
}
lists = new GiSTlist<int>[s];
dists = new GiSTlist<double>[s];
sizes = new int[s];
ns = new int[s];
for (int i=0; i<s; i++) {
sizes[i] = GIST_PAGE_HEADER_SIZE + sizeof(GiSTlte);
ns[i] = 1;
distm[i].Prepend (new double[s]);
}
// compute the relative distances between samples
for (int i=0; i<s; i++) {
for (int j=0; j<i; j++) {
distm[j].front->entry[i] = distm[i].front->entry[j] = data[samples[j]]->object().distance(data[samples[i]]->object());
}
distm[i].front->entry[i] = 0;
}
// assign each entry to its nearest parent
for (int i=0; i<n; i++) {
if (bSampled[i]) {
int j = 0;
for (; samples[j]!=i; j++); // find this entry in the samples set and return position in it
lists[j].Prepend (i); // insert the entry in the right sample
dists[j].Prepend (0); // distance between sample and data[i]
sizes[j] += addEntrySize + data[i]->CompressedLength();
} else { // here we optimize the distance computations (like we do in the insert algorithm)
double *dist = new double[s]; // distance between this non-sample and samples
dist[0] = data[samples[0]]->object().distance(data[i]->object());
int minIndex = 0;
for (int j=1; j<s; j++) { // seek the nearest sample
dist[j] = -MaxDist();
if (fabs (data[samples[j]]->Key()->distance - data[i]->Key()->distance) >= dist[minIndex]) { // pruning
continue;
}
//.........这里部分代码省略.........