void MTnode::InsertBefore(const GiSTentry& entry, int index) { int n=NumEntries(); BOOL ordered=TRUE; if(index>0) ordered=((*this)[index-1]->Compare(entry)<=0); if(index<n) ordered=ordered&&((*this)[index]->Compare(entry)>=0); if(ordered) { // yes, the position is right for this entry assert(index<=n); GiSTentry *e=(GiSTentry *)entry.Copy(); e->SetLevel(Level()); e->SetPosition(index); e->SetNode(this); // Move everything else over for(int i=n; i>index; i--) { GiSTentry *e=(*this)[i-1]; e->SetPosition(i); (*this)[i]=e; } // Stick the entry in (*this)[index]=e; // Bump up the count SetNumEntries(n+1); } else Insert(entry); // find the right place }
// insert before the original number according to the sequence instead of index void MTnode::InsertBefore (const GiSTentry& newEntry, int index) { int n = NumEntries (); assert (index>=0 && index<=n); BOOL bOrder = TRUE; if (index > 0) { bOrder = (*this)[index-1]->Compare(newEntry) <= 0; } if (index < n) { bOrder = bOrder && (*this)[index]->Compare(newEntry) >= 0; } if (bOrder) { // yes, the position is right for this entry GiSTentry *entry = (GiSTentry *) newEntry.Copy (); entry->SetLevel(Level()); entry->SetPosition(index); entry->SetNode(this); // Move everything else over for (int i=n; i>index; i--) { GiSTentry *e = (*this)[i-1]; e->SetPosition(i); (*this)[i] = e; } // Stick the entry in (*this)[index] = entry; // Bump up the count SetNumEntries (n+1); } else { Insert (newEntry); // find the right place } }
GiSTentry* GiSTnode::SearchPtr(GiSTpage ptr) const { for (int i=0; i<numEntries; i++) { GiSTentry *e = (*this)[i]; if (e->Ptr() == ptr) return (GiSTentry*) e->Copy(); } return NULL; }
GiSTlist<GiSTentry*> GiSTnode::Search(const GiSTpredicate &query) const { GiSTlist<GiSTentry*> list; for (int i=0; i<numEntries; i++) { GiSTentry *e = (*this)[i]; if (query.Consistent(*e)) list.Append((GiSTentry*)e->Copy()); } return list; }
void GiSTnode::InsertBefore (const GiSTentry& entry, int index) { assert (index <= NumEntries()); GiSTentry *e = (GiSTentry*)entry.Copy(); e->SetLevel (Level()); e->SetPosition (index); e->SetNode (this); // Move everything else over for (int i=NumEntries(); i>index; i--) { GiSTentry *e = (*this)[i-1]; e->SetPosition (i); (*this)[i] = e; } // Stick the entry in (*this)[index] = e; // Bump up the count numEntries++; }