src/btree/btrec.c
/*====================================================
 * isrecord -- See if there is a record with given key
 *==================================================*/
- See if there is a record with given key
- See if there is a record with given key
BOOLEAN
isrecord (BTREE btree,
          RKEY rkey)
{
	INDEX index;
	INT i, n, lo, hi;
	FKEY nfkey;
	BLOCK block;
	ASSERT(index = bmaster(btree));
	while (ixtype(index) == BTINDEXTYPE) {
		n = nkeys(index);
		nfkey = fkeys(index, 0);
		for (i = 1; i <= n; i++) {
			if (cmpkeys(&rkey, &rkeys(index, i)) < 0)
				break;
			nfkey = fkeys(index, i);
		}
		index = getindex(btree, nfkey);
	}
	block = (BLOCK) index;
	lo = 0;
	hi = nkeys(block) - 1;
	while (lo <= hi) {
		INT md = (lo + hi)/2;
		INT rel = cmpkeys(&rkey, &rkeys(block, md));
		if (rel < 0)
			hi = --md;
		else if (rel > 0)
			lo = ++md;
		else
			return TRUE;
	}
	return FALSE;
}
BOOLEAN isrecord ( BTREE btree , RKEY rkey ) { INDEX index ; INT i , n , lo , hi ; FKEY nfkey ; BLOCK block ; ASSERT ( index = bmaster ( btree ) ) ; while ( ixtype ( index ) == BTINDEXTYPE ) { n = nkeys ( index ) ; nfkey = fkeys ( index , 0 ) ; for ( i = 1 ; i <= n ; i ++ ) { if ( cmpkeys ( & rkey , & rkeys ( index , i ) ) < 0 ) break ; nfkey = fkeys ( index , i ) ; } index = getindex ( btree , nfkey ) ; } block = ( BLOCK ) index ; lo = 0 ; hi = nkeys ( block ) - 1 ; while ( lo <= hi ) { INT md = ( lo + hi ) / 2 ; INT rel = cmpkeys ( & rkey , & rkeys ( block , md ) ) ; if ( rel < 0 ) hi = -- md ; else if ( rel > 0 ) lo = ++ md ; else return TRUE ; } return FALSE ; }
isrecord -- See if there is a record with given key
isrecord -- See if there is a record with given key
/* search for data block that does/should hold record */ /* Found block that may hold record - search for key */