skip_list

This commit is contained in:
enqidu 2020-07-07 15:13:01 +04:00
parent 910180ff21
commit 8e99383dbf

View File

@ -70,8 +70,7 @@ SkipList::SkipList() {
*/ */
int SkipList::randomLevel() { int SkipList::randomLevel() {
int lvl = 0; int lvl = 0;
thread_local unsigned int seed = time(NULL); while((float)rand()/RAND_MAX < P && lvl < MAXLVL) lvl++;
while(rand_r(&seed)%2 < P && lvl < MAXLVL) lvl++;
return lvl; return lvl;
} }
@ -181,13 +180,12 @@ void SkipList::displayList() {
int main() int main()
{ {
thread_local unsigned int seed = time(NULL); srand((unsigned)time(0));
SkipList lst; SkipList lst;
for (int j = 0; j < (1 << (MAXLVL+1)); j++){ for (int j = 0; j < (1 << (MAXLVL+1)); j++){
int k = (rand_r(&seed) % (1 << (MAXLVL+1) + 1)); int k = (rand()% (1 << (MAXLVL+1) + 1));
lst.insertElement(k, &j); lst.insertElement(k, &j);
} }