本文整理汇总了C++中GiSTlist::IsEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ GiSTlist::IsEmpty方法的具体用法?C++ GiSTlist::IsEmpty怎么用?C++ GiSTlist::IsEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GiSTlist
的用法示例。
在下文中一共展示了GiSTlist::IsEmpty方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: ReadNode
// split this M-tree into a list of trees having height level, which is used in the "splitting" phase of the BulkLoad algorithm
// nCreated is the number of created subtrees,
// level is the split level for the tree,
// children is the list of the parents of each subtree,
// name is the root for the subtrees names
// the return value is the list of splitted subtrees's names
GiSTlist<char *> *
MT::SplitTree (int *nCreated, int level, GiSTlist<MTentry *> *parentEntries, const char *name)
{
GiSTlist<MTnode *> *oldList = new GiSTlist<MTnode *>; // upper level nodes
MTnode *node = new MTnode; // this is because the first operation on node is a delete
GiSTpath path;
path.MakeRoot ();
oldList->Append((MTnode *) ReadNode(path)); // insert the root
do { // build the roots list
GiSTlist<MTnode *> *newList = new GiSTlist<MTnode *>; // lower level nodes
while (!oldList->IsEmpty()) {
delete node; // delete the old node created by ReadNode
node = oldList->RemoveFront(); // retrieve next node to be examined
path = node->Path();
for (int i=0; i<node->NumEntries(); i++) { // append all its children to the new list
path.MakeChild ((*node)[i].Ptr()->Ptr());
newList->Append((MTnode *)ReadNode(path));
path.MakeParent ();
}
}
delete oldList;
oldList = newList;
} while (node->Level() > level); // stop if we're at the split level
delete node;
GiSTlist<char *> *newTreeNames = new GiSTlist<char *>; // this is the results list
while (!oldList->IsEmpty()) { // now append each sub-tree to its root
char newName[50];
sprintf (newName, "%s.%i", name, ++(*nCreated));
unlink (newName); // if this M-tree already exists, delete it
MT *newTree = new MT;
newTree->Create(newName); // create a new M-tree
path.MakeRoot ();
MTnode *rootNode = (MTnode *) newTree->ReadNode(path); // read the root of the new tree
node = oldList->RemoveFront();
newTree->Append(rootNode, (MTnode *)node->Copy()); // append the current node to the root of new tree
parentEntries->Append(node->ParentEntry()); // insert the original parent entry into the list
newTreeNames->Append(strdup(newName)); // insert the new M-tree name into the list
delete node;
delete rootNode;
delete newTree;
}
delete oldList;
return newTreeNames;
}
示例3: RemoveTop
void
GiST::OverflowTreatment (GiSTnode *node, const GiSTentry& entry, int *splitvec)
{
// remove the "top" p entries from the node
GiSTlist<GiSTentry*> deleted = RemoveTop (node);
WriteNode (node);
AdjustKeys (node, NULL);
// note that we've seen this level already
splitvec[node->Level()] = 1;
// for each of the deleted entries, call InsertHelper at this level
while (!deleted.IsEmpty()) {
GiSTentry *tmpentry = deleted.RemoveFront ();
InsertHelper (*tmpentry, node->Level(), splitvec);
delete tmpentry;
}
}
示例4: 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;
}
示例5: 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;
}
示例6: main
int main()
{
MXTree *tree = new MXTree;
tree->Open(MXTreePath.c_str());
assert(tree->IsOpen());
time_t time_start, time_end;
time(&time_start);
ifstream fin(path.c_str());
for (int i=0; i<amount/1000; i++) {
Object *obj = Read(fin, rand()%amount);
Pred *pred = new Pred(*obj);
delete obj;
SimpleQuery query(pred, 40);
delete pred;
GiSTlist<MTentry *> list = tree->RangeSearch(query);
while (!list.IsEmpty()) {
MTentry *e = list.RemoveFront();
++objs;
delete e;
}
Progress(i, 1200);
}
fin.close();
time(&time_end);
cout<<difftime(time_end, time_start)<<endl;
delete tree;
cout << "Computed dists = " << compdists << endl;
cout << "IO reads = " << IOread << endl;
cout << "IO writes = " << IOwrite << endl;
cout << "Objs = " << objs << endl;
return 0;
}
示例7: Path
GiSTlist<MTentry *>
MTnode::RangeSearch (const MTquery &query)
{
GiSTlist<MTentry *> results;
if (IsLeaf()) {
for (int i=0; i<NumEntries(); i++) {
MTentry *entry = (MTentry *) (*this)[i].Ptr()->Copy();
MTquery *newQuery = (MTquery *) query.Copy();
if (newQuery->Consistent(*entry)) { // object qualifies
entry->SetMaxRadius(newQuery->Grade());
results.Append (entry);
} else {
delete entry;
}
delete newQuery;
}
} else {
for (int i=0; i<NumEntries(); i++) {
MTentry *entry = (MTentry *) (*this)[i].Ptr();
MTquery *newQuery = (MTquery *) query.Copy();
if (newQuery->Consistent(*entry)) { // sub-tree included
GiSTpath childPath = Path ();
childPath.MakeChild (entry->Ptr());
MTnode *childNode = (MTnode *) ((MT *)Tree())->ReadNode(childPath);
GiSTlist<MTentry *> childResults = childNode->RangeSearch(*newQuery); // recurse the search
while (!childResults.IsEmpty()) {
results.Append (childResults.RemoveFront());
}
delete childNode;
}
delete newQuery;
}
}
return results;
}
示例8: main
//.........这里部分代码省略.........
else {
MTpred *npred=new Pred(*obj);
pred=new NotPred(npred);
delete npred;
}
// eps=atof(argv[1]);
TopQuery query(pred, k);
delete pred;
if(!gist) CommandOpen("mtree", "graphs.M3");
CommandNearest(query);
CommandClose();
delete obj;
}
else if(!strcmp(cmdLine, "cursor")) {
MTobject *obj=Read();
Pred pred(*obj);
if(!gist) CommandOpen("mtree", "graphs.M3");
MTcursor cursor(*gist, pred);
scanf("%s", cmdLine);
while(strcmp(cmdLine, "close")) {
if(!strcmp(cmdLine, "next")) {
int k;
GiSTlist<MTentry *> list;
scanf("%s", cmdLine);
k=atoi(cmdLine);
// std::cout << "Fetching next " << k << " entries...\n";
for(; k>0; k--) list.Append(cursor.Next());
while(!list.IsEmpty()) {
MTentry *e=list.RemoveFront();
// std::cout << e;
delete e;
objs++;
}
}
scanf("%s", cmdLine);
}
delete obj;
CommandClose();
}
/* else if(!strcmp(cmdLine, "find")) {
int n, k, l, oldcompdists, oldIOread, oldobjs;
scanf("%s", cmdLine);
n=atoi(cmdLine);
double **x=(double **)calloc(n, sizeof(double *));
for(i=0; i<n; i++) x[i]=(double *)calloc(dimension, sizeof(double));
MTpred **p=(MTpred **)calloc(n, sizeof(MTpred *));
AndPred **ap=(AndPred **)calloc(n-1, sizeof(AndPred *));
for(i=0; i<n; i++) {
for(int j=0; j<dimension; j++) {
scanf("%s", cmdLine);
x[i][j]=atof(cmdLine);
}
if(x[i][0]>=0) {
MTobject obj(x[i]);
// std::cout << "obj=" << obj << std::endl;
p[i]=new Pred(obj);
}
示例9:
// 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);
//.........这里部分代码省略.........
示例10: 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;
}
//.........这里部分代码省略.........