X-Git-Url: https://pd.if.org/git/?p=nbds;a=blobdiff_plain;f=struct%2Fskiplist.c;fp=struct%2Fskiplist.c;h=aa283fb0face2a2466d152d67dfdf6bff1762154;hp=f7cdf332cc8793724b2a02821df86b93e684220a;hb=fdfe9f6a2a27d10c4c94e29ee62c26061c9761a0;hpb=bfb84a32cb183c37bf4c7a4522f65a1173dcecd4 diff --git a/struct/skiplist.c b/struct/skiplist.c index f7cdf33..aa283fb 100644 --- a/struct/skiplist.c +++ b/struct/skiplist.c @@ -40,13 +40,12 @@ struct sl { static int random_level (void) { unsigned r = nbd_rand(); - if (r&1) + if (r & 1) return 0; - int n = __builtin_ctz(r)-1; #if MAX_LEVEL < 31 - if (n > MAX_LEVEL) - return MAX_LEVEL; + r |= 1 << (MAX_LEVEL+1); #endif + int n = __builtin_ctz(r)-1; assert(n <= MAX_LEVEL); return n; }