{"id":36604881,"url":"https://github.com/geniot/indexed-tree-map","last_synced_at":"2026-01-12T08:43:50.712Z","repository":{"id":34941604,"uuid":"39013947","full_name":"geniot/indexed-tree-map","owner":"geniot","description":"Enhanced java.util.TreeSet with get element by index, get index of an element. The implementation is based on node weights.","archived":false,"fork":false,"pushed_at":"2022-01-07T11:09:59.000Z","size":478,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-28T06:11:17.719Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geniot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-13T13:33:52.000Z","updated_at":"2024-07-16T01:20:52.000Z","dependencies_parsed_at":"2022-09-26T22:11:20.407Z","dependency_job_id":null,"html_url":"https://github.com/geniot/indexed-tree-map","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/geniot/indexed-tree-map","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniot%2Findexed-tree-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniot%2Findexed-tree-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniot%2Findexed-tree-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniot%2Findexed-tree-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geniot","download_url":"https://codeload.github.com/geniot/indexed-tree-map/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniot%2Findexed-tree-map/sbom","scorecard":{"id":422527,"data":{"date":"2025-08-11","repo":{"name":"github.com/geniot/indexed-tree-map","commit":"db92079c8c1ef799e859a4e23c9ff350d612c2fe"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/25 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T01:34:30.431Z","repository_id":34941604,"created_at":"2025-08-19T01:34:30.431Z","updated_at":"2025-08-19T01:34:30.431Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2026-01-12T08:43:50.093Z","updated_at":"2026-01-12T08:43:50.706Z","avatar_url":"https://github.com/geniot.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# indexed-tree-map\n\nJDK's TreeMap / TreeSet implementation is based on the [red-black tree](https://en.wikipedia.org/wiki/Red%E2%80%93black_tree) algorithm.\n\n**indexed-tree-map** is an enhanced version of this algorithm.\n\n# API\n    public interface IndexedNavigableSet\u003cE\u003e extends NavigableSet\u003cE\u003e {\n        E exact(int index);\n        int entryIndex(E e);\n    }\n\n    public interface IndexedNavigableMap\u003cK, V\u003e extends NavigableMap\u003cK, V\u003e {\n        K exactKey(int index);\n        Entry\u003cK, V\u003e exactEntry(int index);\n        int keyIndex(K k);\n    }\n    \nOr simply use [IndexedTreeSet.java](https://github.com/geniot/indexed-tree-map/blob/master/src/main/java/io/github/geniot/indexedtreemap/IndexedTreeSet.java) and [IndexedTreeMap.java](https://github.com/geniot/indexed-tree-map/blob/master/src/main/java/io/github/geniot/indexedtreemap/IndexedTreeMap.java) to avoid the interface complexity.\n\n# How to use / install\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003eio.github.geniot\u003c/groupId\u003e\n            \u003cartifactId\u003eindexedtreemap\u003c/artifactId\u003e\n            \u003cversion\u003e1.1\u003c/version\u003e\n        \u003c/dependency\u003e\n\n# Implementation\n\nI copied SDK's code and added __*int weight*__ field to each node of the tree. \nIt contains the number of elements below the node plus 1 (self).\n\nEvery time there is a change in the tree, weight is updated for changed nodes like this:\n\n        void updateWeight(int delta) {\n            weight += delta;\n            Entry\u003cK, V\u003e p = parent;\n            while (p != null) {\n                p.weight += delta;\n                p = p.parent;\n            }\n        }\n\nWe go from updated node to the root.\n\nLet's take a look at the following tree. I added weight values to each node.\n\n![Red-black tree with weights](screenshots/Red-black_tree_example.svg.png)\n\nSee how the weight of our root node is also the size of the tree (total number of elements).\n\nSo how do you get the index of an element in the tree using weights?\n\nE.g. what is the index value of 11 in the tree above?\n\nLet's take a look at the following method:\n\n        // e is our element - 11\n        int index = 0;\n        int cmp;\n        index += getWeight(e.left); // 0\n        Entry\u003cK, V\u003e p = e.parent;\n        Comparator\u003c? super K\u003e cpr = comparator;\n\n        while (p != null) {\n                cmp = cpr.compare(key, p.key);\n                if (cmp \u003e 0) {\n                    index += getWeight(p.left) + 1;\n                }\n                p = p.parent;\n        }\n\ne.left + parent.left + 1 + (parent.parent.left + 1...) = 3 ! \n\nparent:8, parent.left:1, parent.left.weight=2\n\nIndex starts from 0. 11 is 4th element, so index = 3\n\n\nIndeed. If we draw vertical lines through centers of each node \nwe can see that lines reveal the sorted order of our tree elements.\n\n**So to get the index of an element we need to sum up all weights to the left of our node.**\n\nIf you are not sure about this check out the test:\n\nhttps://github.com/geniot/indexed-tree-map/blob/master/src/test/java/io/github/geniot/indexedtreemap/IndexedTreeSetTest.java\n\n# License\nThe same as of JDK. I copied the implementation and enhanced it. \nI don't think I have the right to change the license.\n\nhttps://www.oracle.com/downloads/licenses/javase-license1.html\n\n# Links\nPopular questions on Stackoverflow:\n\nHow to return the k-th element in TreeSet in Java?\nhttps://stackoverflow.com/questions/8856815/how-to-return-the-k-th-element-in-treeset-in-java\n\nFind element position in a Java TreeMap\nhttps://stackoverflow.com/questions/8502542/find-element-position-in-a-java-treemap\n\nWhy is there no SortedList in Java?\nhttps://stackoverflow.com/questions/8725387/why-is-there-no-sortedlist-in-java\n\nAny implementation of Ordered Set in Java?\nhttps://stackoverflow.com/questions/8712469/any-implementation-of-ordered-set-in-java\n\nWhy doesn't java.util.Set have get(int index)?\nhttps://stackoverflow.com/questions/769731/why-doesnt-java-util-set-have-getint-index\n\nHow to find the index of an element in a TreeSet?\nhttps://stackoverflow.com/questions/7911621/how-to-find-the-index-of-an-element-in-a-treeset\n\nWhat is the most efficient way to access particular elements in a SortedSet?\nhttps://stackoverflow.com/questions/5334020/what-is-the-most-efficient-way-to-access-particular-elements-in-a-sortedset\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeniot%2Findexed-tree-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeniot%2Findexed-tree-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeniot%2Findexed-tree-map/lists"}