-// advance to next slot
-
-uint bt_findnext (BtDb *bt, BtPageSet *set, uint slot)
-{
-BtLatchSet *prevlatch;
-uid page_no;
-
- if( slot < set->page->cnt )
- return slot + 1;
-
- prevlatch = set->latch;
-
- if( page_no = bt_getid(set->page->right) )
- if( set->latch = bt_pinleaf (bt->mgr, page_no, bt->thread_no) )
- set->page = bt_mappage (bt->mgr, set->latch);
- else
- return 0;
- else
- return bt->mgr->err = BTERR_struct, bt->mgr->err_thread = bt->thread_no, bt->mgr->line = __LINE__, 0;
-
- // obtain access lock using lock chaining with Access mode
-
- bt_lockpage(BtLockAccess, set->latch, bt->thread_no, __LINE__);
-
- bt_unlockpage(BtLockRead, prevlatch, bt->thread_no, __LINE__);
- bt_unpinlatch (prevlatch, bt->thread_no, __LINE__);
-
- bt_lockpage(BtLockRead, set->latch, bt->thread_no, __LINE__);
- bt_unlockpage(BtLockAccess, set->latch, bt->thread_no, __LINE__);
- return 1;
-}
-
-// find unique key == given key, or first duplicate key in
-// leaf level and return number of value bytes
-// or (-1) if not found.
-
-int bt_findkey (BtDb *bt, unsigned char *key, uint keylen, unsigned char *value, uint valmax)
-{
-BtPageSet set[1];
-uint len, slot;
-int ret = -1;
-BtKey *ptr;
-BtVal *val;
-
- if( slot = bt_loadpage (bt->mgr, set, key, keylen, 0, BtLockRead, bt->thread_no) )
- do {
- ptr = keyptr(set->page, slot);
-
- // skip librarian slot place holder
-
- if( slotptr(set->page, slot)->type == Librarian )
- ptr = keyptr(set->page, ++slot);
-
- // return actual key found
-
- memcpy (bt->key, ptr, ptr->len + sizeof(BtKey));
- len = ptr->len;
-
- if( slotptr(set->page, slot)->type == Duplicate )
- len -= BtId;
-
- // not there if we reach the stopper key
-
- if( slot == set->page->cnt )
- if( !bt_getid (set->page->right) )
- break;
-
- // if key exists, return >= 0 value bytes copied
- // otherwise return (-1)
-
- if( slotptr(set->page, slot)->dead )
- continue;
-
- if( keylen == len )
- if( !memcmp (ptr->key, key, len) ) {
- val = valptr (set->page,slot);
- if( valmax > val->len )
- valmax = val->len;
- memcpy (value, val->value, valmax);
- ret = valmax;
- }
-
- break;
-
- } while( slot = bt_findnext (bt, set, slot) );
-
- bt_unlockpage (BtLockRead, set->latch, bt->thread_no, __LINE__);
- bt_unpinlatch (set->latch, bt->thread_no, __LINE__);
- return ret;
-}
-