Skip to content

Commit

Permalink
refs #13 simply implementation in randLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
huandu committed Sep 23, 2021
1 parent 8a65cb9 commit 9e1f5d9
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions skiplist.go
Expand Up @@ -453,22 +453,18 @@ func (list *SkipList) SetMaxLevel(level int) (old int) {
}

func (list *SkipList) randLevel() int {
if list.maxLevel <= 1 {
return 1
}

estimated := list.maxLevel
const prob = 1 << 30 // Half of 2^31.
rand := list.rand
i := 0
i := 1

for ; i < estimated; i++ {
if rand.Int31() < prob {
break
}
}

return i + 1
return i
}

// compare compares value of two elements and returns -1, 0 and 1.
Expand Down

0 comments on commit 9e1f5d9

Please sign in to comment.