{"id":15968652,"url":"https://github.com/dmathieu/itree","last_synced_at":"2026-05-14T06:34:28.546Z","repository":{"id":57560133,"uuid":"325352209","full_name":"dmathieu/itree","owner":"dmathieu","description":"An Interval Tree Implementation written in Go","archived":false,"fork":false,"pushed_at":"2021-03-02T09:26:45.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T13:22:19.128Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/dmathieu.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}},"created_at":"2020-12-29T17:52:37.000Z","updated_at":"2023-11-12T15:28:09.000Z","dependencies_parsed_at":"2022-09-04T13:00:32.247Z","dependency_job_id":null,"html_url":"https://github.com/dmathieu/itree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dmathieu/itree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmathieu%2Fitree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmathieu%2Fitree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmathieu%2Fitree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmathieu%2Fitree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmathieu","download_url":"https://codeload.github.com/dmathieu/itree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmathieu%2Fitree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33013274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"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":[],"created_at":"2024-10-07T19:03:08.338Z","updated_at":"2026-05-14T06:34:28.522Z","avatar_url":"https://github.com/dmathieu.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iTree\n[![Go Reference](https://pkg.go.dev/badge/github.com/dmathieu/itree.svg)](https://pkg.go.dev/github.com/dmathieu/itree)\n[![CircleCI](https://circleci.com/gh/dmathieu/itree.svg?style=svg)](https://app.circleci.com/pipelines/github/dmathieu/itree)\n\nAn Interval Tree Implementation written in Go\n\n## Usage\n\n## With int64 values\n\n```go\nintervals := []itree.Interval{\n  itree.Interval{Start: 1, End: 3},\n  itree.Interval{Start: 2, End: 5},\n}\n\ntree, err := itree.NewTree(intervals)\ntree.Contains(context.Background(), 3)\n```\n\n## With times\n\n```go\nnow := time.Now()\nintervals := []time.Time{\n  // The first value is the beginning of the interval, the second is the end\n  []time.Time{now.Add(-2 * time.Minute), now.Add(-1 * time.Minute)},\n  []time.Time{now.Add(-2 * time.Hour), now.Add(-1 * time.Hour)},\n}\n\ntree, err := itree.NewTimesTree(intervals)\ntree.Contains(now)\n```\n\n## With IP Networks\n\n```go\n_, ipnet, _ := net.ParseCIDR(\"127.0.0.1/32\")\n\nintervals := []*net.IPNet{ipnet}\ntree, err := itree.NewIPNetTree(intervals)\n\ntree.Contains(net.ParseIP(\"8.8.8.8\"))\n```\n\n## Graphviz Generation\n\nAfter generating a tree, you can generate a graphviz representation of it.\n\n```go\ntree := // Generate your tree\ngraph, err := tree.Graphviz(itree.GraphvizOptions{})\nif err != nil {\n  log.Fatal(err)\n}\n```\n\nThe graphviz generation creates the graph using\n[go-graphviz](https://github.com/goccy/go-graphviz), and returns a\n`*cgraph.Graph`. So you can use that object to export the data to any format\nsupported by the library.\n\n# Benchmarks\n\nYou can run the internal benchmarks using  `go test -bench=. ./...`\nHere is the output from a 2019 MacBook Pro\n\n```\nBenchmarkBuildTree\nBenchmarkBuildTree-12              10000            990813 ns/op\nBenchmarkTreeContains\nBenchmarkTreeContains-12         2967738               469 ns/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmathieu%2Fitree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmathieu%2Fitree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmathieu%2Fitree/lists"}