{"id":16684578,"url":"https://github.com/peterprokop/swiftconcurrentcollections","last_synced_at":"2025-03-21T18:32:58.305Z","repository":{"id":42657140,"uuid":"237986875","full_name":"peterprokop/SwiftConcurrentCollections","owner":"peterprokop","description":"Swift Concurrent Collections","archived":false,"fork":false,"pushed_at":"2022-11-24T15:35:27.000Z","size":42,"stargazers_count":48,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T03:51:27.027Z","etag":null,"topics":["collection","collections","concurrent-collections","thread-safe","threading","threads"],"latest_commit_sha":null,"homepage":null,"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/peterprokop.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":"2020-02-03T14:38:47.000Z","updated_at":"2024-12-23T09:05:13.000Z","dependencies_parsed_at":"2023-01-21T15:16:47.477Z","dependency_job_id":null,"html_url":"https://github.com/peterprokop/SwiftConcurrentCollections","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterprokop%2FSwiftConcurrentCollections","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterprokop%2FSwiftConcurrentCollections/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterprokop%2FSwiftConcurrentCollections/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterprokop%2FSwiftConcurrentCollections/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterprokop","download_url":"https://codeload.github.com/peterprokop/SwiftConcurrentCollections/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244849200,"owners_count":20520665,"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":["collection","collections","concurrent-collections","thread-safe","threading","threads"],"created_at":"2024-10-12T14:44:21.555Z","updated_at":"2025-03-21T18:32:58.036Z","avatar_url":"https://github.com/peterprokop.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftConcurrentCollections\n\n# Intro\n\nSwift Concurrent Collections (or **SCC**) is a library providing concurrent (thread-safe) implementations of some of default Swift collections. Similar to ones found in `java.util.concurrent` for Java.\n\n# Installation\n\n## Swift Package Manager\n\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nOnce you have your Swift package set up, adding SwiftConcurrentCollections as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```source-swift\ndependencies: [\n    .package(url: \"https://github.com/peterprokop/SwiftConcurrentCollections.git\", .branch(\"master\"))\n]\n```\n\n## Carthage\nIn your Xcode project folder do:\n- `echo \"github \\\"peterprokop/SwiftConcurrentCollections\\\" ~\u003e 1.3.0\" \u003e\u003e Cartfile` (or use `nano`)\n- Run `carthage update`\n- Add `SwiftConcurrentCollections` to your carthage [copy-frameworks phase](https://github.com/Carthage/Carthage#quick-start)\n- Add `import SwiftConcurrentCollections` in files where you plan to use it \n\n# Usage\nDo `import SwiftConcurrentCollections`\n\nThen you can use concurrent collections from different threads without fear of crashes or data corruption\n```swift\nlet concurrentArray = ConcurrentArray\u003cInt\u003e()\nconcurrentArray.append(value)\nprint(concurrentArray[0])\n```\n```swift\nlet concurrentDictionary = ConcurrentDictionary\u003cString, Int\u003e()\nconcurrentDictionary[key] = value\nprint(concurrentDictionary[key])\n```\n\n## Safe subscript\nSafe array subscript: for atomicity of checking if specified index is in the array and getting element with that index use\n```swift\nif let element = concurrentArray[safe: index] {\n    // ...\n}\n```\ninstead of \n```swift\nif index \u003c concurrentArray.count {\n    let element = concurrentArray[index]\n    // ...\n}\n```\n\n## Priority queue\n**SCC** provides both classical and concurrent priority queues\n\n```swift\nvar priorityQueue = PriorityQueue\u003cInt\u003e(\u003c)\n\npriorityQueue.insert(3)\npriorityQueue.insert(2)\npriorityQueue.insert(1)\n\nwhile priorityQueue.count \u003e 0 {\n    print(\n        priorityQueue.pop(),\n        terminator: \" \"\n    )\n    // Will print: 1 2 3\n}\n```\n\nAs you can see `PriorityQueue\u003cInt\u003e(\u003c)` constructs min-queue, with `PriorityQueue\u003cInt\u003e(\u003e)` you can get max-queue.\nIf you need to reserve capacity right away, use `PriorityQueue\u003cInt\u003e(capacity: 1024, comparator: \u003c)`.\n`ConcurrentPriorityQueue\u003cInt\u003e(\u003c)` creates a thread-safe version, with a very similar interface.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterprokop%2Fswiftconcurrentcollections","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterprokop%2Fswiftconcurrentcollections","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterprokop%2Fswiftconcurrentcollections/lists"}