{"id":21707814,"url":"https://github.com/flightaware/swift-speedtables","last_synced_at":"2025-03-20T17:22:25.244Z","repository":{"id":66872762,"uuid":"59763053","full_name":"flightaware/swift-speedtables","owner":"flightaware","description":"Framework for creating multi-way indexed tables in Swift, similar to Speedtables in Tcl","archived":false,"fork":false,"pushed_at":"2017-04-06T14:17:42.000Z","size":98,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":14,"default_branch":"master","last_synced_at":"2023-04-18T10:34:09.471Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flightaware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-26T15:47:10.000Z","updated_at":"2019-06-29T10:29:20.000Z","dependencies_parsed_at":"2023-02-23T10:46:10.988Z","dependency_job_id":null,"html_url":"https://github.com/flightaware/swift-speedtables","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightaware%2Fswift-speedtables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightaware%2Fswift-speedtables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightaware%2Fswift-speedtables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flightaware%2Fswift-speedtables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flightaware","download_url":"https://codeload.github.com/flightaware/swift-speedtables/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244657084,"owners_count":20488714,"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-11-25T22:19:23.394Z","updated_at":"2025-03-20T17:22:25.216Z","avatar_url":"https://github.com/flightaware.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\nThis is a work in progress. The goal of this project is to create a multi-way indexed relation in Swift. Right now creating an indexed table is pretty manual:\n\n```swift\n// Manually generated speedtable definition. This could be automatically generated\n// from something SQL-ish like:\n// TABLE Table (\n//     String name indexed\n//     Int age indexed\n//     String school optional\n//     String studentID unique optional indexed\n// )\nclass Table: SpeedTable {\n    let nameIndex: SkipList\u003cString, TableRow\u003e\n    let ageIndex: SkipList\u003cInt, TableRow\u003e\n    let studentIDIndex: SkipList\u003cString, TableRow\u003e\n    init(maxLevel: Int) {\n        nameIndex = SkipList\u003cString, TableRow\u003e(maxLevel: maxLevel)\n        ageIndex = SkipList\u003cInt, TableRow\u003e(maxLevel: maxLevel)\n        studentIDIndex = SkipList\u003cString, TableRow\u003e(maxLevel: maxLevel)\n    }\n    init(size: Int) {\n        nameIndex = SkipList\u003cString, TableRow\u003e(maxNodes: size)\n        ageIndex = SkipList\u003cInt, TableRow\u003e(maxNodes: size)\n        studentIDIndex = SkipList\u003cString, TableRow\u003e(maxNodes: size)\n    }\n    func insert(name: String, age: Int) -\u003e TableRow {\n        // Creating the table row does all the insertion stuff\n        return TableRow(parent: self, name: name, age: age)\n    }\n    func delete(row: TableRow) {\n        // delegate to row\n        row.delete()\n    }\n}\n\n// Each speedtable requires two classes, one for the table as a whole, one for\n// the row holding the data\nclass TableRow: SpeedTableRow, Equatable {\n    var parent: Table?\n    var name: String {\n        willSet { parent!.nameIndex.delete(name, value: self) }\n        didSet { parent!.nameIndex.insert(name, value: self) }\n    }\n    var age: Int {\n        willSet { parent!.ageIndex.delete(age, value: self) }\n        didSet { parent!.ageIndex.insert(age, value: self) }\n    }\n    var school: String? // Unindexed value\n    var studentIDStorage: String? // unique optional value\n    func getStudentID() -\u003e String? {\n        return studentIDStorage\n    }\n    func setStudentID(ID: String?) throws {\n        if let key = ID {\n            if parent!.studentIDIndex.exists(key) {\n                throw SpeedTableError.KeyNotUnique(key: key)\n            }\n        }\n        parent!.studentIDIndex.replace(ID, keyStore: \u0026studentIDStorage, value: self)\n    }\n    init(parent: Table, name: String, age: Int) {\n        self.parent = parent\n        self.name = name\n        self.age = age\n        // This needs to be done explicitly because the willSet/didSet doesn't\n        // fire on initialization.\n        parent.nameIndex.insert(self.name, value: self)\n        parent.ageIndex.insert(self.age, value: self)\n    }\n    func delete() {\n        parent!.nameIndex.delete(name, value: self)\n        parent!.ageIndex.delete(age, value:self)\n        if let ID = studentIDStorage {\n            parent!.studentIDIndex.delete(ID, value:self)\n        }\n        parent = nil // do not modify a row after it's deleted!\n    }\n}\n\n// This function can be anything guaranteed unique for the table. We're using === here\n// but it can be a unique key within the row instead, if there is one. Possibly a \"primary\n// key\" field in the generator can be used to drive this.\nfunc ==(lhs: TableRow, rhs: TableRow) -\u003e Bool {\n    return lhs === rhs\n}\n```\n\nEventually, we would like to have this created by a little applet that takes a Tcl\nor SQL-ish speedtable definition and generates this framework.\n\nThere are a few operations you can do on a table right now. The first two are implicit\nin the above definition.\n\n* ```table.insert(column, column, column...)```\n\nInsert a new row into the table, and all indexes, returns the row... or you can search for the row later.\n\n* ```table.delete(row)```\n\nDelete a row from the table, unthreads it from all the indexes and unlinks it from the table.\n\n* ```row.column = value```\n\nWhen you update a column in a row, it updates the index on the column automatically.\n\nThe rest of the operations are implied by the behaviour of the indexes (skiplists), for\nexample:\n\n```swift\nfor row in table.nameIndex.search(equal: myName) {\n\tif(row.age \u003e = 16) {\n\t\trow.school = \"senior\"\n\t}\n}\n```\n\nIndexes are skiplists:\n \n* ```thingIndex = SkipList\u003cType, TableRow\u003e(maxLevel: maxLevel)```\n* ```thingIndex = SkipList\u003cType, TableRow\u003e(maxSize: maxSize)```\n\n** maxLevel - maximum depth of the list, at least log(2) maximum nodes\n** maxSize - maximum number of nodes (convenience init)\n** unique - true if the index is unique\n\nThe operations on indexes are:\n\n* ```skiplist.search(key)```\n\nSearch looks up a key and returns an array of rows that match the key. This is just a simple skiplist lookup.\n\n* ```skiplist.insert(key, value)```\n* ```skiplist.delete(key, value)```\n\nYou will not be using these directly in speedtables. The insert and delete a key-value pair from the index.\n\n* ```skiplist.exists(key)```\n* ```skiplist.exists(key, value)```\n\nHelper functions for handling unique lists.\n\n* ```for (key, value) in skiplist```\n\nWalks the entire skiplist and returns all the key-value pairs. The value in a speedtable will be a speedtable row.\n\n* ```for (key, value) in skiplist.query(lessThan: key)```\n* ```for (key, value) in skiplist.query(lessThanOrEqual: key)```\n* ```for (key, value) in skiplist.query(greaterThan: key)```\n* ```for (key, value) in skiplist.query(greaterThanOrEqual: key)```\n* ```for (key, value) in skiplist.query(from: key, to: key)```\n* ```for (key, value) in skiplist.query(from: key, through: key)```\n\nThere is no \"equalTo\" because skiplist.search() already provides this functionality\ndirectly.\n\nThese are all convenience functions on the general:\n\n* ```for (key value) in skiplist.query(min: key, max: key, minEquals: Bool, maxEquals: Bool)```\n\nThe query object actually suports two mechanisms for walking the results, either the\ngenerator implied above, or the functions:\n\n* ```(key, value)? = query.first()```\n* ```(key, value)? = query.next()```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightaware%2Fswift-speedtables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflightaware%2Fswift-speedtables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflightaware%2Fswift-speedtables/lists"}