本文整理汇总了C++中GiSTnode类的典型用法代码示例。如果您正苦于以下问题:C++ GiSTnode类的具体用法?C++ GiSTnode怎么用?C++ GiSTnode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GiSTnode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadNode
// adjust the keys of node, which is used during the final phase of the BulkLoad algorithm
void
MT::AdjKeys (GiSTnode *node)
{
if (node->Path().IsRoot()) {
return;
}
GiSTpath parentPath = node->Path();
parentPath.MakeParent ();
GiSTnode *parentNode = ReadNode (parentPath);
GiSTentry *parentEntry = parentNode->SearchPtr(node->Path().Page()); // parent entry
assert (parentEntry != NULL);
GiSTentry *unionEntry = node->Union();
unionEntry->SetPtr(node->Path().Page());
((MTkey *) unionEntry->Key())->distance = ((MTkey *) parentEntry->Key())->distance; // necessary to keep track of the distance from the parent
if (!parentEntry->IsEqual(*unionEntry)) { // replace this entry
parentNode->DeleteEntry(parentEntry->Position());
parentNode->Insert(*unionEntry);
WriteNode (parentNode);
AdjKeys (parentNode);
}
delete unionEntry;
delete parentEntry;
delete parentNode;
}
示例2: Search
void
GiST::Delete (const GiSTpredicate& pred)
{
GiSTcursor *c = Search (pred);
GiSTentry *e;
do {
if (c == NULL) {
return;
}
e = c->Next();
GiSTpath path = c->Path();
delete c;
if (e == NULL) {
return;
}
// Read in the node that this belongs to
GiSTnode *node = ReadNode (path);
node->DeleteEntry(e->Position());
WriteNode (node);
int condensed = CondenseTree (node);
delete node;
if (condensed) {
ShortenTree ();
// because the tree changed, we need to search all over again!
// XXX - this is inefficient! users may want to avoid condensing.
c = Search (pred);
}
} while (e != NULL);
}
示例3:
GiSTnode*
GiST::ChooseSubtree(GiSTpage page, const GiSTentry &entry, int level)
{
GiSTnode *node;
GiSTpath path;
for(;;) {
path.MakeChild(page);
node=ReadNode(path);
if(level==node->Level()||node->IsLeaf()) break;
page=node->SearchMinPenalty(entry);
delete node;
}
return node;
}
示例4: NewNode
GiSTnode*
GiST::ReadNode (const GiSTpath& path) const
{
char *buf = new char[store->PageSize()];
GiSTnode *node = NewNode((GiST *)this);
store->Read(path.Page(), buf); // do the deed
node->Unpack(buf);
#ifdef PRINTING_OBJECTS
if (debug) {
cout << "READ PAGE " << path.Page() << ":\n";
node->Print(cout);
}
#endif
node->Path() = path;
delete []buf;
return node;
}
示例5: ReadNode
void
MT::CollectStats ()
{
GiSTpath path;
path.MakeRoot ();
GiSTnode *node = ReadNode (path);
if (!node->IsLeaf()) {
int maxLevel = node->Level();
double *radii = new double[maxLevel];
int *pages = new int[maxLevel];
for (int i=0; i<maxLevel; i++) {
pages[i] = 0;
radii[i] = 0;
}
TruePredicate truePredicate;
GiSTlist<GiSTentry*> list = node->Search(truePredicate); // retrieve all the entries in this node
double overlap = ((MTnode *)node)->Overlap();
double totalOverlap = overlap;
delete node;
while (!list.IsEmpty()) {
GiSTentry *entry = list.RemoveFront ();
path.MakeChild (entry->Ptr());
node = ReadNode (path);
overlap = ((MTnode *)node)->Overlap();
totalOverlap += overlap;
pages[node->Level()]++;
radii[node->Level()] += ((MTkey *) entry->Key())->MaxRadius();
GiSTlist<GiSTentry*> newlist;
if (!node->IsLeaf()) {
newlist = node->Search(truePredicate); // recurse to next level
}
while (!newlist.IsEmpty()) {
list.Append (newlist.RemoveFront ());
}
path.MakeParent ();
delete entry;
delete node;
}
// output the results
cout << "Level:\tPages:\tAverage_Radius:"<<endl;
int totalPages = 1; // for the root
for (int i=maxLevel-1; i>=0; i--) {
totalPages += pages[i];
cout << i << ":\t" << pages[i] << "\t" << radii[i]/pages[i] << endl;
}
cout << "TotalPages:\t" << totalPages << endl;
cout << "LeafPages:\t" << pages[0] << endl;
cout << "TotalOverlap:\t" << (float)totalOverlap << endl;
delete []radii;
delete []pages;
} else {
delete node;
}
}
示例6: CreateStore
void
GiST::Create (const char *filename)
{
if (IsOpen()) {
return;
}
store = CreateStore();
store->Create(filename);
if (!store->IsOpen()) { // create failed!
return;
}
store->Allocate(); // added by myself, reserved for root
store->Allocate();
GiSTnode *node = NewNode(this);
node->Path().MakeRoot();
WriteNode (node);
delete node;
isOpen = 1;
}
示例7: CreateStore
void MXTree::Create(const char *filename)
{
if (IsOpen()) {
return;
}
store = CreateStore();
store->Create(filename);
if (!store->IsOpen()) {
return;
}
store->Allocate(); // reserved for root pointer
rootPage = store->Allocate();
assert(rootPage == 1);
GiSTnode *node = NewNode(this);
node->Path().MakeRoot();
WriteNode(node);
delete node;
isOpen = 1;
}
示例8: while
GiSTentry*
GiSTcursor::Next()
{
GiSTpage page;
while (first || !stack.IsEmpty()) {
if (first) {
page = GiSTRootPage;
first = 0;
} else {
assert(lastlevel >= 0);
GiSTentry *entry = stack.RemoveFront();
if (entry->IsLeaf())
return entry;
// Pop off the stack
for (int i=0; i < entry->Level() - lastlevel; i++)
path.MakeParent();
page = entry->Ptr();
delete entry;
}
// Entry was a pointer to another node
path.MakeChild(page);
GiSTnode *node = gist.ReadNode(path);
lastlevel = node->Level();
GiSTlist<GiSTentry*> list = node->Search(*query);
while (!list.IsEmpty()) {
GiSTentry *entry = list.RemoveRear();
stack.Prepend(entry);
}
delete node;
}
// The search is over...
return NULL;
}
示例9: ReadNode
void
GiST::DumpNode (ostream& os, GiSTpath path) const
{
GiSTnode *node = ReadNode(path);
node->Print(os);
if (!node->IsLeaf()) {
TruePredicate truePredicate;
GiSTlist<GiSTentry*> list = node->Search(truePredicate);
while (!list.IsEmpty()) {
GiSTentry *e = list.RemoveFront();
path.MakeChild(e->Ptr());
DumpNode (os, path);
path.MakeParent();
delete e;
}
}
delete node;
}
示例10: Split
void
GiST::InsertHelper(const GiSTentry &entry,
int level, // level of tree at which to insert
int *splitvec) // a vector to trigger Split instead of forced reinsert
{
GiSTnode *leaf;
int overflow=0;
leaf=ChooseSubtree(GiSTRootPage, entry, level);
leaf->Insert(entry);
if (leaf->IsOverFull(*store)) {
if(ForcedReinsert()&&!leaf->Path().IsRoot()&&(!splitvec||!splitvec[level])) {
int split[GIST_MAX_LEVELS];
// R*-tree-style forced reinsert
for(int i=0; i<GIST_MAX_LEVELS; i++) split[i]=0;
OverflowTreatment(leaf, entry, split);
overflow=1;
}
else Split(&leaf, entry);
if(leaf->IsOverFull(*store)) {
// we only should get here if we reinserted, and the node re-filled
assert(overflow);
leaf->DeleteEntry(entry.Position());
Split(&leaf, entry);
}
}
else WriteNode(leaf);
if(!overflow) AdjustKeys(leaf, NULL);
delete leaf;
}
示例11: Node
double
RTentry::OverlapArea(const RTkey &k) const
{
int i;
GiSTnode *n = Node();
RTkey *okey, *tmpkey;
double retval;
okey = new RTkey(k);
for (i = 0; i < n->NumEntries(); i++)
if (i != Position()) {
tmpkey = okey;
okey = tmpkey->intersect(((RTentry *)((*n)[i].Ptr()))->bbox());
delete tmpkey;
if (okey == NULL)
return(0);
}
retval = okey->area();
delete okey;
return(retval);
}
示例12: ceil
GiSTnode* MXTree::ReadNode(const GiSTpath& path) const
{
char *firstBuffer = new char[store->PageSize()];
int startPage = (path.IsRoot() ? rootPage : path.Page());
store->Read(startPage, firstBuffer);
int pageNum = ceil((float)(((MXTnodeHeader *)firstBuffer)->numEntries*(EntrySize()+sizeof(GiSTpage))+sizeof(MXTnodeHeader))/(float)PAGE_SIZE);
GiSTnode *node = new MXTnode(pageNum);
node->SetTree((GiST *)this);
node->Path() = path;
if (pageNum > 1) {
char *buffer = new char[store->PageSize()*pageNum];
memset(buffer, 0, store->PageSize()*pageNum);
memcpy(buffer, firstBuffer, store->PageSize());
((MXTfile *)store)->Read(startPage+1, buffer+store->PageSize(), pageNum-1); // do the deed
node->Unpack(buffer);
delete[] buffer;
} else {
node->Unpack(firstBuffer);
}
delete[] firstBuffer;
return node;
}
示例13: EntrySize
//.........这里部分代码省略.........
GiSTpath path;
path.MakeRoot ();
MTnode *node = (MTnode *) ReadNode (path);
GiSTlist<MTnode *> *oldList = new GiSTlist<MTnode *>; // upper level nodes
oldList->Append(node);
int level = node->Level();
while (level > 0) { // build the leaves list for super tree
GiSTlist<MTnode *> *newList = new GiSTlist<MTnode *>; // lower level nodes
while (!oldList->IsEmpty()) {
node = oldList->RemoveFront();
path = node->Path();
node->SetLevel(node->Level() + minHeight); // update level of the upper nodes of the super tree
WriteNode (node);
for (int i=0; i<node->NumEntries(); i++) {
MTentry *entry = (MTentry *) (*node)[i].Ptr();
path.MakeChild (entry->Ptr());
newList->Append((MTnode *)ReadNode(path));
path.MakeParent ();
}
delete node;
}
delete oldList;
oldList = newList;
level--;
}
while (!oldList->IsEmpty()) { // attach each subtree to its leaf
node = oldList->RemoveFront(); // retrieve next leaf (root of subtree)
node->SetLevel(minHeight); // update level of the root of the subtree
path = node->Path();
for (int i=0; i<node->NumEntries(); i++) {
MTentry *entry = (MTentry *) (*node)[i].Ptr();
path.MakeChild(Store()->Allocate());
MTnode *newNode = (MTnode *) CreateNode ();
newNode->Path() = path;
entry->SetPtr(path.Page());
path.MakeParent ();
int j = 0;
for (; entry->object() != topEntrArr[j]->object(); j++); // search the position to append
subtree->Open(subNameArr[j]);
GiSTpath rootPath;
rootPath.MakeRoot ();
Append (newNode, (MTnode *)subtree->ReadNode(rootPath)); // append this subtree to the super tree
subtree->Close();
delete subtree->Store(); // it was created in tree->Open()
delete newNode;
}
WriteNode (node);
delete node;
}
subtree->Open(subNameArr[0]); // in order to destroy the object tree
delete subtree;
for (int i=0; i<nSamples; i++) {
delete []subNameArr[i];
}
delete []subNameArr;
delete []topEntrArr;
// update radii of the upper nodes of the result M-tree
path.MakeRoot ();
node = (MTnode *) ReadNode (path);
oldList->Append(node);
level = node->Level();
while (level >= minHeight) { // build the list of the nodes which radii should be recomputed
GiSTlist<MTnode *> *newList = new GiSTlist<MTnode *>;
while (!oldList->IsEmpty()) {
node = oldList->RemoveFront();
path = node->Path();
for (int i=0; i<node->NumEntries(); i++) {
path.MakeChild ((*node)[i].Ptr()->Ptr());
newList->Append((MTnode *)ReadNode(path));
path.MakeParent ();
}
delete node;
}
delete oldList;
oldList = newList;
level--;
}
while (!oldList->IsEmpty()) { // adjust the radii of the nodes
MTnode *node = oldList->RemoveFront();
AdjKeys (node);
delete node;
}
delete oldList;
for (int i=0; i<=nCreated; i++) { // delete all temporary subtrees
sprintf (newName, "%s.%i", name, i);
unlink (newName);
}
} else { // we can insert all the entries in a single node
GiSTpath path;
path.MakeRoot ();
GiSTnode *node = ReadNode (path);
for (int i=0; i<n; i++) {
node->Insert(*(data[i]));
}
assert (!node->IsOverFull(*Store()));
WriteNode (node);
delete node;
}
}
示例14: assert
// handle underfull leaf nodes
int
GiST::CondenseTree(GiSTnode *node)
{
GiSTlist<GiSTentry*> Q;
int deleted=0;
// Must be condensing a leaf
assert(node->IsLeaf());
while(!node->Path().IsRoot()) {
GiSTpath parent_path=node->Path();
parent_path.MakeParent();
GiSTnode *P=ReadNode(parent_path);
GiSTentry *En=P->SearchPtr(node->Path().Page());
assert(En!=NULL);
// Handle under-full node
if(node->IsUnderFull(*store)) {
if(!IsOrdered()) {
TruePredicate truePredicate;
GiSTlist<GiSTentry*> list=node->Search(truePredicate);
while(!list.IsEmpty()) {
GiSTentry *e=list.RemoveFront();
Q.Append(e);
}
P->DeleteEntry(En->Position());
WriteNode(P);
deleted=1;
AdjustKeys(P, NULL);
}
else {
// Try to borrow entries, else coalesce with a neighbor
// Have to look at left sibling???
GiSTpage neighbor_page=P->SearchNeighbors(node->Path().Page());
GiSTpath neighbor_path=node->Path();
neighbor_path.MakeSibling(neighbor_page);
if(neighbor_page!=0) {
GiSTnode *neighbor;
// If neighbor is RIGHT sibling...
if(node->Sibling()==neighbor_page) neighbor=ReadNode(neighbor_path);
else {
neighbor=node;
node=ReadNode(neighbor_path);
}
GiSTentry *e=P->SearchPtr(node->Path().Page());
node->Coalesce(*neighbor, *e);
delete e;
// If not overfull, coalesce, kill right node
if(!node->IsOverFull(*store)) {
node->SetSibling(neighbor->Sibling());
WriteNode(node);
// Delete the neighbor from parent
GiSTentry *e=P->SearchPtr(neighbor->Path().Page());
P->DeleteEntry(e->Position());
WriteNode(P);
delete e;
store->Deallocate(neighbor->Path().Page());
deleted=1;
}
// If overfull, split (same as borrowing)
else {
GiSTnode *node2=node->PickSplit();
node2->Path()=neighbor->Path();
node2->SetSibling(neighbor->Sibling());
WriteNode(node);
WriteNode(node2);
AdjustKeys(node2, &P);
delete node2;
deleted=1;
}
delete neighbor;
}
}
}
// Adjust covering predicate
if(!deleted) AdjustKeys(node, &P);
parent_path=node->Path();
parent_path.MakeParent();
delete node;
// Propagate deletes
if(!deleted) break;
node=P;
}
// Re-insert orphaned entries
while(!Q.IsEmpty()) {
GiSTentry *e=Q.RemoveFront();
InsertHelper(*e, e->Level());
delete e;
}
return(deleted);
//.........这里部分代码省略.........
示例15: vec
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();
//.........这里部分代码省略.........