All Projects → peterprokop → SwiftConcurrentCollections

peterprokop / SwiftConcurrentCollections

Licence: MIT license
Swift Concurrent Collections

Programming Languages

swift
15916 projects
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to SwiftConcurrentCollections

Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (+442.5%)
Mutual labels:  collections, threading
Phpcollections
A set of collections for PHP.
Stars: ✭ 53 (+32.5%)
Mutual labels:  collection, collections
The-Java-Workshop
A New, Interactive Approach to Learning Java
Stars: ✭ 65 (+62.5%)
Mutual labels:  collection, threading
php-underscore
PHP underscore inspired &/or cloned from _.js, with extra goodies like higher order messaging
Stars: ✭ 42 (+5%)
Mutual labels:  collection, collections
indicium
🔎 A simple in-memory search for collections and key-value stores.
Stars: ✭ 41 (+2.5%)
Mutual labels:  collection, collections
flare
Useful thread-safe collections with performance in mind for Java 8+.
Stars: ✭ 14 (-65%)
Mutual labels:  collections, thread-safe
Knapsack
Collection pipeline library for PHP
Stars: ✭ 521 (+1202.5%)
Mutual labels:  collection, collections
NonEmptyCollections
A type-safe implementation for collections that cannot be empty. Life is too short for emptiness-checks!
Stars: ✭ 45 (+12.5%)
Mutual labels:  collection, collections
Awesome Deep Learning And Machine Learning Questions
【不定期更新】收集整理的一些网站中(如知乎、Quora、Reddit、Stack Exchange等)与深度学习、机器学习、强化学习、数据科学相关的有价值的问题
Stars: ✭ 203 (+407.5%)
Mutual labels:  collection, collections
Containers
This library provides various containers. Each container has utility functions to manipulate the data it holds. This is an abstraction as to not have to manually manage and reallocate memory.
Stars: ✭ 125 (+212.5%)
Mutual labels:  collection, collections
Buckets Js
A complete, fully tested and documented data structure library written in pure JavaScript.
Stars: ✭ 1,128 (+2720%)
Mutual labels:  collection, collections
go-streams
Stream Collections for Go. Inspired in Java 8 Streams and .NET Linq
Stars: ✭ 127 (+217.5%)
Mutual labels:  collection, collections
HelloWorlds
Hello-World program in most programming languages
Stars: ✭ 102 (+155%)
Mutual labels:  collection, collections
thread-pool
A modern thread pool implementation based on C++20
Stars: ✭ 104 (+160%)
Mutual labels:  threading, threads
collections
📝 Collections library made in TypeScript
Stars: ✭ 14 (-65%)
Mutual labels:  collections
my-action-github
awesome github
Stars: ✭ 62 (+55%)
Mutual labels:  collection
VBCorLib
The VBCorLib framework brings many of the powerful .NET classes to VB6.
Stars: ✭ 81 (+102.5%)
Mutual labels:  collections
gologger
A concurrent, fast queue/service worker based filesystem logging system perfect for servers with concurrent connections
Stars: ✭ 16 (-60%)
Mutual labels:  threads
jdk-source-code-reading
JDK source code reading
Stars: ✭ 19 (-52.5%)
Mutual labels:  collection
Perfect-Thread
Core threading library for Perfect Server Side Swift. Includes support for serial and concurrent thread queues, locks, read/write locks and events.
Stars: ✭ 17 (-57.5%)
Mutual labels:  threading

SwiftConcurrentCollections

Intro

Swift 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.

Installation

Carthage

In your Xcode project folder do:

  • echo "github \"peterprokop/SwiftConcurrentCollections\" ~> 1.3.0" >> Cartfile (or use nano)
  • Run carthage update
  • Add SwiftConcurrentCollections to your carthage copy-frameworks phase
  • Add import SwiftConcurrentCollections in files where you plan to use it

Usage

Do import SwiftConcurrentCollections

Then you can use concurrent collections from different threads without fear of crashes or data corruption

let concurrentArray = ConcurrentArray<Int>()
concurrentArray.append(value)
print(concurrentArray[0])
let concurrentDictionary = ConcurrentDictionary<String, Int>()
concurrentDictionary[key] = value
print(concurrentDictionary[key])

Safe subscript

Safe array subscript: for atomicity of checking if specified index is in the array and getting element with that index use

if let element = concurrentArray[safe: index] {
    // ...
}

instead of

if index < concurrentArray.count {
    let element = concurrentArray[index]
    // ...
}

Priority queue

SCC provides both classical and concurrent priority queues

var priorityQueue = PriorityQueue<Int>(<)

priorityQueue.insert(3)
priorityQueue.insert(2)
priorityQueue.insert(1)

while priorityQueue.count > 0 {
    print(
        priorityQueue.pop(),
        terminator: " "
    )
    // Will print: 1 2 3
}

As you can see PriorityQueue<Int>(<) constructs min-queue, with PriorityQueue<Int>(>) you can get max-queue. If you need to reserve capacity right away, use PriorityQueue<Int>(capacity: 1024, comparator: <). ConcurrentPriorityQueue<Int>(<) creates a thread-safe version, with a very similar interface.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].