Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Design] Interface of SkipList #15670

Closed
rapiz1 opened this issue May 14, 2020 · 5 comments
Closed

[Design] Interface of SkipList #15670

rapiz1 opened this issue May 14, 2020 · 5 comments

Comments

@rapiz1
Copy link
Member

rapiz1 commented May 14, 2020

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

  • eltType
  • record comparator
  • size
  • insert(x: eltType): insert an element.
  • contains(x: eltType): bool: return if x is in the list
  • lower_bound(x: eltType, out result: eltType): bool same as std::lower_bound(), return false if no occurence.
  • upper_bound(x: eltType, out result: eltType): bool same as std::upper_bound(), return false if no occurence.
  • remove(x: eltType): bool: remove x in the list. Does nothing if not present
  • these(): iterate over the list
  • kth(idx: int): return k-th element in the sorted sequence, throw an error if out of range
  • toArray: convert to an array
  • clear()
  • predecessor(x: eltType, out result: eltType): bool return the predecessor of one element, return false if it's the first one.
  • successor(x: eltType, out result: eltType): bool return the successor of one element, return false if it's the last one.

SkipListMap same as Map but with SkipList as the underlying structure

@rapiz1

This comment has been minimized.

@e-kayrakli
Copy link
Contributor

Issues somewhat related to your questions:

#15394
#14423

@cassella
Copy link
Contributor

Why are lower_bound() and upper_bound() here?

@rapiz1
Copy link
Member Author

rapiz1 commented May 20, 2020

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
Copy link
Member Author

rapiz1 commented Jul 7, 2020

Closed by #15921

@rapiz1 rapiz1 closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants