MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / zslRandomLevel

Function zslRandomLevel

src/t_zset.cpp:122–127  ·  view source on GitHub ↗

Returns a random level for the new skiplist node we are going to create. * The return value of this function is between 1 and ZSKIPLIST_MAXLEVEL * (both inclusive), with a powerlaw-alike distribution where higher * levels are less likely to be returned. */

Source from the content-addressed store, hash-verified

120 * (both inclusive), with a powerlaw-alike distribution where higher
121 * levels are less likely to be returned. */
122int zslRandomLevel(void) {
123 int level = 1;
124 while ((random()&0xFFFF) < (ZSKIPLIST_P * 0xFFFF))
125 level += 1;
126 return (level<ZSKIPLIST_MAXLEVEL) ? level : ZSKIPLIST_MAXLEVEL;
127}
128
129/* Insert a new node in the skiplist. Assumes the element does not already
130 * exist (up to the caller to enforce that). The skiplist takes ownership

Callers 1

zslInsertFunction · 0.85

Calls 1

randomFunction · 0.85

Tested by

no test coverage detected