{"id":36975171,"url":"https://github.com/swangoframework/swango-segment_tree","last_synced_at":"2026-01-13T22:03:32.473Z","repository":{"id":57062946,"uuid":"188343800","full_name":"swangoframework/swango-segment_tree","owner":"swangoframework","description":"A simple segment tree writen in PHP. Provide several specific kinds of segment tree.","archived":false,"fork":false,"pushed_at":"2025-04-28T06:24:27.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-06T11:46:31.453Z","etag":null,"topics":["php","segment-tree","version-manager"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/swangoframework.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":"2019-05-24T03:07:51.000Z","updated_at":"2025-04-28T06:23:26.000Z","dependencies_parsed_at":"2022-08-24T10:10:12.644Z","dependency_job_id":null,"html_url":"https://github.com/swangoframework/swango-segment_tree","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/swangoframework/swango-segment_tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swangoframework%2Fswango-segment_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swangoframework%2Fswango-segment_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swangoframework%2Fswango-segment_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swangoframework%2Fswango-segment_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swangoframework","download_url":"https://codeload.github.com/swangoframework/swango-segment_tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swangoframework%2Fswango-segment_tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400857,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["php","segment-tree","version-manager"],"created_at":"2026-01-13T22:03:32.413Z","updated_at":"2026-01-13T22:03:32.467Z","avatar_url":"https://github.com/swangoframework.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swango\\SegmentTree\n\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg?maxAge=2592000)](https://secure.php.net/)\n[![SegmentTree License](https://img.shields.io/hexpm/l/plug.svg?maxAge=2592000)](https://github.com/swlib/archer/blob/master/LICENSE)\n\nEasy segment tree in PHP. Support multi key-value storage. Written without any global variable. Can be used in all kinds of environment.\n### Common segment tree\n```php\n$tree = Swango\\SegmentTree\\Tree\\Common::newTree(0,100000); // Create a tree with scale of 0~100000;\n\n// Set to use \"==\" when comparing values. Two objects of different instances that have same content will be considered equal.\n$tree-\u003euseDoubleEqualSign();\n// Set to use \"===\" when comparing values. Two objects of different instances will be considered not equal no matter their content.\n$tree-\u003euseTripleEqualSign();\n\n// Accept all kinds of values including string, number, null, bool, array, object, etc. \n$tree-\u003esetValue(100, 1000, 'key1', 123);\n$tree-\u003esetValue(20000, 20400, 'key1', null);\n$tree-\u003esetValue(21000, 30000, 'key1', false);\n$tree-\u003esetValue(20005, 21005, 'key1', [1, 2, 3]);\n$tree-\u003esetValue(50000, 60000, 'key2', new \\SplQueue());\n$tree-\u003esetValue(99999, 100000, 'key3', 'some value');\n\n// Get value of certain position.\nvar_dump($tree-\u003egetValue(20006, 'key1'));\n\n// Delete value of between certain positions.\n$tree-\u003edelValue(30000, 100000, 'key1');\n\n// Throws exception when value not found.\nvar_dump($tree-\u003egetValue(70000, 'key1'));\n\n// Get segment arrays.\nvar_dump($tree-\u003egetSegmentsOfGivenKey('key1'));\nvar_dump($tree-\u003egetSegmentsOfGivenKeyAndValue('key1', [1, 2, 3]));\n\n// Remove all redundant nodes in the tree to reduce memory cost.\n$tree-\u003eoptimize();\n\n// Clear all values and child nodes and make it a new tree.\n$tree-\u003eclear();\n```\n### Version compressed segment tree\n```php\n$tree = Swango\\SegmentTree\\Tree\\Version::newTree(\n    '1.0.0', '1.0.1', '1.0.2', '1.0.3', '1.1.0', '1.4.1', '2.0.0', '2.0.1-RC1', '3.0.0'\n); // Create a tree with versions. These versions will be sorted using version_compare() and remove all duplicated\n\n// All methods are similar with Common tree.\n$tree-\u003esetValue('1.0.2', '2.0.0', 'key1', true);\nvar_dump($tree-\u003egetValue('1.1.0'));\n```\n### Date compressed segment tree\n```php\n$tree = Swango\\SegmentTree\\Tree\\Date::newTree(\n    '2020-09-25', '2020-12-12'\n); // Create a tree with dates. \n\n// All methods are similar with Common tree.\n$tree-\u003esetValue('2020-09-29', '2020-11-11', 'key1', true);\nvar_dump($tree-\u003egetValue('2020-11-01'));\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswangoframework%2Fswango-segment_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswangoframework%2Fswango-segment_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswangoframework%2Fswango-segment_tree/lists"}