{"id":16126974,"url":"https://github.com/mikolalysenko/segment-tree","last_synced_at":"2025-03-18T13:32:09.666Z","repository":{"id":8905309,"uuid":"10628860","full_name":"mikolalysenko/segment-tree","owner":"mikolalysenko","description":"Basic segment tree data structure","archived":false,"fork":false,"pushed_at":"2013-07-18T01:32:44.000Z","size":132,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T20:51:16.740Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/mikolalysenko.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":"2013-06-11T19:18:01.000Z","updated_at":"2021-06-14T03:35:23.000Z","dependencies_parsed_at":"2022-08-29T19:01:37.173Z","dependency_job_id":null,"html_url":"https://github.com/mikolalysenko/segment-tree","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/mikolalysenko%2Fsegment-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fsegment-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fsegment-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Fsegment-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikolalysenko","download_url":"https://codeload.github.com/mikolalysenko/segment-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244231586,"owners_count":20419969,"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-09T21:41:28.090Z","updated_at":"2025-03-18T13:32:09.392Z","avatar_url":"https://github.com/mikolalysenko.png","language":"JavaScript","readme":"segment-tree\n============\nA minimal implementation of a segment tree for storing run-length encoded arrays with updates.\n\n## Example\n\n```javascript\nvar tree = require(\"segment-tree\").zeros(10)\n\ntree.set(1, 1)\ntree.set(2, 1)\n\nconsole.log(tree.length)\nconsole.log(tree.pointers)\nconsole.log(tree.values)\n```\n\n## Install\n\n    npm install segment-tree\n\n## API\n\n```javascript\nvar SegmentTree = require(\"segment-tree\")\n```\n\n### `SegmentTree(length, pointers, values)`\nSegmentTree constructor\n\n* `length` is the size of the segment tree\n* `pointers` is a sorted list of pointers\n* `values` is a sorted list of values\n\nThe segment tree object has the same properties as the arguments.\n\n### `SegmentTree.proto.get(index)`\nRetrieves the value `index`\n\n* `index` is the coordinate of the value to retrieve\n\n**Returns** The value at `index`\n\n### `SegmentTree.proto.set(index, v)`\nSets the value at `index` to `v`\n\n* `index` is the index to update\n* `v` is the new value\n\n**Returns** `v`\n\n### `SegmentTree.proto.slice(begin[, end])`\nReturns a slice of the segment tree.  Same semantics as [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)\n\n* `begin` is the start of the interval\n* `end` is the end of the interval\n\n**Returns** A 1-level deep slice of the segment tree\n\n### `SegmentTree.proto.toArray([array])`\nUnpacks the segment tree into an array\n\n* `array` gets the output.  If not specified a new array is allocated\n\n**Returns** `array`\n\n### `SegmentTree.zeros(size)`\nCreate an empty segment tree\n\n* `size` is the size of the new segment tree\n\n**Returns** A new segment tree\n\n### `SegmentTree.fromArray(array)`\nEncodes an array into a segment tree\n\n* `array` is the array to encode\n\n**Returns** A new segment tree encoding `array`\n\n### `SegmentTree.fromGenericArray(array)`\nEncodes an array into a segment tree, except instead of using [] to access the array it uses .get()\n\n* `array` is the array to encode\n\n**Returns** A new segment tree encoding `array`\n\n## Credits\n(c) 2013 Mikola Lysenko. MIT License","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Fsegment-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikolalysenko%2Fsegment-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Fsegment-tree/lists"}