]> pd.if.org Git - nbds/blobdiff - struct/skiplist.c
minor change
[nbds] / struct / skiplist.c
index f7cdf332cc8793724b2a02821df86b93e684220a..aa283fb0face2a2466d152d67dfdf6bff1762154 100644 (file)
@@ -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;
 }