[cairo-skiplist] Use one random number per insertion, instead of two

This commit is contained in:
Behdad Esfahbod 2007-04-08 23:35:01 -04:00
parent 6daaf8a89d
commit b6924722b8
2 changed files with 8 additions and 2 deletions

View file

@ -32,6 +32,9 @@
* http://citeseer.ist.psu.edu/pugh90skip.html
*/
/* Note that random_level() called from alloc_node_for_level() depends on
* this being not more than 16.
*/
#define MAX_LEVEL 15
/* Returns the index of the free-list to use for a node at level 'level' */

View file

@ -269,9 +269,12 @@ _cairo_skip_list_fini (cairo_skip_list_t *list)
static int
random_level (void)
{
/* tricky bit -- each bit is '1' 75% of the time */
long int bits = lfsr_random() | lfsr_random();
int level = 0;
/* tricky bit -- each bit is '1' 75% of the time.
* This works because we only use the lower MAX_LEVEL
* bits, and MAX_LEVEL < 16 */
long int bits = lfsr_random();
bits |= bits >> 16;
while (++level < MAX_LEVEL)
{