{"id":15297579,"url":"https://github.com/cloventt/intervaltree","last_synced_at":"2025-10-07T10:31:04.427Z","repository":{"id":57737032,"uuid":"86296627","full_name":"cloventt/intervaltree","owner":"cloventt","description":"Interval Tree implementation in Java","archived":false,"fork":true,"pushed_at":"2017-04-03T23:18:54.000Z","size":33,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-26T01:50:30.324Z","etag":null,"topics":["algorithm","algorithms","data-structure","data-structures","datastructures","interval","interval-tree","intervals","java","java-8","java8","range"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"kevinjdolan/intervaltree","license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloventt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-27T05:57:07.000Z","updated_at":"2025-06-30T21:08:33.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cloventt/intervaltree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cloventt/intervaltree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloventt%2Fintervaltree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloventt%2Fintervaltree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloventt%2Fintervaltree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloventt%2Fintervaltree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloventt","download_url":"https://codeload.github.com/cloventt/intervaltree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloventt%2Fintervaltree/sbom","scorecard":{"id":293450,"data":{"date":"2025-08-11","repo":{"name":"github.com/cloventt/intervaltree","commit":"eb81fbf1af60ed75ff5b97829e898f3d50d505d2"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"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":"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":"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":"Code-Review","score":0,"reason":"Found 0/15 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":"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":"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":"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":"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":"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":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE.txt:0"],"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":"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"}},{"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"}}]},"last_synced_at":"2025-08-17T18:53:41.103Z","repository_id":57737032,"created_at":"2025-08-17T18:53:41.103Z","updated_at":"2025-08-17T18:53:41.103Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278761347,"owners_count":26041370,"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","status":"online","status_checked_at":"2025-10-07T02:00:06.786Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["algorithm","algorithms","data-structure","data-structures","datastructures","interval","interval-tree","intervals","java","java-8","java8","range"],"created_at":"2024-09-30T19:18:22.016Z","updated_at":"2025-10-07T10:31:04.107Z","avatar_url":"https://github.com/cloventt.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Interval Tree Implementation in Java\n====================================\n\n## 2017 Update\n\nThis project was initially created by Kevin Dolan in 2010, and has been forked and updated by David Palmer in 2017. \n\nI found myself needing a quick way to find the country code of an IP, given a list of IP blocks and associated country codes. Kevin's project suited this need perfectly, so I adapted it. I wanted to support IPv4 and IPv6 however, which presented an annoying inefficiency. Supporting IPv6 meant I needed to move from using `long` like Kevin to `BigInteger` (because IPv6 is represented by 128 bits). This worked fine, but because I'd hardcoded `BigInteger` in to the class and I was also using it for IPv4, there was massive memory overhead (an unsigned `Integer` would be heaps more memory efficient for IPv4).\n\nThe solution was to make the `IntervalTree` class accept any generic `Number` subclass for the intervals, and on the off-chance this is useful to anyone else I thought I'd throw it back up online. Plus the old library was written for Java 6, and I'm using Java 8.\n\nMajor improvements include:\n * use of generics so you can use any* arbitrary number type in your intervals (just specify a number type when you create the tree)\n * updated to use Java 1.8 (not tested on previous versions)\n * tests and maven integration\n \nMajor drawbacks include:\n * no support for primitives (added memory overhead)\n \n(\\*Disclaimer: I say any `Number`, but specifically it must also satisfy `Comparable\u003cN super Number\u003e`, which is most of them luckily)\n\n## Original Disclaimer\n\nThis project is no longer maintained or supported. If you find this useful and would like to contribute or submit a pull request, I will just make you a contributor.\n\nI wrote this back in 2010, when I was a Sophomore in Undergrad. I have not used it or updated it since then. I was an _okay_ programmer back then, but I've learned a lot since then so no guarantees on quality here. I'm dumping this here because I am taking down my old blog and a lot of people would download this from there.\n\nReleased under the [WTFPL](http://en.wikipedia.org/wiki/WTFPL).\n\n## Original release notes from 2010\n\nIn a recent Java project, I found myself needing to store several intervals of time which I could access readily and efficiently.  I only needed to build the tree once, so a static data structure would work fine, but queries needed to be as efficient as possible.\n\nI found a data structure that accomplishes just this, an interval tree.\n\nIt’s a simple enough data structure, but I couldn’t find any Java implementations for it online.\n\nI then went to coding the data structure at the airport last week, and just finished unit testing it to convince myself everything was good to go.  I’m making it available if you are interested, because it’s really a waste of time to hand-code a well-known data structure.\n\nIt uses generic typing for the data object, but requires all the intervals to be expressed in terms of longs.  There are probably some obvious problems with catching programmer error.  For instance, if you search for an interval, but reverse start and end, I don’t know what will happen, nor do I care.\n\nIt is a static data structure, meaning it must be rebuilt anytime a change is made to the underlying data.  Rebuilds happen automatically if you try to make a query and it is out-of-sync, but you can build manually by calling .build() if you want to, and you can find out if it is currently in-sync by calling .inSync().\n\n## Usage\nThe tree makes no effort to check that you are not mixing data types, so you should _always_ let the compiler know what you plan to store in it. Mixing data types for ranges is not supported, and may cause awkward `ClassCastException` errors, so proceed at your own risk.\n\nYou must also supply a constructor for your chosen Number sub-type that represents zero. This is a side-effect of using generics and type erasure. For most number types you can just pass a lambda that creates a new zero-value object into the constructor of the Interval Tree:\n\n```\nnew IntervalTree\u003c\u003e( () -\u003e Integer(0) );\nnew IntervalTree\u003c\u003e( () -\u003e Double(0.0) );\nnew IntervalTree\u003c\u003e( () -\u003e BigInteger.valueOf(0) );\nnew IntervalTree\u003c\u003e( () -\u003e BigDecimal.valueOf(0.0) );\n...etc...\n```\n\nTo create an interval tree using ints for ranges and strings as data, simply, do this:\n\n```\nIntervalTree\u003cInteger, String\u003e tree = new IntervalTree\u003c\u003e(() -\u003e 0);\n```\n\nThen you can add an interval like this:\n\n```\ntree.addInterval(5, 10, \"This is the range of 5 to 10 inclusive\");\n```\n\nNow you can query the tree like this:\n\n```\ntree.get(7);\n```\n\nThis will return a `List` of data like this:\n\n```\n[\"This is the range of 5 to 10 inclusive\"]\n```\n\nIf you have overlapping ranges then `get()` will return multiple data values in the list, one for every range your query intersects. Its up to you to handle this list, including any the case where your value isn't in a range in the tree.\n\nA valid range is any two different numbers, where the first number comes before the second on the number line.\n\nMore usage examples can be found in the `src/test/java/intervalTree` directory.\n\n## Deployment\nIf you want the .jar and you have maven, simply run:\n\n```\nmvn install\n```\n\nfrom the project root. \n\nIt's also hosted in the Maven Central Repo, so you can include it in your Maven project by adding\n\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.cloventt\u003c/groupId\u003e\n    \u003cartifactId\u003eintervalTree\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.3\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nto your `pom.xml`. Then you can import it just like anything else:\n\n```\nimport intervalTree.IntervalTree;\n```\n\n## License\nFor the updated version I'm relicensing this to Apache 2.0. The original WTFPL license is great but some organisations may not permit the use of software with an untested license like that.\n\nCopyright 2017 David Palmer\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloventt%2Fintervaltree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloventt%2Fintervaltree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloventt%2Fintervaltree/lists"}