{"id":17267996,"url":"https://github.com/arjunsk/intervalst","last_synced_at":"2025-03-26T11:15:07.337Z","repository":{"id":202160930,"uuid":"703347808","full_name":"arjunsk/intervalst","owner":"arjunsk","description":"Golang Interval Search Tree extracted from etcd","archived":false,"fork":false,"pushed_at":"2023-10-23T20:06:06.000Z","size":1940,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T12:29:02.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arjunsk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-11T04:41:16.000Z","updated_at":"2024-03-18T16:51:40.000Z","dependencies_parsed_at":"2023-10-23T21:25:10.073Z","dependency_job_id":null,"html_url":"https://github.com/arjunsk/intervalst","commit_stats":null,"previous_names":["arjunsk/intervalst"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunsk%2Fintervalst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunsk%2Fintervalst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunsk%2Fintervalst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arjunsk%2Fintervalst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arjunsk","download_url":"https://codeload.github.com/arjunsk/intervalst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245641436,"owners_count":20648644,"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":[],"created_at":"2024-10-15T08:12:11.412Z","updated_at":"2025-03-26T11:15:07.313Z","avatar_url":"https://github.com/arjunsk.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Interval Search Tree\n[![Go Reference](https://pkg.go.dev/badge/github.com/arjunsk/intervalst/intervalst.svg)](https://pkg.go.dev/github.com/arjunsk/intervalst)\n[![Go Report Card](https://goreportcard.com/badge/github.com/arjunsk/intervalst)](https://goreportcard.com/report/github.com/arjunsk/intervalst)\n[![Codecov](https://codecov.io/gh/arjunsk/intervalst/branch/master/graph/badge.svg)](https://codecov.io/gh/arjunsk/intervalst)\n\nAn [interval tree](https://en.wikipedia.org/wiki/Interval_tree) is a balanced binary search tree designed to efficiently\nstore and query intervals. It allows for queries of the form \"find all intervals that overlap with a\ngiven interval\" or \"find an interval that contains a specific point.\"\n\nThis library is extracted from [etcd](https://github.com/etcd-io/etcd/tree/main)\n\n## Installing\n\n```sh\n$ go get github.com/arjunsk/intervalst\n```\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"github.com/arjunsk/intervalst\"\n)\n\nfunc main() {\n\tist := intervalst.NewIntervalTree()\n\tist.Insert(intervalst.NewInt64Interval(1, 3), \"user1\")\n\tist.Insert(intervalst.NewInt64Interval(9, 13), \"user2\")\n\tist.Insert(intervalst.NewInt64Interval(7, 20), \"user3\")\n\n\t// Output :\n\t// given interval {Begin:4 End:8} overlaps with these existing intervals\n\t// interval_st interval: \u0026{Ivl:{Begin:7 End:20} Val:user3}\n\tfindIntervalIntersections(ist, intervalst.NewInt64Interval(4, 8))\n\n\t// Output :\n\t// given point {Begin:10 End:11} overlaps with these existing intervals\n\t// interval_st interval: \u0026{Ivl:{Begin:7 End:20} Val:user3}\n\t// interval_st interval: \u0026{Ivl:{Begin:9 End:13} Val:user2}\n\tfindPointIntersections(ist, intervalst.NewInt64Point(10))\n\n\t// Output : 3\n\tfmt.Println(ist.Len())\n\n\t// Output:\n\t// given interval {Begin:4 End:8} does not overlap with any existing intervals\n\tist.Delete(intervalst.NewInt64Interval(7, 20))\n\tfindIntervalIntersections(ist, intervalst.NewInt64Interval(4, 8))\n\n}\n\nfunc findPointIntersections(ist intervalst.IntervalTree, newPoint intervalst.Interval) {\n\n\tif ist.Intersects(newPoint) {\n\t\tfmt.Printf(\"given point %+v overlaps with these existing intervals \\n\", newPoint)\n\n\t\trs := ist.Stab(newPoint)\n\t\tfor _, v := range rs {\n\t\t\tfmt.Printf(\"interval_st interval: %+v\\n\", v)\n\t\t}\n\t\tfmt.Println()\n\t}\n}\n\nfunc findIntervalIntersections(ist intervalst.IntervalTree, newInterval intervalst.Interval) {\n\tif ist.Intersects(newInterval) {\n\t\tfmt.Printf(\"given interval %+v overlaps with these existing intervals \\n\", newInterval)\n\t\trs := ist.Stab(newInterval)\n\t\tfor _, v := range rs {\n\t\t\tfmt.Printf(\"interval_st interval: %+v\\n\", v)\n\t\t}\n\t\tfmt.Println()\n\t} else {\n\t\tfmt.Printf(\"given interval %+v does not overlap with any existing intervals \\n\", newInterval)\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunsk%2Fintervalst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farjunsk%2Fintervalst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farjunsk%2Fintervalst/lists"}