{"id":22787670,"url":"https://github.com/bigspider/segtree","last_synced_at":"2025-10-20T09:34:15.536Z","repository":{"id":131341179,"uuid":"58004911","full_name":"bigspider/segtree","owner":"bigspider","description":"A simple implementation of a segment tree for range sums.","archived":false,"fork":false,"pushed_at":"2016-05-13T07:54:27.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-05T17:45:42.207Z","etag":null,"topics":["complexity","range-query","range-sum","segment-tree"],"latest_commit_sha":null,"homepage":null,"language":"Python","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/bigspider.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-03T22:14:09.000Z","updated_at":"2018-02-10T23:21:03.000Z","dependencies_parsed_at":"2023-03-22T22:16:03.583Z","dependency_job_id":null,"html_url":"https://github.com/bigspider/segtree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigspider%2Fsegtree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigspider%2Fsegtree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigspider%2Fsegtree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bigspider%2Fsegtree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bigspider","download_url":"https://codeload.github.com/bigspider/segtree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246342993,"owners_count":20761947,"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":["complexity","range-query","range-sum","segment-tree"],"created_at":"2024-12-12T00:59:50.656Z","updated_at":"2025-10-20T09:34:10.514Z","avatar_url":"https://github.com/bigspider.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# segtree\nA simple implementation of a fixed-length segment tree for range sums. See for example http://www.geeksforgeeks.org/segment-tree-set-1-sum-of-given-range/.\n\nNOTE: the name \"segment tree\" is used in literature for different structures used in computational geometry. Here we refer to a data structure that provides random access to an array, augmented with efficient range queries.\n\nThe SumSegmentTree class stores an array A of size n, providing access with three methods:\n\n- `get(i)`: returns the element at index i\n- `set(i, x)`: set the element at index i to x\n- `sum(i, j)`: return the sum of all the elements between indexes i and j (inclusive)\n\nThe complexity of `get` is O(1); the complexity of `set` and `sum` is O(log n)\n\nWith easy modifications, the structure can be easily adapted to other kinds of range queries for example: minimum, maximum, product, and so on. More generally, range queries for any associative binary operator can be implemented in O(log n).\n\n# Usage example\n```\nIn [1]: from segtree import SumSegmentTree\n\nIn [2]: T = SumSegmentTree([1,5,3,2,-2,4,0,12])\n\nIn [3]: T.get_data()\nOut[3]: [1, 5, 3, 2, -2, 4, 0, 12]\n\nIn [4]: T.get(1)\nOut[4]: 5\n\nIn [5]: T.sum(2, 4)\nOut[5]: 3\n\nIn [6]: T.set(3, 10)\n\nIn [7]: T.sum(2, 4)\nOut[7]: 11\n\nIn [8]: T.get_data()\nOut[8]: [1, 5, 3, 10, -2, 4, 0, 12]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigspider%2Fsegtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbigspider%2Fsegtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbigspider%2Fsegtree/lists"}