{"id":18485308,"url":"https://github.com/arturopala/scala-tree","last_synced_at":"2025-10-18T20:13:24.945Z","repository":{"id":152785405,"uuid":"247766449","full_name":"arturopala/scala-tree","owner":"arturopala","description":"General purpose, covariant, immutable, low overhead, efficient, monadic tree-like data structure with comprehensive API.","archived":false,"fork":false,"pushed_at":"2020-09-15T08:22:11.000Z","size":3992,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-12T01:04:29.678Z","etag":null,"topics":["data-structures","library","scala","tree","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/arturopala.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":"2020-03-16T16:38:12.000Z","updated_at":"2022-12-17T06:10:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"6e5ea75d-4dea-446c-8a41-a0425f78cd89","html_url":"https://github.com/arturopala/scala-tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arturopala/scala-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturopala%2Fscala-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturopala%2Fscala-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturopala%2Fscala-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturopala%2Fscala-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arturopala","download_url":"https://codeload.github.com/arturopala/scala-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturopala%2Fscala-tree/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259374729,"owners_count":22847855,"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":["data-structures","library","scala","tree","tree-structure"],"created_at":"2024-11-06T12:44:47.569Z","updated_at":"2025-10-18T20:13:24.836Z","avatar_url":"https://github.com/arturopala.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Build](https://github.com/arturopala/scala-tree/workflows/Build/badge.svg)\n\nTree\\[+T]\n===\n\nThis is a micro-library for Scala providing \na general-purpose, covariant, immutable, low overhead, \nefficient, monadic tree-like data structure with comprehensive API.\n\nMotivation\n---\n\nA Tree is one of the most versatile data structure concepts with numerous flavours, applications and implementations.\n\nWhile the concept is dead simple, practical implementation details of immutable tree pose significant challenges, e.g.\n\n- traversing and transforming the tree using stack-safe algorithms\n- using reasonable amount of memory resources to represent large trees\n- keeping children distinct when transforming or merging trees\n- supporting numerous use cases in the balanced API\n\nDesign\n---\n\nConceptually, apart from an empty, each node of the tree has:\n- a head value\n- a collection of subtrees (children).\n\nInternally, there are three main implementations of the `Tree`:\n\n- `Tree.empty` an empty tree singleton, i.e. `Tree[Nothing]`,\n- `Tree.NodeTree` a classic, deeply-nested hierarchy of immutable nodes (inflated tree),\n- `Tree.ArrayTree` the tree encoded in an ultra-compact flat format of twin linear arrays of structure and values (deflated tree).\n\nThe reason for having an inflated and deflated variants of the tree\nis such that each one exhibits different performance and memory\nconsumption characteristics, making it possible to experiment and optimize\nfor individual targets while facing the same API. \nFurther optimization is possible with using `MutableTree` for series of transformations.\n\nDistinct and Lax operations\n---\n\nBy the design choice, every node of the tree can have duplicated children values,\nalthough the default API methods preserve the uniqueness of modified elements.\n\nIf the data is distinct by itself, or you don't care about uniqueness, there is \na matching set of `LaxTree` API operations supplied as extensions methods in `LaxTreeOps`.\n\nLax operations are more performant as they do not have to perform additional checks and merges.\n\nTo enable lax operations, just `import com.github.arturopala.tree.LaxTreeOps._`.\n\nMutableTree\\[+T]\n---\n\n`MutableTree` is not a `Tree` per se, but a special `TreeLike` type to handle series of heavy operations on a tree without \nhaving to pay a price of intermediate immutable representations. \n\nThis works the best by using the following scenario:\n\n- call `.mutable` on a `Tree` to access mutable copy\n- make a series of operations on `MutableTree`\n- call `.immutable` to get back immutable `Tree`\n\nAs both `.mutable` and `.immutable` methods have to make a copy of a Tree representation,\nit saves time and resources only for two or more operations in a row, comparing with a `Tree`.\n\nWarning: Iterating over subtrees has much worse performance on `MutableTree` because each subtree must be a copy, \nprefer using light iteration available on the `Tree` instead.\n\n\nDependencies\n--- \n\nDepends on:\n\n- a standard built-in Scala library,\n- [`com.github.arturopala.bufferandslice`](https://github.com/arturopala/buffer-and-slice).\n\nCross-compiles to Scala versions `2.13.3`, `2.12.11`, `2.11.12`, and Dotty `0.27.0-RC1`.\n\nAPI\n---\n\nProvided API allows for a rich set of queries and operations on the tree. \n\nFor more details, see [Scaladoc](https://arturopala.github.io/scala-tree/latest/api/com/github/arturopala/tree/Tree.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturopala%2Fscala-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farturopala%2Fscala-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturopala%2Fscala-tree/lists"}