Tags: zhangyunhao116/skipmap
Tags
LoadOrStore: generate the level lazily (#10) The key problem is that `LoadOrStore` uses an outdated highest level to search the skip list, if the new generated level(says `newLevel`) is bigger than the outdated highest level(says `oldLevel`), all slots in the slices `preds[newLevel-oldLevel:newLevel]` are nil, the function will panic. The solution is that if the `newLevel` has updated the highest level, we could just continue the loop, and find a new path. At this time, the latest highest level used by the `findNode` is always bigger than or equal to the newLevel, the function won't panic. name old time/op new time/op delta LoadOrStoreExist-16 4.43ns ±11% 1.06ns ±21% -76.05% (p=0.000 n=10+10) LoadOrStoreLazyExist-16 4.61ns ± 6% 1.16ns ± 0% -74.90% (p=0.000 n=9+7) LoadOrStoreExistSingle-16 37.5ns ± 6% 10.3ns ± 0% -72.61% (p=0.000 n=9+9) LoadOrStoreLazyExistSingle-16 38.3ns ±11% 10.6ns ± 0% -72.43% (p=0.000 n=10+10) LoadOrStoreRandom-16 209ns ±14% 206ns ±14% ~ (p=0.684 n=10+10) LoadOrStoreLazyRandom-16 215ns ± 8% 207ns ± 9% ~ (p=0.139 n=10+10) LoadOrStoreRandomSingle-16 1.05µs ± 1% 1.04µs ± 4% ~ (p=0.535 n=9+10) LoadOrStoreLazyRandomSingle-16 1.07µs ± 1% 1.06µs ± 3% -1.09% (p=0.029 n=8+9)
PreviousNext