feat: add Skip List (Data-Structures/Linked-List)#1896
Open
ChrisJr404 wants to merge 1 commit intoTheAlgorithms:masterfrom
Open
feat: add Skip List (Data-Structures/Linked-List)#1896ChrisJr404 wants to merge 1 commit intoTheAlgorithms:masterfrom
ChrisJr404 wants to merge 1 commit intoTheAlgorithms:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1896 +/- ##
==========================================
+ Coverage 85.91% 86.12% +0.20%
==========================================
Files 379 380 +1
Lines 19778 20089 +311
Branches 3016 3068 +52
==========================================
+ Hits 16993 17302 +309
- Misses 2785 2787 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a Skip List implementation under
Data-Structures/Linked-List/SkipList.jswith a companion test file under the existingtest/directory.A skip list is a probabilistic ordered-set / map data structure with expected O(log n) search, insert and delete. Each newly inserted node is promoted to the next level with probability
p(default 1/2), giving an expected height of log_{1/p}(n). Compared to balanced BSTs (AVL, red-black) it is much simpler to implement because there are no rotations - balance is maintained statistically rather than structurally. Its semantics also map cleanly onto a multi-level linked list, which is why it lives next to the other linked-list variants in this repo.Reference: https://en.wikipedia.org/wiki/Skip_list
API
SkipListexposes:insert(key, value?)(returnsthis, chainable; updates value if key exists)search(key)-> value orundefinedhas(key)-> booleandelete(key)-> booleansize()/isEmpty()entries()generator yielding[key, value]pairs in ascending key orderSymbol.iteratoryielding keys in ascending orderThe constructor accepts
{ maxLevel, p, random }so the RNG can be injected for deterministic testing.Tests
Data-Structures/Linked-List/test/SkipList.test.jsadds 14 cases covering:SetreferencemaxLevel,p,random)Checks
npm run check-stylecleannpm test-> 347 files / 11984 tests pass locally (including the 14 new ones)DIRECTORY.mdis intentionally not touched in this PR - theUpdateDirectoryworkflow will regenerate it on push.