chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

[Design] Interface of SkipList #15670

Closed rapiz1 closed 4 years ago

rapiz1 commented 4 years ago

SkipList / SkipListMap

Red-Black Tree alternative.

I'm also proposing a kind of Map built on SkipList.

Used in many popular projects like LevelDB, Reddis, Bigtable

vs Red-Black Tree

SkipList Red-Black Tree
Larger constant factor, but fast in practice
Easy to implement Very difficut to implement
Could be lock-free Need a lock
With expected time complexity, not stable With upper bound complexity

And Skip List will on expectation use less space than all balanced trees.

In practice, it's fairly fast

So between Skip List and Treap, it's a time-space trade off ( though SkipList sometimes is actually faster )

Interface

SkipListMap same as Map but with SkipList as the underlying structure

rapiz1 commented 4 years ago

One question: How can lower_bound and upper_bound return nullable value? This is also a problem for SearchTree. We can only apply ? to class, but many times users would use these structures that support quick search with integers. In that case, when users search the structure but with no occurrence, we couldn't return a nil value. One solution could be that passing a reference to the procedure and store the result in that if there's an occurrence. Meanwhile, the procedure returns bool to indicate whether there is indeed an occurrence.

e-kayrakli commented 4 years ago

Issues somewhat related to your questions:

https://github.com/chapel-lang/chapel/issues/15394 https://github.com/chapel-lang/chapel/issues/14423

cassella commented 4 years ago

Why are lower_bound() and upper_bound() here?

rapiz1 commented 4 years ago

Why are lower_bound() and upper_bound() here?

SkipList has all the functionality of a search tree. Or think it as a sorted array. lower_bound and upper_bound are useful for searching elements closest to the target.

rapiz1 commented 4 years ago

Closed by https://github.com/chapel-lang/chapel/issues/15921