src/btree/utils.c
/* Explanation of FKEY algorithm, by example.
 *
 * Iter  Text    Hex (HI/LO)  Text   Hex (HI/LO)  Notes 
 * ----+-------+------------+------+------------+------------
 *  00                        ab/ab  0x00010001   First index key
 *  01   ab/ab   0x00010001   aa/ab  0x00000001   Case 1
 *  02   aa/ab   0x00000001   ac/aa  0x00020000   Case 4
 *  03   ac/aa   0x00020000   ac/ab  0x00020001   Case 2
 *  04   ac/ab   0x00020001   ac/ac  0x00020002   Case 2
 *  05   ac/ac   0x00020002   aa/ac  0x00000002   Case 1
 *  06   aa/ac   0x00000002   ab/ac  0x00010002   Case 3
 *  07   ab/ac   0x00010002   ad/aa  0x00030000   Case 4
 *  08   ad/aa   0x00030000   ad/ab  0x00030001   Case 2
 *  09   ad/ab   0x00030001   ad/ac  0x00030002   Case 2
 *  10   ad/ac   0x00030002   ad/ad  0x00030003   Case 2
 *  11   ad/ad   0x00030003   aa/ad  0x00000003   Case 1
 *  12   aa/ad   0x00000003   ab/ad  0x00010003   Case 3
 *  13   ab/ad   0x00010003   ac/ad  0x00020003   Case 3
 *  14   ac/ad   0x00020003   ae/aa  0x00040000   Case 4
 *  15   ae/aa   0x00040000   ae/ab  0x00040001   Case 2
 * 
 * and so on ...
 * 
 * This is curious pattern and will be difficult to optimize.
 */
Explanation of FKEY algorithm, by example.

and so on

This is curious pattern and will be difficult to optimize.
Explanation of FKEY algorithm by example . and so on This is curious pattern and will be difficult to optimize .
void
nextfkey (BTREE btree)
{
	FKEY fkey = btree->b_kfile.k_fkey;
	INT16 hi = (fkey & 0xffff0000) >> 16;
	INT16 lo = fkey & 0x0000ffff;
	char scratch[MAXPATHLEN];
	if (hi == lo)
		fkey = lo;
	else if (hi > lo)
		++fkey;
	else if (hi < lo-1)
		fkey += 0x00010000;
	else 
        {
		fkey += 0x00020000;
		fkey &= 0xffff0000;
		snprintf(scratch, sizeof(scratch), "%s/%s", btree->b_basedir, fkey2path(fkey));
		if (!mkalldirs(scratch))
			FATAL();
	}
	btree->b_kfile.k_fkey = fkey;
}
void nextfkey ( BTREE btree ) { FKEY fkey = btree -> b_kfile . k_fkey ; INT16 hi = ( fkey & 0xffff0000 ) >> 16 ; INT16 lo = fkey & 0x0000ffff ; char scratch [ MAXPATHLEN ] ; if ( hi == lo ) fkey = lo ; else if ( hi > lo ) ++ fkey ; else if ( hi < lo - 1 ) fkey += 0x00010000 ; else { fkey += 0x00020000 ; fkey &= 0xffff0000 ; snprintf ( scratch , sizeof ( scratch ) , " " , btree -> b_basedir , fkey2path ( fkey ) ) ; if ( ! mkalldirs ( scratch ) ) FATAL ( ) ; } btree -> b_kfile . k_fkey = fkey ; }
Explanation of FKEY algorithm, by example.
Explanation of FKEY algorithm by example .
/* Case 1: HI=0000 LO=xxxx */ /* Case 2: HI=HI, LO=LO+1 */ /* Case 3: HI++, LO=LO */ /* Case 4: HI+=2, LO=00 */ /* (hi == lo-1) */