{"id":28630958,"url":"https://github.com/piotrmurach/splay_tree","last_synced_at":"2025-12-16T20:28:56.444Z","repository":{"id":25125918,"uuid":"28547709","full_name":"piotrmurach/splay_tree","owner":"piotrmurach","description":"A self-balancing binary tree optimised for fast access to frequently used nodes.","archived":false,"fork":false,"pushed_at":"2024-03-23T21:11:40.000Z","size":50,"stargazers_count":24,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T17:49:33.130Z","etag":null,"topics":["algorithm","binarytree","ruby","ruby-gem","splay-trees","splaytree","tree"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piotrmurach.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"piotrmurach"}},"created_at":"2014-12-27T22:18:48.000Z","updated_at":"2024-01-09T22:38:13.000Z","dependencies_parsed_at":"2024-03-23T22:22:46.245Z","dependency_job_id":null,"html_url":"https://github.com/piotrmurach/splay_tree","commit_stats":{"total_commits":61,"total_committers":1,"mean_commits":61.0,"dds":0.0,"last_synced_commit":"ea5e2a41a52835e934281a01c55ad208bf9530a1"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/piotrmurach/splay_tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fsplay_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fsplay_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fsplay_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fsplay_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piotrmurach","download_url":"https://codeload.github.com/piotrmurach/splay_tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piotrmurach%2Fsplay_tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259470951,"owners_count":22862999,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","binarytree","ruby","ruby-gem","splay-trees","splaytree","tree"],"created_at":"2025-06-12T13:09:27.961Z","updated_at":"2025-12-16T20:28:51.398Z","avatar_url":"https://github.com/piotrmurach.png","language":"Ruby","funding_links":["https://github.com/sponsors/piotrmurach"],"categories":[],"sub_categories":[],"readme":"# SplayTree\n\n[![Gem Version](https://badge.fury.io/rb/splay_tree.svg)][gem]\n[![Actions CI](https://github.com/piotrmurach/splay_tree/workflows/CI/badge.svg?branch=master)][gh_actions_ci]\n[![Build status](https://ci.appveyor.com/api/projects/status/smfi5r38ihtn9gom?svg=true)][appveyor]\n[![Maintainability](https://api.codeclimate.com/v1/badges/32d2351f6c349a58d8da/maintainability)][codeclimate]\n[![Coverage Status](https://coveralls.io/repos/github/piotrmurach/splay_tree/badge.svg?branch=master)][coverage]\n[![Inline docs](https://inch-ci.org/github/piotrmurach/splay_tree.svg)][inchpages]\n\n[gem]: https://badge.fury.io/rb/splay_tree\n[gh_actions_ci]: https://github.com/piotrmurach/splay_tree/actions?query=workflow%3ACI\n[appveyor]: https://ci.appveyor.com/project/piotrmurach/splay-tree\n[codeclimate]: https://codeclimate.com/github/piotrmurach/splay_tree/maintainability\n[coverage]: https://coveralls.io/github/piotrmurach/splay_tree\n[inchpages]: https://inch-ci.org/github/piotrmurach/splay_tree\n\n\u003e A self-balancing binary tree optimised for fast access to frequently used nodes. Useful for implementing caches and garbage collection algorithms.\n\n## Features\n\n* Familiar `Hash` like access\n* Easy instantiation with default value\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"splay_tree\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install splay_tree\n\n## Contents\n\n* [1. Usage](#1-usage)\n  * [1.1 insert](#11-insert)\n  * [1.2 fetch](#12-fetch)\n  * [1.3 default](#13-default)\n  * [1.4 delete](#14-delete)\n  * [1.5 empty?](#15-empty)\n  * [1.6 each](#16-each)\n\n## 1. Usage\n\n**SplayTree** operations are similar to that of `Hash`:\n\n```ruby\ntree = SplayTree.new\ntree[:foo] = :bar\n\ntree[:foo]  # =\u003e :bar\ntree.size   # =\u003e 1\n```\n\n### 1.1 insert\n\nTo assign a value to a given key do the following:\n\n```ruby\ntree = SplayTree.new\ntree[:foo] = 1\ntree[:bar] = 2\n```\n\nNote: The inserted key will be subjected to splaying, which means the tree will be rearranged to help with quicker access on subsequent calls.\n\n### 1.2 fetch\n\nTo retrieve a value at a given key do:\n\n```ruby\ntree = SplayTree.new\ntree[:foo]  #  =\u003e nil\n\ntree[:foo] = 1\ntree[:foo]  #  =\u003e 1\n```\n\nNote: Frequently accessed keys will move nearer to the root where they can be accessed more quickly.\n\n### 1.3 default\n\nYou can set a default value for a missing key. This can be done during initialization:\n\n```ruby\ntree = SplayTree.new\ntree.default  # =\u003e UndefinedValue\n\ntree = SplayTree.new(1)\ntree.default  # =\u003e 1\ntree[:foo]    # =\u003e 1\n```\n\nOr using `default` method:\n\n```ruby\ntree = SplayTree.new\ntree.default = 1\n\ntree[:foo] # =\u003e 1\n```\n\nYou can also use a block to set the default value:\n\n```ruby\ntree = SplayTree.new\ntree.default_proc  # =\u003e nil\n\ntree = SplayTree.new { 1 }\ntree.default_proc  # =\u003e #\u003cProc...\u003e\ntree[:foo]         # =\u003e 1\n```\n\n### 1.4 delete\n\nIn order to remove an entry from a splay tree use `delete` method. If a key is not found, the default value is returned, otherwise `nil`.\n\n```ruby\ntree = SplayTree.new\ntree[:foo] = 1\ntree.delete(:foo)  # =\u003e 1\ntree.delete(:bar)  # =\u003e nil\n```\n\n### 1.5 empty?\n\nUse `empty?` to check if a tree contains any elements:\n\n```ruby\ntree = SplayTree.new\ntree.empty?  # =\u003e true\n\ntree[:foo] = 1\ntree.empty?  # =\u003e false\n```\n\n### 1.6 each\n\nUse `each` method to iterate over all tree nodes like so:\n\n```ruby\ntree = SplayTree.new\ntree[:foo] = 1\ntree[:bar] = 2\n\ntree.each { |key, value| puts \"#{key}: #{value}\" }\n# =\u003e\n# bar: 2\n# foo: 1\n```\n\nYou can also use `each_key` and `each_value` to enumerate only keys or values:\n\n```ruby\ntree.each_key { |key| ... }\ntree.each_value { |value| ... }\n```\n\nIf no block is given, an enumerator is returned instead.\n\n## Contributing\n\n1. Fork it ( https://github.com/piotrmurach/splay_tree/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Code of Conduct\n\nEveryone interacting in the SplayTree project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/splay_tree/blob/master/CODE_OF_CONDUCT.md).\n\n## Copyright\n\nCopyright (c) 2014 Piotr Murach. See LICENSE for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fsplay_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiotrmurach%2Fsplay_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiotrmurach%2Fsplay_tree/lists"}