Skip to content

Commit 01fb890

Browse files
authored
Update design-skiplist.cpp
1 parent 4a026c7 commit 01fb890

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

C++/design-skiplist.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ class Skiplist {
105105
}
106106

107107
int random_level() {
108-
static const int P_INV = 2; // P_INV = 4 in redis implementation
108+
static const int P_NUMERATOR = 1;
109+
static const int P_DENOMINATOR = 2; // P = 1/4 in redis implementation
109110
static const int MAX_LEVEL = 32; // enough for 2^32 elements
110111
int level = 1;
111-
while (uniform_int_distribution<int>{1, P_INV}(gen_) <= 1 &&
112+
while (uniform_int_distribution<int>{1, P_DENOMINATOR}(gen_) <= P_NUMERATOR &&
112113
level < MAX_LEVEL) {
113114
++level;
114115
}
@@ -223,10 +224,11 @@ class Skiplist2 {
223224
}
224225

225226
int random_level() {
226-
static const int P_INV = 2; // P_INV = 4 in redis implementation
227+
static const int P_NUMERATOR = 1;
228+
static const int P_DENOMINATOR = 2; // P = 1/4 in redis implementation
227229
static const int MAX_LEVEL = 32; // enough for 2^32 elements
228230
int level = 1;
229-
while (uniform_int_distribution<int>{1, P_INV}(gen_) <= 1 &&
231+
while (uniform_int_distribution<int>{1, P_DENOMINATOR}(gen_) <= P_NUMERATOR &&
230232
level < MAX_LEVEL) {
231233
++level;
232234
}

0 commit comments

Comments
 (0)