github.com/songzhibin97/go-baseutils@v0.0.2-0.20240302024150-487d8ce9c082/structure/sets/skipset/README.md (about) 1 ## Introduction 2 3 skipset is a high-performance concurrent set based on skip list. In typical pattern(100000 operations, 90%CONTAINS 9%ADD 4 1%REMOVE), the skipset up to 3x ~ 15x faster than the built-in sync.Map. 5 6 The main idea behind the skipset 7 is [A Simple Optimistic Skiplist Algorithm](<https://people.csail.mit.edu/shanir/publications/LazySkipList.pdf>). 8 9 Different from the sync.Map, the items in the skipset are always sorted, and the `Contains` and `Range` operations are 10 wait-free (A goroutine is guaranteed to complete an operation as long as it keeps taking steps, regardless of the 11 activity of other goroutines). 12 13 ## Features 14 15 - Concurrent safe API with high-performance. 16 - Wait-free Contains and Range operations. 17 - Sorted items. 18 19 ## When should you use skipset 20 21 In these situations, `skipset` is better 22 23 - **Sorted elements is needed**. 24 - **Concurrent calls multiple operations**. such as use both `Contains` and `Add` at the same time. 25 - **Memory intensive**. The skipset save at least 50% memory in the benchmark. 26 27 In these situations, `sync.Map` is better 28 29 - Only one goroutine access the set for most of the time, such as insert a batch of elements and then use 30 only `Contains` (use built-in map is even better).