Commonly used data structures for Swift

Overview

Swift Collections

Swift Collections is an open-source package of data structure implementations for the Swift programming language.

Read more about the package, and the intent behind it, in the announcement on swift.org.

Contents

The package currently provides the following implementations:

  • Deque , a double-ended queue backed by a ring buffer. Deques are range-replaceable, mutable, random-access collections.

  • OrderedSet , a variant of the standard Set where the order of items is well-defined and items can be arbitrarily reordered. Uses a ContiguousArray as its backing store, augmented by a separate hash table of bit packed offsets into it.

  • OrderedDictionary , an ordered variant of the standard Dictionary, providing similar benefits.

The following data structures are currently being worked on but they aren't ready for inclusion in a tagged release:

Swift Collections uses the same modularization approach as Swift Numerics: it provides a standalone module for each thematic group of data structures it implements. For instance, if you only need a double-ended queue type, you can pull in only that by importing DequeModule. OrderedSet and OrderedDictionary share much of the same underlying implementation, so they are provided by a single module, called OrderedCollections. However, there is also a top-level Collections module that gives you every collection type with a single import statement:

import Collections

var deque: Deque<String> = ["Ted", "Rebecca"]
deque.prepend("Keeley")
deque.append("Nathan")
print(deque) // ["Keeley", "Ted", "Rebecca", "Nathan"]

Project Status

The Swift Collections package is source stable. The version numbers follow Semantic Versioning -- source breaking changes to public API can only land in a new major version.

The public API of version 1.0 of the swift-collections package consists of non-underscored declarations that are marked public in the Collections, DequeModule and OrderedCollections modules.

Interfaces that aren't part of the public API may continue to change in any release, including patch releases. If you have a use case that requires using underscored APIs, please submit a Feature Request describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution.

By "underscored declarations" we mean declarations that have a leading underscore anywhere in their fully qualified name. For instance, here are some names that wouldn't be considered part of the public API, even if they were technically marked public:

  • FooModule.Bar._someMember(value:) (underscored member)
  • FooModule._Bar.someMember (underscored type)
  • _FooModule.Bar (underscored module)
  • FooModule.Bar.init(_value:) (underscored initializer)

Note that contents of the Tests, Utils and Benchmarks subdirectories aren't public API. We don't make any source compatibility promises about them -- they may change at whim, and code may be removed in any new release. Do not rely on anything about them.

Future minor versions of the package may update these rules as needed.

We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, we expect that new versions of this package will require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.) Requiring a new Swift release will only need a minor version bump.

Using Swift Collections in your project

To use this package in a SwiftPM project, you need to set it up as a package dependency:

// swift-tools-version:5.4
import PackageDescription

let package = Package(
  name: "MyPackage",
  dependencies: [
    .package(
      url: "https://github.com/apple/swift-collections.git", 
      .upToNextMajor(from: "1.0.0") // or `.upToNextMinor
    )
  ],
  targets: [
    .target(
      name: "MyTarget",
      dependencies: [
        .product(name: "Collections", package: "swift-collections")
      ]
    )
  ]
)

Contributing to Swift Collections

We have a dedicated Swift Collections Forum where people can ask and answer questions on how to use or work on this package. It's also a great place to discuss its evolution.

If you find something that looks like a bug, please open a Bug Report! Fill out as many details as you can.

Working on the package

We have some basic documentation on package internals that will help you get started.

By submitting a pull request, you represent that you have the right to license your contribution to Apple and the community, and agree by submitting the patch that your contributions are licensed under the Swift License, a copy of which is provided in this repository.

Fixing a bug or making a small improvement

  1. Submit a PR with your change. If there is an existing issue for the bug you're fixing, please include a reference to it.
  2. Make sure to add tests covering whatever changes you are making.

Proposing a small enhancement

  1. Raise a Feature Request. Discuss why it would be important to implement it.
  2. Submit a PR with your implementation, participate in the review discussion.
  3. When there is a consensus that the feature is desirable, and the implementation works well, it is fully tested and documented, then it will be merged.
  4. Rejoice!

Proposing the addition of a new data structure

  1. Start a topic on the forum, explaining why you believe it would be important to implement the data structure. This way we can figure out if it would be right for the package, discuss implementation strategies, and plan to allocate capacity to help.
  2. When maintainers agreed to your implementation plan, start work on it, and submit a PR with your implementation as soon as you have something that's ready to show! We'd love to get involved as early as you like.
  3. Participate in the review discussion, and adapt the code accordingly. Sometimes we may need to go through several revisions! This is fine -- it makes the end result that much better.
  4. When there is a consensus that the feature is ready, and the implementation is fully tested and documented, the PR will be merged by a maintainer.
  5. Celebrate! You've achieved something great!

Code of Conduct

Like all Swift.org projects, we would like the Swift Collections project to foster a diverse and friendly community. We expect contributors to adhere to the Swift.org Code of Conduct. A copy of this document is available in this repository.

Contact information

The current code owner of this package is Karoy Lorentey (@lorentey). You can contact him on the Swift forums, or by writing an email to klorentey at apple dot com. (Please keep it related to this project.)

In case of moderation issues, you can also directly contact a member of the Swift Core Team.

Comments
  • Cherry pick recent fixes to release/1.0 in preparation of tagging 1.0.3

    Cherry pick recent fixes to release/1.0 in preparation of tagging 1.0.3

    • #153: [OrderedDictionary][doc] Update docs for merge/filter operations
    • #155: Remove Swift PM Artifacts to avoid Generated Schemes in Xcode
    • #156: Reinstate custom schemes under Utils/swift-collections.xcworkspace
    • #161: [Xcode] Update schemes & file template
    • #160: [OrderedCollection] Use standard temp allocation facility, if available
    • #162: [OrderedSet] Work around weird name lookup issue in compiler
    • #165: Force-inline _modify accessors to work around a performance issue
    opened by lorentey 27
  • [Heap] Performance tweaks

    [Heap] Performance tweaks

    • @inline(__always) has a detrimental effect when used on large functions. Let's not do that.
    • Speed up invariant checking with COLLECTIONS_INTERNAL_CHECKS (resolves #69)
    • Replace naked ints with _Node, precalculating levels for each offset (resolves #71)
    • Rebase heap operations on UMBP instead Array, eliminating unnecessary index validation (resolves #75)
    • ~Add some (slightly questionable) effects attributes to heap internals.~
    • Optimize removals and heap construction

    Checklist

    • [X] I've read the Contribution Guidelines
    • [X] My contributions are licensed under the Swift license.
    • [X] I've followed the coding style of the rest of the project.
    • [ ] I've added tests covering all new code paths my change adds to the project (if appropriate).
    • [ ] I've added benchmarks covering new functionality (if appropriate).
    • [X] I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
    • [ ] I've updated the documentation if necessary.
    Heap 
    opened by lorentey 21
  • OrderedSet.intersection crashes due to out of bounds index

    OrderedSet.intersection crashes due to out of bounds index

    If have two OrderedSets of what are essentially UUIDs (wrapped in Tagged). Finding the intersection from setA works.

    setA.intersection(setB)
    

    But taking the two, same, sets and flipping the order causes an out of bounds crash in RandomAccessCollection+Offsets.swift#28.

    setB.intersection(setA)
    

    The items in the sets are 1389 vs. 1388 if that could somehow matter.

    Here's a stack trace if it helps:

    #0	0x000000018f8d9a3c in _swift_runtime_on_report ()
    #1	0x000000018f949530 in _swift_stdlib_reportFatalErrorInFile ()
    #2	0x000000018f64b5d8 in closure #1 in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) ()
    #3	0x000000018f64b37c in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) ()
    #4	0x000000018f64ad2c in _assertionFailure(_:_:file:line:flags:) ()
    #5	0x000000018f64aff0 in _fatalErrorMessage(_:_:file:line:flags:) ()
    #6	0x000000018f848f8c in UnsafeBufferPointer.subscript.read ()
    #7	0x000000018f848dfc in protocol witness for Collection.subscript.read in conformance UnsafeBufferPointer<τ_0_0> ()
    #8	0x00000001046bf4c0 in RandomAccessCollection.subscript.getter at swift-collections/Sources/OrderedCollections/Utilities/RandomAccessCollection+Offsets.swift:28
    #9	0x000000010467d904 in _HashTable.UnsafeHandle._find<τ_0_0>(_:in:) at swift-collections/Sources/OrderedCollections/HashTable/_HashTable+UnsafeHandle.swift:299
    #10	0x00000001046bd5e4 in closure #1 in closure #1 in OrderedSet._find_inlined(_:) at swift-collections/Sources/OrderedCollections/OrderedSet/OrderedSet.swift:396
    #11	0x00000001046bd648 in thunk for @callee_guaranteed (@unowned _HashTable.UnsafeHandle) -> (@unowned Int?, @unowned _HashTable.Bucket, @error @owned Error) ()
    #12	0x00000001046bf154 in partial apply for thunk for @callee_guaranteed (@unowned _HashTable.UnsafeHandle) -> (@unowned Int?, @unowned _HashTable.Bucket, @error @owned Error) ()
    #13	0x00000001046837d8 in closure #1 in _HashTable.read<τ_0_0>(_:) at swift-collections/Sources/OrderedCollections/HashTable/_HashTable.swift:151
    #14	0x0000000104683ec0 in partial apply for closure #1 in _HashTable.read<τ_0_0>(_:) ()
    #15	0x000000018f730e18 in ManagedBuffer.withUnsafeMutablePointers<τ_0_0>(_:) ()
    #16	0x00000001046836fc in _HashTable.read<τ_0_0>(_:) at swift-collections/Sources/OrderedCollections/HashTable/_HashTable.swift:149
    #17	0x00000001046bd454 in closure #1 in OrderedSet._find_inlined(_:) at swift-collections/Sources/OrderedCollections/OrderedSet/OrderedSet.swift:395
    #18	0x00000001046bd6e0 in thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<τ_0_0>) -> (@unowned Int?, @unowned _HashTable.Bucket, @error @owned Error) ()
    #19	0x00000001046bebe8 in partial apply for thunk for @callee_guaranteed (@unowned UnsafeBufferPointer<τ_0_0>) -> (@unowned Int?, @unowned _HashTable.Bucket, @error @owned Error) ()
    #20	0x000000018f62ef9c in ContiguousArray.withUnsafeBufferPointer<τ_0_0>(_:) ()
    #21	0x00000001046bd180 in OrderedSet._find_inlined(_:) atswift-collections/Sources/OrderedCollections/OrderedSet/OrderedSet.swift:391
    #22	0x00000001046ab544 in OrderedSet.contains(_:) at swift-collections/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra+Basics.swift:47
    #23	0x00000001046abdb8 in OrderedSet.intersection(_:) at swift-collections/Sources/OrderedCollections/OrderedSet/OrderedSet+Partial SetAlgebra+Operations.swift:164
    

    Information

    • Package version: version 0.0.7?
    • Platform version: iOS 15, iPhone 12 Pro simulator.
    • Swift version: I assume Swift 5.5 (Xcode 13 beta 5)

    Checklist

    • [ ] If possible, I've reproduced the issue using the main branch of this package.
    • [x] I've searched for existing GitHub issues.

    Did not attempt to reproduce on main as swift-collections is a sub-dependency on one of my dependencies. But could absolutely try if requested. Getting late where I am 😅

    Steps to Reproduce

    I have not been able to reproduce this issue unfortunately. I'm doing this a on a few different pairs of sets, and only one of them with this specific type (Tagged<Product, UUID> — product being a custom struct) causes the issue. The other sets are also Tagged<X, UUID>.

    Happy to attempt to provide more attempts to reproduce. The inner workings of all this is a bit over my head though.

    Expected behavior

    I expect the "call order" to not matter.

    Actual behavior

    Out of bounds crash.

    bug OrderedCollections 
    opened by simme 19
  • Fails to compile (Abort trap: 6)

    Fails to compile (Abort trap: 6)

    Failed to compile using SPM.

    TLDR (log file attached below)

    Abort Trap: 6

    <unknown>:0: error: fatal error encountered while reading from module 'OrderedCollections'; please file a bug report with your project and the crash log
    <unknown>:0: note: module 'OrderedCollections' full misc version is '5.3.2(5.3.2)/Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)'
    
    *** DESERIALIZATION FAILURE (please include this section in any bug report) ***
    result not found
    Cross-reference to module 'OrderedCollections'
    ... OrderedSet
    ... in an extension in module 'OrderedCollections'
    ... Element
    

    Information

    • Package version: What tag or branch of swift-collections are you using?
      • 0.0.1
    • Platform version: Please tell us the version number of your operating system.
      • macOS: 11.2.1 (20D74)
      • Xcode: 12.4 (12D4e)
      • Simulator/device: Doesn't seem to matter
    • Swift version: Paste the output of swift --version here.
      • Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
      • Target: x86_64-apple-darwin20.3.0

    EDIT: Adding more details today

    ~ > sw_vers                                                                                                            system
    ProductName:	macOS
    ProductVersion:	11.2.3
    BuildVersion:	20D91
    
    ~ > uname -a                                                                                                           system
    Darwin ****.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
    
    ~ > swift --version                                                                                                    system
    Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
    Target: x86_64-apple-darwin20.3.0
    
    ~ > clang --version                                                                                                    system
    Apple clang version 12.0.0 (clang-1200.0.32.29)
    Target: x86_64-apple-darwin20.3.0
    Thread model: posix
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`
    

    Checklist

    • [X] If possible, I've reproduced the issue using the main branch of this package.
    • [X] I've searched for existing GitHub issues.

    Steps to Reproduce

    • Create new iOS app in Xcode (just default code)
    • Set up SPM to include this repo at v 0.0.1 (same for main)
    • Build
      • iOS app target fails (log file attached below)
      • Collections target fails
      • CollectionsBenchmark target fails
      • DequeModule succeeds
      • OrderedCollections target fails
      • swift-collections-benchmark fails
      • swift-collections-benchmark-Package succeeds
      • swift-collections-Package fails

    Expected behavior

    Expect SPM to compile the targets in this repo

    Actual behavior

    Build fails. see attached build log

    bug 
    opened by zakkhoyt 18
  • Add a min-max heap implementation that can be used to back a priority queue

    Add a min-max heap implementation that can be used to back a priority queue

    Description

    This is an extraction of the heap implementation hammered out in #51.

    Detailed Design

    One of the big advantages of using a min-max heap is that we don't need to bifurcate into a min heap or max heap and keep track of which kind is used — you can pop min or max, as needed. This makes it very useful as the backing storage for a double-ended priority queue.

    public struct Heap<Element: Comparable> {
        public var isEmpty: Bool
        public var count: Int
    
        // Read-only view into the underlying array
        public var unordered: [Element]
    
        // Initializers
        public init()
        public init<S: Sequence>(_ elements: S)
    
        // Mutations
        public mutating func insert(_ element: Element)
        public mutating func insert<S: Sequence>(contentsOf: S)
        public func min() -> Element?
        public func max() -> Element?
        public mutating func popMin() -> Element?
        public mutating func popMax() -> Element?
        public mutating func removeMin() -> Element
        public mutating func removeMax() -> Element
    }
    
    // Array literal
    extension Heap: ExpressibleByArrayLiteral {
        public init(arrayLiteral elements: Element...)
    }
    
    // Iteration
    extension Heap {
        public struct Iterator: Sequence, IteratorProtocol {}
    
        public var ascending: Iterator
        public var descending: Iterator
    }
    

    Future Directions

    • Add replaceMin and replaceMax (@timvermeulen has a branch of this already)
    • Implement a priority queue on top of this (that work will be picked back up in #51)

    Documentation

    The public APIs have largely been documented. An overview document has been added to the Documentation directory that is adapted from the API review and code comments.

    Testing

    There are unit tests for the added Heap type.

    Performance

    Performance tests have been added (including comparable tests against a CFBinaryHeap). We may want to revisit the library JSON to ensure we have the desired comparisons defined. (Can somebody with a better understanding of how all of that works/is structured take a look? Maybe @lorentey?)

    Source Impact

    This is purely additive. No existing APIs were changed, deprecated, or removed.

    Checklist

    • [X] I've read the Contribution Guidelines
    • [X] My contributions are licensed under the Swift license.
    • [X] I've followed the coding style of the rest of the project.
    • [X] I've added tests covering all new code paths my change adds to the project (to the extent possible).
    • [X] I've added benchmarks covering new functionality (if appropriate).
    • [X] I've verified that my change does not break any existing tests or introduce unexpected benchmark regressions.
    • [x] I've updated the documentation (if appropriate).
    Heap 
    opened by AquaGeek 17
  • Persistent collections updates (part 4)

    Persistent collections updates (part 4)

    This is the first in a series of subsequent PRs with large-scale logic changes. This first one concentrates on the representation of node storage, and the patterns of accessing it:

    • Switch to using ManagedBuffer to represent node storage. This has useful performance benefits, but it significantly complicates access to node data. We no longer have direct access to the underlying raw storage: everything needs to go through closures passed to ManagedBuffer.withUnsafeMutablePointers.
    • Introduce struct _Node and struct _Node.UnsafeHandle to represent a (strong) reference to a hash tree node, and a convenient handle for node storage, respectively. Use these instead of directly accessing the ManagedBuffer object, whenever feasible. (_Node holds the implementation of all the actual tree operations -- it provides mutating methods to manipulate a (sub)tree, providing a workable illusion of value semantics on the level of individual subtrees. UnsafeHandle provides both read-only and mutable views into storage inside a node -- mutating operations require (and assume) that the corresponding _Node holds a uniquely held reference to the storage object.)
    • Implement separate paths for in-place mutations vs copy-on-write operation, optimizing both flavors.
    • Go to great lengths to eliminate unnecessary retain-release traffic, whenever possible.
    • Push subtree counts into parent nodes by moving the corresponding field from the node header into the _Node struct. (This results in a cool ~20x speedup for jumping around in the tree by integer offsets.)
    • Implement a type-punned empty root singleton, to allow creating empty trees without allocating anything.

    The implementation of dictionary operations remain conceptually unchanged for now (although the details look superficially different now) -- future updates will start tweaking things in earnest.

    Checklist

    • [X] I've read the Contribution Guidelines
    • [X] My contributions are licensed under the Swift license.
    • [X] I've followed the coding style of the rest of the project.
    • [ ] I've added tests covering all new code paths my change adds to the project (if appropriate).
    • [ ] I've added benchmarks covering new functionality (if appropriate).
    • [X] I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
    • [ ] I've updated the documentation if necessary.
    HashTreeCollections 
    opened by lorentey 13
  • Deque subscript _modify accessor heap allocates

    Deque subscript _modify accessor heap allocates

    Consider the following simple function (the operation is not useful, it's just intended to be complex enough to defeat being optimized away and simple enough to make the generated assembly simple):

    func twiddle(index: Int, twiddle: UInt8, deque: inout Deque<UInt8>) {
        deque[index] ^= twiddle
    }
    

    When compiled in release mode using swift-collections 1.0.2 and current main (c3fdcf7), this generates the following assembly on my arm64 Mac:

    _$s18alloc_modify_repro10DequeReproV7twiddle5indexAD5dequeySi_s5UInt8V0D6Module0D0VyAHGztFZTf4nnnd_n:        // function signature specialization <Arg[3] = Dead> of static alloc_modify_repro.DequeRepro.twiddle(index: Swift.Int, twiddle: Swift.UInt8, deque: inout DequeModule.Deque<Swift.UInt8>) -> ()
    sub        sp, sp, #0x40                               ; CODE XREF=_$s18alloc_modify_repro10DequeReproV4mainyyFZTf4d_n+208
    stp        x20, x19, [sp, #0x20]
    stp        fp, lr, [sp, #0x30]
    add        fp, sp, #0x30
    mov        x19, x1
    mov        x1, x0                                      ; argument #2 for method _$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5
    mov        x0, sp                                      ; argument #1 for method _$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5
    mov        x20, x2
    bl         _$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5     ; generic specialization <Swift.UInt8> of DequeModule.Deque.subscript.modify : (Swift.Int) -> A
    mov        x8, x0
    ldrb       w9, [x1]
    eor        w9, w9, w19
    strb       w9, [x1]
    mov        x0, sp
    mov        w1, #0x0
    blr        x8
    ldp        fp, lr, [sp, #0x30]
    ldp        x20, x19, [sp, #0x20]
    add        sp, sp, #0x40
    ret
    

    As you can see, _modify has not been inlined but it has been specialized. As a result, the call to the continuation has been split and delayed (visible as blr x8).

    _modify has compiled to:

    _$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5:        // generic specialization <Swift.UInt8> of DequeModule.Deque.subscript.modify : (Swift.Int) -> A
    stp        x24, x23, [sp, #-0x40]!                     ; CODE XREF=_$s18alloc_modify_repro10DequeReproV7twiddle5indexAD5dequeySi_s5UInt8V0D6Module0D0VyAHGztFZTf4nnnd_n+32
    stp        x22, x21, [sp, #0x10]
    stp        x20, x19, [sp, #0x20]
    stp        fp, lr, [sp, #0x30]
    add        fp, sp, #0x30
    mov        x21, x1
    mov        x22, x0
    mov        w0, #0x28                                   ; argument "size" for method imp___stubs__malloc
    bl         imp___stubs__malloc                         ; malloc
    str        x0, [x22]
    stp        x21, x20, [x0]
    tbnz       x21, 0x3f, loc_100012600
    
    mov        x19, x0
    ldr        x23, [x20]
    mov        x0, #0x0
    bl         _$sSo10HeapObjectVMa                        ; type metadata accessor for __C.HeapObject
    ldr        x8, [x23, #0x18]
    cmp        x8, x21
    b.le       loc_100012604
    
    add        x22, x19, #0x20
    mov        x0, x23                                     ; argument "arg0" for method imp___stubs__swift_isUniquelyReferenced_nonNull_native
    bl         imp___stubs__swift_isUniquelyReferenced_nonNull_native ; swift_isUniquelyReferenced_nonNull_native
    tbnz       w0, 0x0, loc_1000125b0
    
    bl         _$s11DequeModule0A0V8_StorageV15_makeUniqueCopyyyFs5UInt8V_Tg5 ; generic specialization <Swift.UInt8> of DequeModule.Deque._Storage._makeUniqueCopy() -> ()
    
    loc_1000125b0:
    ldr        x8, [x20]                                   ; CODE XREF=_$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5+88
    ldr        x9, [x8, #0x20]!
    str        x9, [x19, #0x10]
    add        x9, x9, x21
    ldur       x10, [x8, #-0x10]
    str        x10, [x19, #0x18]
    cmp        x9, x10
    csel       x10, xzr, x10, lt
    sub        x9, x9, x10
    add        x8, x8, x9
    ldrb       w8, [x8, #0x8]
    strb       w8, [x19, #0x20]
    adr        x0, #0x100012608
    nop
    mov        x1, x22
    ldp        fp, lr, [sp, #0x30]
    ldp        x20, x19, [sp, #0x20]
    ldp        x22, x21, [sp, #0x10]
    ldp        x24, x23, [sp], #0x40
    ret
    
    loc_100012600:
    brk        #0x1                                        ; CODE XREF=_$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5+44
    
    loc_100012604:
    brk        #0x1                                        ; CODE XREF=_$s11DequeModule0A0VyxSiciMs5UInt8V_Tg5+72
    

    Notice the call to malloc at the start of the function. This call drastically dominates the performance of _modify, and it makes Deque extremely difficult to use in performance sensitive code.

    Information

    • Package version: 1.0.2 or main (c3fdcf7)
    • Platform version: 21G83
    • Swift version: swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12) Target: arm64-apple-macosx12.0

    Checklist

    • [X] If possible, I've reproduced the issue using the main branch of this package.
    • [X] I've searched for existing GitHub issues.

    Steps to Reproduce

    Use the above code sample in an empty Swift project that depends on swift-collections.

    Expected behavior

    No allocations in _modify.

    Actual behavior

    A direct call to malloc and a subsequent call to free.

    bug 
    opened by Lukasa 13
  • Release version 1.0.2

    Release version 1.0.2

    Candidate commit:

    ~~da3a73ed90a17ac37b42e238b48a678d340f563f on release/1.0~~ ~~1337897dc6a878fe97a83f1549d49ddf6d093651 on release/1.0~~ 48254824bb4248676bf7ce56014ff57b142b77eb on release/1.0

    enhancement 
    opened by lorentey 13
  • DequeModule compilation error on Ubuntu

    DequeModule compilation error on Ubuntu

    I'm trying to build a CLI tool in GitHub Actions with a dependency on this package. It's building fine on macOS but it fails to build on Ubuntu 20.04.2 LTS fails. I'm using fwal/setup-swift@v1 to install Swift on the ubuntu environment. I apologise if this is not an issue on the package itself.

    Information

    • Package version: Tried both 0.0.3 and the most recent commit c0549b6
    • Platform version: Ubuntu 20.04.2 LTS
    • Swift version: Swift version 5.4 (swift-5.4-RELEASE) | Target: x86_64-unknown-linux-gnu

    Checklist

    • [x] If possible, I've reproduced the issue using the main branch of this package.
    • [x] I've searched for existing GitHub issues.

    Actual behavior

    The compiler error is as follows:

    gnu/debug/DequeModule.swiftmodule
    2021-06-16T14:48:22.9117174Z <unknown>:0: error: fatal error encountered while reading from module 'DequeModule'; please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project
    2021-06-16T14:48:22.9119412Z <unknown>:0: note: module 'DequeModule' full misc version is '5.4(5.4)/Swift version 5.4 (swift-5.4-RELEASE)'
    2021-06-16T14:48:22.9120239Z 
    2021-06-16T14:48:22.9121042Z *** DESERIALIZATION FAILURE (please include this section in any bug report) ***
    2021-06-16T14:48:22.9121888Z result not found
    2021-06-16T14:48:22.9122743Z Cross-reference to module 'DequeModule'
    2021-06-16T14:48:22.9123511Z ... Deque
    2021-06-16T14:48:22.9124310Z ... in an extension in module 'DequeModule'
    2021-06-16T14:48:22.9125028Z ... Element
    2021-06-16T14:48:22.9125472Z 
    2021-06-16T14:48:22.9126669Z Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
    2021-06-16T14:48:22.9127715Z Stack dump:
    2021-06-16T14:48:22.9174473Z 1.	Swift version 5.4 (swift-5.4-RELEASE)
    2021-06-16T14:48:22.9175397Z 2.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module DequeModule)
    2021-06-16T14:48:22.9176720Z 3.	While deserializing SIL function "$s11DequeModule0A0VAASERzlE6encode2toys7Encoder_p_tKF"
    2021-06-16T14:48:22.9178025Z 4.	While reading from 'DequeModule'
    2021-06-16T14:48:22.9179066Z 5.	While finishing conformance for protocol conformance to 'Sequence' (in module 'Swift') for type 'Deque<Element>'
    

    Full logs

    bug 
    opened by alexito4 11
  • Force-inline _modify accessors to work around a performance issue

    Force-inline _modify accessors to work around a performance issue

    As @Lukasa discovered in #164, the _modify accessor in Deque's index subscript tends to call malloc unless it happens to get inlined into the caller. Try to prevent this performance bottleneck by force-inlining this accessor.

    To mitigate potential code size issues, move the preparation/finalization steps into separate functions that aren't force-inlined.

    Resolves #164.

    Checklist

    • [X] I've read the Contribution Guidelines
    • [X] My contributions are licensed under the Swift license.
    • [X] I've followed the coding style of the rest of the project.
    • [ ] I've added tests covering all new code paths my change adds to the project (if appropriate).
    • [ ] I've added benchmarks covering new functionality (if appropriate).
    • [X] I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
    • [ ] I've updated the documentation if necessary.
    enhancement Deque 
    opened by lorentey 10
  • Update README files

    Update README files

    • Fix issues reported by @benrimmington (thanks!)
    • Update wording on evolving Swift toolchain requirements
    • Update contributor guide on adding a new data structure to better reflect reality
    • Add an extra sentence on combinatorial tests

    Resolves #209

    Checklist

    • [X] I've read the Contribution Guidelines
    • [X] My contributions are licensed under the Swift license.
    • [X] I've followed the coding style of the rest of the project.
    • [ ] I've added tests covering all new code paths my change adds to the project (if appropriate).
    • [ ] I've added benchmarks covering new functionality (if appropriate).
    • [ ] I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
    • [X] I've updated the documentation if necessary.
    opened by lorentey 9
  • You need a `ConcatenatedSequence` that joins two sequences without allocating storage

    You need a `ConcatenatedSequence` that joins two sequences without allocating storage

    This is not fully documented and could use conditional MutableCollection/Equatable/Hashable conformances, but it's a pretty complete implementation that you could use as a starting point.

    enhancement 
    opened by dabrahams 4
  • Is _BTree defaultLeafCapacity correct?

    Is _BTree defaultLeafCapacity correct?

    I assume I'm wrong here, asking for education mostly :)

    The code looks like this:

    /// Recommended node size of a given B-Tree
    @inlinable
    @inline(__always)
    internal static var defaultLeafCapacity: Int {
      #if DEBUG
      return 5
      #else
      let capacityInBytes = 2000
      return Swift.min(16, capacityInBytes / MemoryLayout<Key>.stride)
      #endif
    }
    

    From my reading the max leaf capacity is 16? Is that right? I would expect (without really understanding much of the code here) performance to be better if leaves could contain more then 16 elements when element size is small.

    bug SortedCollections 
    opened by jessegrosjean 1
  • `partitioningIndex(where:)` for Sorted Set/Dictionary

    `partitioningIndex(where:)` for Sorted Set/Dictionary

    I realize the docs say this code is still unstable, but it's never too early to ask for more, right? 😉

    There should be something analogous to partitioningIndex(where:) for the sorted associative containers. An example of why: I have a multimap K:V where the chance of having multiple V's for any K is very low and for any K, all Vs are unique. The best storage format is roughly as a sorted set of lexicographically ordered (K,V) pairs. There should be a way to find the beginning and end of the sequence of contiguous items with a given K value, without (obviously) the cost of treating the tree as a flat collection and using indices.

    In fact I'm very surprised not to see something like this in the BTree source (though it's so spread out, I may have missed it); it seems like contains and perhaps a few other things might be able to be built upon it. Thanks!

    enhancement SortedCollections 
    opened by dabrahams 11
  • [OrderedDictionary] Explicitly mention in documentation that keys/values are ordered

    [OrderedDictionary] Explicitly mention in documentation that keys/values are ordered

    It currently takes some mental gymnastics or deep data structures background to grok if OrderedDictionary's keys and values are ordered. These minor additions to the docs make that more explicit. If this sort of change is welcome I'm happy to clarify some of the other data structures as well.

    Checklist

    • [x] I've read the Contribution Guidelines
    • [x] My contributions are licensed under the Swift license.
    • [x] I've followed the coding style of the rest of the project.
    • [n/a] I've added tests covering all new code paths my change adds to the project (if appropriate).
    • [n/a] I've added benchmarks covering new functionality (if appropriate).
    • [n/a] I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
    • [x] I've updated the documentation if necessary.
    opened by warpling 3
  • README links to BitSet/BitArray are 404's

    README links to BitSet/BitArray are 404's

    Just wanted to bring this up real quick: The current README.md lists BitSet and BitArray and links both to respective files in the Documentation/ folder -- but none of these exist. Couldn't see an obvious deletion from the commit messages; so is this WIP or did the files go missing, maybe?

    bug 
    opened by DivineDominion 2
Releases(1.0.4)
  • 1.0.4(Dec 8, 2022)

    This is a documentation update, including the addition of basic DocC documentation bundles. This release has no functional changes.

    Changes

    • The package now contains documentation bundles, enabling nicer presentation of API documentation in DocC.

    Fixes

    • #186 [OrderedCollections] Document Sorting as Stable (by @benrimmington)

    Pull requests

    • #178 [OrderedDictionary] Tiny documentation fix (by @lorentey)
    • #187 Fix rethrows position (by @ensan-hcl)
    • #189 [OrderedSet] Tiny doc fixes for isSuperset (by @lorentey)
    • #201 [OrderedCollections] Update docs to state that the sort algorithm is stable (by @lorentey)
    • #214 [OrderedSet] Small doc updates/fixes (by @lorentey)
    • #252 [1.0] Add DocC documentation bundles (by @lorentey)

    Full Changelog: https://github.com/apple/swift-collections/compare/1.0.3...1.0.4

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.3(Sep 2, 2022)

    This release resolves issues uncovered since 1.0.2 was tagged. The fixes improve performance of some operations, resolve compile-time issues and update documentation. This release contains no observable behavioral changes.

    Changes

    • [Clutter] When opened in Xcode, the package no longer adds spurious schemes to dependent projects. (#155)

    Fixes

    • [Build-time issue] Code that is calling OrderedDictionary's uniquing/unique/grouping initializers and merge operations no longer gets flagged as ambiguous in certain cases involving type inference. (#125, #139)
    • [Build-time issue] The package no longer fails to build when library evolution is enabled. (#157) (Note: this configuration remains unsupported. This package does not provide any guarantees about ABI stability.)
    • [Performance] In-place mutations of collection contents no longer result in unnecessary heap allocations. (#164)
    • [Performance] On Swift 5.6 and better, some operations in the OrderedCollections module now make use of the stdlib's temporary allocation facility. (#160)
    • [Docs] Documentation was updated to clarify behavior of the filter and merge methods of OrderedDictionary. (#145)

    Pull requests

    • #140 [OrderedDictionary] Fix type inference issue with OrderedDictionary.init(grouping:by:) (by @lorentey)
    • #153 [OrderedDictionary][doc] Update docs for merge/filter operations (by @lorentey)
    • #155 Remove Swift PM Artifacts to avoid Generated Schemes in Xcode (by @hectormatos2011)
    • #156 Reinstate custom schemes under Utils/swift-collections.xcworkspace (by @lorentey)
    • #160 [OrderedCollection] Use standard temp allocation facility, if available (by @lorentey)
    • #161 [Xcode] Update schemes & file template (by @lorentey)
    • #162 [OrderedSet] Work around weird name lookup issue in compiler (by @lorentey)
    • #165 Force-inline _modify accessors to work around a performance issue (by @lorentey)
    • #169 [OrderedDictionary] Resolve call-site ambiguities (by @lorentey)
    • #170 Update README for 1.0.3 (by @lorentey)

    Full Changelog: https://github.com/apple/swift-collections/compare/1.0.2...1.0.3

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Nov 16, 2021)

    This release resolves issues uncovered since 1.0.1 was tagged, including a high severity crash in OrderedSet and OrderedDictionary. Upgrading is recommended for all clients.

    Fixes

    • Fixed a value semantic violation in OrderedSet and OrderedDictionary that could result in some mutation methods corrupting shared copies of the same value, leading to subsequent crashes. (Issue #104)
    • Deque.append(contentsOf:) now uses an exponential storage resizing strategy, as expected. Calling it in a loop no longer results in O(n) reallocations. (Issue #113)

    Pull requests

    • #113 [Deque] append(contentsOf:): Use exponential capacity reservation (by @lorentey)
    • #123 [OrderedSet] Add missing uniqueness check (by @lorentey)
    • #126 [Utils] run-full-tests.sh: Keep going after a failure (by @lorentey)
    • #128 [Utils] run-full-tests.sh: Add support for testing on Swift 5.3 without manual editing (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Sep 20, 2021)

    Changes

    • The CMake configuration now supports building the package for AArch64 Linux distributions, unblocking adoption in SPM.

      (Note that the CMake configuration is intended only to support the use of this package from within Swift toolchain builds. It is provided as is, with no source compatibility guarantees.)

    • Minor documentation updates.

    Pull requests

    • #111 [CMake] Match lowercase "aarch64" (by @neonichu)
    • #112 [OrderedSet][doc] Fix thinko (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Sep 10, 2021)

    This release marks an important milestone for this package -- the advent of source stability!

    Changes

    • The public API of Swift Collections is now considered source stable. The README defines what we consider public API.
    • The three OrderedDictionary methods that were deprecated in 0.0.7 are now marked unavailable.
    • OrderedDictionary.init(uncheckedUniqueElements:) no longer creates large dictionary instances without an associated hash table.

    Pull requests

    • #95 Follow stdlib's leading underscore rule (by @ejmarchant)
    • #96 Documentation: Remove in-place mutation comments (by @ejmarchant)
    • #97 Freeze some types for consistency with their inlinable initializers (by @lorentey)
    • #102 1.0 release preparations (by @lorentey)
    • #106 [OrderedSet] Make _checkInvariants public and call it in more operations (by @lorentey)
    • #107 [OrderedSet] Don't let the unchecked init create large sets with no hash table (by @lorentey)
    • #110 [run-full-tests.sh] Fix bashism: == vs = (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.7(Aug 20, 2021)

    This release prepares for source stability by deprecating some OrderedDictionary APIs that we'd like to remove in version 1.0 of the package. (All deprecated names have reasonable replacements.)

    Changes

    • The two OrderedDictionary.modifyValue methods were renamed updateValue, to better align with the standard updateValue function (#90)

      /* Old: */ d.modifyValue(forKey: key,  default: []) { $0.append(newValue) }
      /* New: */ d.updateValue(forKey: key,  default: []) { $0.append(newValue) }
      
      /* Old: */ d.modifyValue(forKey: key,  insertingDefault: [], at: 0) { $0.append(newValue) }
      /* New: */ d.updateValue(forKey: key,  insertingDefault: [], at: 0) { $0.append(newValue) }
      
    • OrderedDictionary.subscript(offset:) was removed; it used inconsistent terminology. To access a key-value pair at a given position, you can continue using the unlabeled subscript on the elements view.

      /*  Deprecated: */ d[offset: 42]
      /* Replacement: */ d.element[42]
      
    • The collections benchmarks were moved to a standalone nested package in a subdirectory of the repository, allowing the top-level package manifest to stop declaring a dependency on swift-collections-benchmark. This will make it easier to add Swift Collections as a dependency, especially in projects such as the Package Manager (or the benchmarking tool itself).

    The old names for removed/renamed APIs are still available as deprecated members -- these will be removed in the 1.0 release.

    Pull requests

    • #81 Fix typos: missing subscript parameters (by @ejmarchant)
    • #82 Fix documentation for types conforming to ExpressibleByArrayLiteral or ExpressibleByDictionaryLiteral (by @ejmarchant)
    • #86 Stop depending on swift-collections-benchmark (by @lorentey)
    • #91 [OrderedDictionary] modifyValue → updateValue (by @lorentey)
    • #93 Add Benchmarks package to workspace (by @lorentey)
    • #92 [OrderedDictionary] Deprecate subscript(offset:) for now (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.5(Jul 30, 2021)

    This release consists of an update to the CMake config that is used during non-bootstrapped builds of the Swift toolchain. It contains no changes for package-based projects.

    Pull requests

    • #64: Add arm64 support to CMake build (by @neonichu)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.4(Jul 9, 2021)

    Fixes

    • Work around a nondeterministic build issue that triggered a compiler crash on some machines (#56)
    • Basic support for building on OpenBSD (#52)
    • Building the package with COLLECTIONS_INTERNAL_CHECKS no longer fails (#53)

    Pull requests

    • #52: Changes to support OpenBSD (by @3405691582)
    • #53: Update invalid OrderedDictionary invariant check (by @vihanb)
    • #55: Fixing a small typo on quick help docs (by @rkreutz)
    • #54: Mark OrderedSetDiffingTests with availability (by @amonshiz)
    • #60: [CMake] Update config to prepare for SwiftPM adoption (by @lorentey)
    • #62: Work around another MergeModules crash (by @lorentey)
    • #63: [test] checkCollection: Don’t pass decreasing indices to distance(from:to:) (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.3(May 28, 2021)

    Fixes

    • The repository no longer contains files with invalid names on Windows (#33)
    • Deque.append(contentsOf:), .prepend(contentsOf:) and the sequence-based initializer no longer crash when given an array instance bridged from Objective-C. (#27)
    • OrderedSet.insert is now marked @discardableResult. (#19)
    • The benchmark executable is no longer exposed as a public package product. (#28)

    Pull requests

    (You can also find a full list of issues resolved and PRs merged in this release by looking at the 0.0.3 milestone.)

    • #10: [meta] Update links in PR templates (by @lorentey)
    • #13: Add Package.resolved to .gitignore (by @maniramezan)
    • #21: Add the @discardableResult attribute to OrderedSet.insert(_:at:) (by @kielgillard)
    • #23: Fix CollectionTestCase calling super's setup on tearDown issue (by @abintom)
    • #25: Update to swift-collections-benchmark 0.0.2 (by @lorentey)
    • #26: [OrderedDictionary] Document encoding format (by @lorentey)
    • #28: [OrderedCollections] Correct spelling of BitsetTests filename (by @msteindorfer)
    • #32: Replace Index with Int where possible (by @Frizlab)
    • #34: Documentation: remove invalid file characters (by @compnerd)
    • #36: Remove the benchmark product from the package manifest (by @lorentey)
    • #40: Add Xcode template file with license comment. (by @vihanb)
    • #41: git: ignore vim swap files (by @compnerd)
    • #42: build: add a CMake based build system (by @compnerd)
    • #44: [Deque] Work around stdlib issue with Array.withContiguousStorageIfAvailable (by @lorentey)
    • #47: [manifest] Ignore CMake files (by @lorentey)
    • #48: [meta] Update dependencies (by @lorentey)
    • #49: [Deque][NFC] Remove unused code (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.2(Apr 10, 2021)

    Additions

    • OrderedSet now implements an efficient, linear time diffing algorithm, like Foundation's NSOrderedSet and SwiftUI's List. (https://github.com/apple/swift-collections/pull/6)

    Fixes

    • We've worked around a nondeterministic build issue that triggered a compiler crash on a minority of machines. (https://github.com/apple/swift-collections/issues/7)

    Pull requests

    (You can also find a full list of issues resolved and PRs merged in this release by looking at the 0.0.2 milestone.)

    • #6: Efficient diffing for OrderedSet (by @numist)
    • #8: Fixes link to combinatorics. (by @powerje)
    • #9: Minor doc fix (by @byaruhaf)
    • #12: Remove outdated passage in OrderedSet.init(minimumCapacity:persistent:) docs (by @lorentey)
    • #14: Correct typo for address sanitizer (by @toddpress)
    • #15: Update Package.resolved with swift-collections-benchmark package (by @Sajjon)
    • #16: Update Xcode schemes for the package (by @lorentey)
    • #18: Fix nondeterministic compiler crash in debug builds (by @lorentey)

    Thank you to everyone who contributed to this release! Your bug reports, discussions and pull requests all help improve this package.

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Apr 5, 2021)

Owner
Apple
Apple
Algorithms and data structures in Swift, with explanations!

Welcome to the Swift Algorithm Club! Here you'll find implementations of popular algorithms and data structures in everyone's favorite new language Sw

raywenderlich 27.3k Jan 8, 2023
Simple implementations of various dynamic data structures in Swift.

SwiftDataStructures Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installatio

Hector Delgado 0 Oct 21, 2021
EKAlgorithms contains some well known CS algorithms & data structures.

EKAlgorithms EKAlgorithms is a set of computer exercises implemented in Objective-C. Data structures, well known algorithms, CS curiosities, you name

Evgeny Karkan 2.4k Jan 4, 2023
Swivl - A set of BLAS-accelerated linerar algebra structures and functions

Swivl - Swift Vector Library A set of BLAS-accelerated linerar algebra structure

null 0 Jan 19, 2022
Algorithm is a library of tools that is used to create intelligent applications.

Welcome to Algorithm Algorithm is a library of tools that is used to create intelligent applications. Features Probability Tools Expected Value Progra

Cosmicmind 820 Dec 9, 2022
A Graph Data Structure in Pure Swift

SwiftGraph SwiftGraph is a pure Swift (no Cocoa) implementation of a graph data structure, appropriate for use on all platforms Swift supports (iOS, m

David Kopec 700 Dec 16, 2022
The simplest abstraction to synchronize local data with remote source. For iOS, wirtten in swift.

Purpose The simplest abstraction to synchronize local data with remote source. For iOS, written in swift. Overview Many applications uses remote serve

Siarhei Ladzeika 7 Mar 17, 2022
Arena is an implementation of the generational arena data structure in Swift.

Arena This package is very much work in progress. Arena is an implementation of the generational arena data structure in Swift. An Arena is useful for

null 7 Dec 7, 2021
KeyPathKit is a library that provides the standard functions to manipulate data along with a call-syntax that relies on typed keypaths to make the call sites as short and clean as possible.

KeyPathKit Context Swift 4 has introduced a new type called KeyPath, with allows to access the properties of an object with a very nice syntax. For in

Vincent Pradeilles 406 Dec 25, 2022
Swift-extensions - Swift package extending the Swift programming language.

swift-extensions A package containing extensions for the Swift programming language. Contribution Reporting a bug If you find a bug, please open a bug

Alexandre H. Saad 2 Jun 12, 2022
Fast sorted collections for Swift using in-memory B-trees

Fast Sorted Collections for Swift Using In-Memory B-Trees Overview Reference Documentation Optimizing Collections: The Book What Are B-Trees? Why In-M

null 1.3k Dec 20, 2022
Simple diff library in pure Swift

Diff Simple diffing library in pure Swift. Installing You can use Carthage or Swift Package Manager to install Diff. Usage Start by importing the pack

Sam Soffes 120 Sep 9, 2022
A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript

Dollar Dollar is a Swift library that provides useful functional programming helper methods without extending any built in objects. It is similar to L

Ankur Patel 4.2k Jan 4, 2023
Swift type modelling the success/failure of arbitrary operations.

Result This is a Swift µframework providing Result<Value, Error>. Result<Value, Error> values are either successful (wrapping Value) or failed (wrappi

Antitypical 2.5k Dec 26, 2022
Swift μ-framework for efficient array diffs and datasource adapters.

Buffer Swift μ-framework for efficient array diffs, collection observation and data source implementation. C++11 port here Installation cd {PROJECT_RO

Alex Usbergo 348 Aug 2, 2022
A Generic Priority Queue in Pure Swift

SwiftPriorityQueue SwiftPriorityQueue is a pure Swift (no Cocoa) implementation of a generic priority queue data structure, appropriate for use on all

David Kopec 350 Dec 22, 2022
Super lightweight DB written in Swift.

Use of value types is recommended and we define standard values, simple structured data, application state and etc. as struct or enum. Pencil makes us

Naruki Chigira 88 Oct 22, 2022
A fast Swift diffing library.

HeckelDiff Pure Swift implementation of Paul Heckel's A Technique for Isolating Differences Between Files Features This is a simple diff algorithm tha

Matias Cudich 166 Oct 6, 2022
NSCoding's counterpart for Swift structs.

Dekoter Why You Might Be Interested How Much Familiar It Feels One More Example What We've Learned from It Features Save an Object to UserDefaults Arc

Artem Stepanenko 25 May 15, 2022