MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / randomLevel

Function randomLevel

sorted_set.go:322–333  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

320// (both inclusive), with a powerlaw-alike distribution where higher
321// levels are lesl likely to be returned.
322func randomLevel() int {
323 level := 1
324
325 for float64(rand.Int31()&0xFFFF) < SkipListP*0xFFFF {
326 level += 1
327 }
328 if level < SkipListMaxLevel {
329 return level
330 }
331
332 return SkipListMaxLevel
333}
334
335func newSkipList(db *DB) *SkipList {
336 skipList := &SkipList{

Callers 1

insertNodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected