{"id":32151741,"url":"https://github.com/emma-k-alexandra/rtree","last_synced_at":"2025-10-21T10:51:59.923Z","repository":{"id":63909344,"uuid":"216895790","full_name":"emma-k-alexandra/RTree","owner":"emma-k-alexandra","description":"An on-disk, Codable R*-Tree for Swift","archived":false,"fork":false,"pushed_at":"2022-01-29T00:54:28.000Z","size":108,"stargazers_count":24,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-05T11:45:13.511Z","etag":null,"topics":["codable","data-structures","json","mit-license","r-tree","search-trees","swift-package-manager","trees","xcode"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/emma-k-alexandra.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-10-22T19:39:50.000Z","updated_at":"2025-09-25T18:12:14.000Z","dependencies_parsed_at":"2022-11-28T22:58:44.769Z","dependency_job_id":null,"html_url":"https://github.com/emma-k-alexandra/RTree","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/emma-k-alexandra/RTree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emma-k-alexandra%2FRTree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emma-k-alexandra%2FRTree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emma-k-alexandra%2FRTree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emma-k-alexandra%2FRTree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emma-k-alexandra","download_url":"https://codeload.github.com/emma-k-alexandra/RTree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emma-k-alexandra%2FRTree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280248569,"owners_count":26297925,"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","status":"online","status_checked_at":"2025-10-21T02:00:06.614Z","response_time":58,"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":["codable","data-structures","json","mit-license","r-tree","search-trees","swift-package-manager","trees","xcode"],"created_at":"2025-10-21T10:51:55.700Z","updated_at":"2025-10-21T10:51:59.906Z","avatar_url":"https://github.com/emma-k-alexandra.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RTree\n\nRTree is an on-disk, [`Codable`](https://developer.apple.com/documentation/foundation/archives_and_serialization/encoding_and_decoding_custom_types) R\\*-Tree for searching.\n\nRTree is a port of the Rust crate [`Spade`](https://crates.io/crates/spade)'s N-Dimentional R\\*-Tree, modified to store the tree on disk rather than in memory. It only can perform inserts and nearest neighbor queries.\n\n## Contents\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Disclaimer \u0026 Warnings](#disclaimer--warnings)\n- [Design](#design)\n- [Usage](#usage)\n    - [Getting Started](#getting-started)\n- [Dependencies](#dependencies)\n- [Contributing](#contributing)\n- [Contact](#contact)\n- [Acknowledgements](#acknowledgements)\n- [License](#license)\n\n## Requirements\n- Swift 5.1+\n- iOS 13, watchOS 6, macOS 10.15, tvOS 15\n\n## Installation\n\n### Swift Package Manager\n```swift\ndependencies: [\n    .package(\n        name: \"RTree\",\n        url: \"https://github.com/emma-k-alexandra/RTree.git\",\n        from: \"2.2.0\"\n    )\n]\n```\n\n## Disclaimer \u0026 Warnings\nRTree performs nearest neighbor searches at the expected speed of a R*-Tree. RTree uses far more space than expected on disk, and inserts are extemely inefficient. RTree does not currently support deletion or updating of records. \n\n## Design\nThis R\\*-Tree is designed to use exclusively Swift, and provide a general interface for doing nearest neighbor queries on N-dimensional objects.\n\nExpect to a implement your own `SpatialObject`-implementing structure and `PointN`-implementing vector type in order to use RTree. For an example, see `RTreeTests.swift` or [Usage](#usage)\n\n## Usage \n\n### Getting started\nFirst, you need a SpatialObject-implementing type to store in the R-Tree. For demonstration purposes, I will implement a 2-dimensional vector and SpatialObject that will store a custom field.\n\n2-dimensional vector:\n```swift\nimport RTree\n\nstruct Point2D: PointN {\n    typealias Scalar = Double\n    \n    var x: Scalar\n    var y: Scalar\n    \n    init(x: Scalar, y: Scalar) {\n        self.x = x\n        self.y = y\n        \n    }\n    \n    func dimensions() -\u003e Int {\n        2\n        \n    }\n    \n    static func from(value: Double) -\u003e Self {\n        Point2D(x: value, y: value)\n        \n    }\n    \n    subscript(index: Int) -\u003e Scalar {\n        get {\n            if index == 0 {\n                return self.x\n                \n            } else {\n                return self.y\n                \n            }\n            \n        }\n        set(newValue) {\n            if index == 0 {\n                self.x = newValue\n                \n            } else {\n                self.y = newValue\n                \n            }\n             \n        }\n        \n    }\n    \n}\n\nextension Point2D: Equatable {\n    static func == (lhs: Point2D, rhs: Point2D) -\u003e Bool {\n        lhs.x == rhs.x \u0026\u0026 lhs.y == rhs.y\n        \n    }\n    \n}\n```\n\nSpatialObject:\n```swift\nstruct Element: SpatialObject {\n    typealias Point = Point2D\n        \n    let point: Point\n    let hello = \"world\"\n    \n    func minimumBoundingRectangle() -\u003e BoundingRectangle\u003cPoint2D\u003e {\n        BoundingRectangle(lower: self.point, upper: self.point)\n        \n    }\n    \n    func distanceSquared(point: Point2D) -\u003e Double {\n        pow(point.x - self.point.x, 2) + pow(point.y - self.point.y, 2)\n        \n    }\n    \n}\n\nextension Element: Equatable {\n    static func == (lhs: Element, rhs: Element) -\u003e Bool {\n        lhs.point == rhs.point \u0026\u0026 lhs.hello == rhs.hello\n        \n    }\n    \n}\n```\n\nThen, I'm able to create an R\\*-Tree that stores `Elements` over `Point2D`:\n\n```swift\nvar tree = try RTree\u003cElement\u003e(path: path)\nlet zerozero = Element(point: Point2D(x: 0, y: 0))\nlet oneone = Element(point: Point2D(x: 1, y: 1))\nlet threethree = Element(point: Point2D(x: 3, y: 3))\n\ntry tree.insert(oneone)\ntry tree.insert(threethree)\n\ntree.nearestNeighbor(zerozero.point)! == oneone\n```\n\n## Dependencies\nNone\n\n## Contact\nFeel free to email questions and comments to [emma@emma.sh](mailto:emma@emma.sh). \n\n## Acknowledgements\n- [Spade](https://crates.io/crates/spade)'s developers and contributors for making a very simple to understand R-Tree implementation that is also (Rust's equivalent to) `Codable`.\n\n## License\n\nRTree is released under the MIT license. [See LICENSE](https://github.com/emma-k-alexandra/RTree/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femma-k-alexandra%2Frtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femma-k-alexandra%2Frtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femma-k-alexandra%2Frtree/lists"}