void GuiTextListCtrl::sort(U32 column, bool increasing) { if (getNumEntries() < 2) return; sortColumn = column; sIncreasing = increasing; dQsort((void *)&(mList[0]), mList.size(), sizeof(Entry), textCompare); }
static void endStep(struct gbIndex* index, struct stepInfo* info) /* print the end of step message and record state */ { int numEntries = getNumEntries(index); gbVerbPr(0, "end %s: acc-added=%d, acc-total=%d ", info->step, (numEntries - info->startNumEntries), numEntries); }
const char* SamReferenceInfo::getReferenceName(int index) const { if((index >= 0) && (index < getNumEntries())) { return(myReferenceContigs[index].c_str()); } // Out of range, return blank return(""); }
int32_t SamReferenceInfo::getReferenceLength(int index) const { if((index >= 0) && (index < getNumEntries())) { return(myReferenceLengths[index]); } // Out of bounds, return 0 return(0); }
QTextStream &YZHistory::writeToStream( QTextStream &stream ) const { static const unsigned int MAX_ENTRIES_TO_WRITE = 50; QStringList::iterator start = d->entries.begin(); QStringList::iterator end = d->entries.end(); // cap the write out at MAX_ENTRIES_TO_WRITE if ( getNumEntries() > MAX_ENTRIES_TO_WRITE ) { start += getNumEntries() - MAX_ENTRIES_TO_WRITE; } for ( QStringList::iterator i = start; i != end; ++i ) { stream << ":"; stream << *i; stream << endl; } return stream; }
static struct stepInfo beginStep(struct gbIndex* index, struct gbRelease* release, char* step) /* print the start of step message and record state. gbRel maybe NULL */ { struct stepInfo info; if (release != NULL) printf("begin %s %s \n", release->name, step); else printf("begin %s \n", step); fflush(stdout); info.step = step; info.startNumEntries = getNumEntries(index); return info; }
RC deleteKey (BTreeHandle *tree, Value *key){ RID res; int rt = findKey(tree,key,&res); if(rt!=RC_OK){ return rt; } printf("delete(%d)\n", key->v.intV); int val = key->v.intV; Node *nd = (Node *)tree->mgmtData; int nnod,nent; getNumNodes (tree, &nnod); getNumEntries (tree, &nent); int i; while(1){ if(nd==NULL || nd->nval==0){ printf("error!\n"); return RC_IM_KEY_NOT_FOUND; } if(nd->leaf==true){//leaf //printf("leaf!!!!%d\n",key->v.intV); for(i=0;i<nd->nval;i++){ if(nd->vals[i]==val && nd->delt[i]==false){ nd->delt[i]=true; return RC_OK; } } return RC_IM_KEY_NOT_FOUND; } if(val < nd->vals[0]){ //printf("left(%d<%d)\n",val,nd->vals[0]); nd = nd->nds[0]; } else if(val < nd->vals[1]){ //printf("mid(%d<%d)\n",val,nd->vals[1]); nd = nd->nds[1]; } else{ //printf("right(%d>%d)\n",val,nd->vals[1]); nd = nd->nds[2]; } } }
RC openTreeScan (BTreeHandle *tree, BT_ScanHandle **handle) { *handle=(BT_ScanHandle*)calloc(1,sizeof(BT_ScanHandle)); (*handle) ->tree=tree; int n; BT_Node *node=NULL; n=tree->rootPage; getNode (tree, n, &node); while(node->nodeType !=1) { n=node->element->node; getNode(tree,n,&node); } (*handle)->currentNode=node->current; (*handle)->currentPos=0; getNumEntries (tree, &n); (*handle)->count=n; freeNode(node); return RC_OK; }
int ListSequencer::forward() { int pos; pos = getCurrent(); if (pos < 0) return 0; pos++; if (pos >= getNumEntries()) { if (loop()) { pos = 0; } else { return 0; } } setCurrent(pos); return 1; }
int ListSequencer::rewind() { int pos; pos = getCurrent(); if (pos < 0) return 0; pos--; if (pos < 0) { if (loop()) { pos = getNumEntries()-1; } else { pos++; } } setCurrent(pos); return 1; }
// index access RC findKey (BTreeHandle *tree, Value *key, RID *result){ //printf("finding(%d)\n", key->v.intV); int val = key->v.intV; Node *nd = (Node *)tree->mgmtData; //printf("root: %d,%d\n",nd->vals[0],nd->vals[1]); int nnod,nent; getNumNodes (tree, &nnod); getNumEntries (tree, &nent); int i; while(1){ if(nd==NULL || nd->nval==0){ //printf("error!\n"); return RC_IM_KEY_NOT_FOUND; } if(nd->leaf==true){//leaf //printf("leaf!!!!%d\n",key->v.intV); for(i=0;i<nd->nval;i++){ if(nd->vals[i]==val && nd->delt[i]==false){ result->page = nd->rids[i].page; result->slot = nd->rids[i].slot; return RC_OK; } } return RC_IM_KEY_NOT_FOUND; } if(val < nd->vals[0]){ //printf("left(%d<%d)\n",val,nd->vals[0]); nd = nd->nds[0]; } else if(val < nd->vals[1]){ //printf("mid(%d<%d)\n",val,nd->vals[1]); nd = nd->nds[1]; } else{ //printf("right(%d>%d)\n",val,nd->vals[1]); nd = nd->nds[2]; } } }
// ************************************************************ void testInsertAndFind (void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "test b-tree inserting and search"; int i, testint; BTreeHandle *tree = NULL; keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); printf("\n Init"); TEST_CHECK(createBtree("testidx", DT_INT, 2)); printf("\n Created"); TEST_CHECK(openBtree(&tree, "testidx")); // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[i], insert[i])); // check index stats TEST_CHECK(getNumNodes(tree, &testint)); ASSERT_EQUALS_INT(testint,4, "number of nodes in btree"); TEST_CHECK(getNumEntries(tree, &testint)); ASSERT_EQUALS_INT(testint, numInserts, "number of entries in btree"); // search for keys for(i = 0; i < 1000; i++) { int pos = rand() % numInserts; RID rid; Value *key = keys[pos]; TEST_CHECK(findKey(tree, key, &rid)); ASSERT_EQUALS_RID(insert[pos], rid, "did we find the correct RID?"); } // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); TEST_DONE(); }
// ************************************************************ void testIndexScan (void) { RID insert[] = { {1,1}, {2,3}, {1,2}, {3,5}, {4,4}, {3,2}, }; int numInserts = 6; Value **keys; char *stringKeys[] = { "i1", "i11", "i13", "i17", "i23", "i52" }; testName = "random insertion order and scan"; int i, testint, iter, rc; BTreeHandle *tree = NULL; BT_ScanHandle *sc = NULL; RID rid; keys = createValues(stringKeys, numInserts); // init TEST_CHECK(initIndexManager(NULL)); for(iter = 0; iter < 50; iter++) { int *permute; // create permutation permute = createPermutation(numInserts); // create B-tree TEST_CHECK(createBtree("testidx", DT_INT, 2)); TEST_CHECK(openBtree(&tree, "testidx")); // insert keys for(i = 0; i < numInserts; i++) TEST_CHECK(insertKey(tree, keys[permute[i]], insert[permute[i]])); // check index stats TEST_CHECK(getNumEntries(tree, &testint)); ASSERT_EQUALS_INT(testint, numInserts, "number of entries in btree"); // execute scan, we should see tuples in sort order openTreeScan(tree, &sc); i = 0; while((rc = nextEntry(sc, &rid)) == RC_OK) { RID expRid = insert[i++]; ASSERT_EQUALS_RID(expRid, rid, "did we find the correct RID?"); } ASSERT_EQUALS_INT(RC_IM_NO_MORE_ENTRIES, rc, "no error returned by scan"); ASSERT_EQUALS_INT(numInserts, i, "have seen all entries"); closeTreeScan(sc); // cleanup TEST_CHECK(closeBtree(tree)); TEST_CHECK(deleteBtree("testidx")); free(permute); } TEST_CHECK(shutdownIndexManager()); freeValues(keys, numInserts); TEST_DONE(); }
void DropDownBox::resizeListBox() { int listBoxHeight = std::max(1,std::min(numVisibleEntries,getNumEntries())) * (int) GUIStyle::getInstance().getListBoxEntryHeight() + 2; listBox.resize(getSize().x-1, listBoxHeight); }
int ListSequencer::getNumItems() { return getNumEntries(); }
RC insertKey(BTreeHandle *tree, Value *key, RID rid) { RC rc; // get root page PageNumber rootPage; rc = -99; rc = getRootPage(tree, &rootPage); if (rc != RC_OK) { return rc; } RID result; BT_KeyPosition *kp; rc = -99; rc = searchKeyFromRoot(tree, key, &result, kp); // if return RC_OK, then the to-be inserted key is found, return RC_IM_KEY_ALREADY_EXISTS // else if return RC_IM_KEY_NOT_FOUND, then the to-be inserted key is not in the tree, insert it // else, some error happens, return rc if (rc == RC_OK) { return RC_IM_KEY_ALREADY_EXISTS; } else if (rc == RC_IM_KEY_NOT_FOUND) { // start to insert // get N int n; rc = -99; rc = getN(tree, &n); if (rc != RC_OK) { return rc; } // get current keys int currentKeys; rc = -99; rc = getCurrentKeys(tree, kp->nodePage, ¤tKeys); if (rc != RC_OK) { return rc; } // if current node is full, split it into two nodes if (currentKeys == n) { // split splitNode(); } else { rc = -99; rc = insertLeafNode(tree, kp, key, &rid); if (rc != RC_OK) { return rc; } } // increment # of entries by 1 int numEntries; rc = -99; rc = getNumEntries(tree, kp->nodePage, &numEntries); if (rc != RC_OK) { return rc; } rc = -99; rc = setNumEntries(tree, kp->nodePage, ++numEntries); if (rc != RC_OK) { return rc; } } else { return rc; } return RC_OK; }