Skip to content

Commit

Permalink
Properly set randomized priority for treaps.
Browse files Browse the repository at this point in the history
  • Loading branch information
rbehrends committed Apr 12, 2018
1 parent bb7fc12 commit b4143a6
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,27 @@ static int treap_delete(treap_t **treap, void *addr)
return 0;
}

static uint64_t xorshift_rng_state = 1;

static uint64_t xorshift_rng()
{
uint64_t x = xorshift_rng_state;
x = x ^ (x >> 12);
x = x ^ (x << 25);
x = x ^ (x >> 27);
xorshift_rng_state = x;
return x * (uint64_t) 0x2545F4914F6CDD1DUL;
}


static treap_t *bigvals;

void *alloc_bigval(size_t size) {
void *result = malloc(size);
memset(result, 0, size);
treap_t *node = alloc_treap();
node->addr = result;
node->prio = xorshift_rng();
treap_insert(&bigvals, node);
return result;
}
Expand Down

0 comments on commit b4143a6

Please sign in to comment.