mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-08 05:40:31 +01:00
[cairo-skiplist] Use one random number per insertion, instead of two
This commit is contained in:
parent
6daaf8a89d
commit
b6924722b8
2 changed files with 8 additions and 2 deletions
|
|
@ -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' */
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue