Skip to content

Add splay tree data structure#1041

Open
kuchma19 wants to merge 1 commit into
TheAlgorithms:masterfrom
kuchma19:add-splay-tree
Open

Add splay tree data structure#1041
kuchma19 wants to merge 1 commit into
TheAlgorithms:masterfrom
kuchma19:add-splay-tree

Conversation

@kuchma19
Copy link
Copy Markdown

@kuchma19 kuchma19 commented May 21, 2026

Adds a SplayTree data structure.

Description

A splay tree is a self-adjusting binary search tree: after an access, the accessed value is moved to the root. If the searched value is absent, the last visited node is moved to the root instead. This implementation uses safe Rust with Option<Box<Node<T>>> and does not store parent pointers.

Implemented operations:

  • new
  • len
  • is_empty
  • contains
  • insert
  • remove
  • merge
  • FromIterator

The merge operation assumes that every value in the left tree is less than every value in the right tree.

Reference:
https://en.wikipedia.org/wiki/Splay_tree

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

Notes:

  • cargo fmt -- --check passes.
  • cargo test splay_tree --lib passes.
  • cargo clippy --all -- -D warnings currently reports existing warnings in unrelated files:
    • src/string/manacher.rs
    • src/greedy/job_sequencing.rs
    • src/string/burrows_wheeler_transform.rs
  • Full cargo test aborted with SIGABRT while running the repository-wide test suite, outside the new splay_tree tests.

@kuchma19 kuchma19 requested a review from imp2002 as a code owner May 21, 2026 22:24
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.90164% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.82%. Comparing base (37c9e12) to head (f4dfb53).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/data_structures/splay_tree.rs 95.90% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1041      +/-   ##
==========================================
- Coverage   95.82%   95.82%   -0.01%     
==========================================
  Files         393      394       +1     
  Lines       29972    30215     +243     
==========================================
+ Hits        28722    28954     +232     
- Misses       1250     1261      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants