Skip to contentSkip to conversation

binary search in ext4_ext_binsearch_idx()

DISCUSSION minskey 1 participant 1 message Apr 8, 2010

lore
Share & tools
lore

minskey

author
#0 lore raw

in ext4_ext_binsearch_idx() routine, there is the following code:

 while (l <= r) {
                m = l + (r - l) / 2;
                if (block < le32_to_cpu(m->ei_block))
                        r = m - 1;
                else
                        l = m + 1;

}

path->p_idx = l - 1;

The code always runs logN iterations to get the expected extent, if 3-way comparison is used, we can save some iterations when (block == le32_to_cpu(m->ei_block)) at the first iteration.

some other routines, such as ext4_ext_binsearch() etc, use the same algorithm (2-way comparison), Is there any special goal ?

thanks,
-minskey