Giter Site home page Giter Site logo

orderedset's Introduction

Introduction

OrderedSet is essentially the Swift equivalent of Foundation's NSOrderedSet/NSMutableOrderedSet. It was created so Swift would have a unique, ordered collection with fast lookup performance that supported strong typing through Generics, and so we could store Swift structs and enums in it.

Usage

OrderedSet works very much like an Array. Here are some basic examples of its usage:

var set = OrderedSet<Int>()
set.append(1)
set.contains(1) // => true
set[0] = 2
set[0] // => 2
set.insert(3, at: 0)
set // => [3, 2]
set = [1,2,3] // OrderedSet's support array literals
set // => [1, 2, 3]
set += [3, 4] // You can concatenate any sequence type to an OrderedSet
set // => [1, 2, 3, 4] (Since 3 was already in the set it was not added again)

Its also recommended that you use the instance methods when possible instead of the global Swift methods for searching an OrderedSet. For example, the Swift.contains(haystack, needle) method will enumerate the OrderedSet instead of making use of the fast lookup implementation that the OrderedSet.contains(needle) method will do.

Be sure to check out the unit tests to see all the different ways to interact with an OrderedSet in action. You can also check out the sample project, which tweaks the default master/detail project to use an OrderedSet instead of an Array.

Installation

OrderedSet is a single Swift file in the Sources directory. You can copy that file into your project, or use via CocoaPods by adding the following line to your Podfile:

pod 'OrderedSet', '5.0'

or use via Carthage by adding

github "Weebly/OrderedSet"

to your Cartfile and embedding the OrderedSet.framework in your app.

And then add the following import where you want to use OrderedSet:

import OrderedSet

Using SwiftPM:

package.append(.package(url: "https://github.com/Weebly/OrderedSet.git", .upToNextMajor(from: "5.0.0")))

License

OrderedSet is available under the MIT license. See the LICENSE file for more info.

CONTRIBUTING

We love to have your help to make OrderedSet better. Feel free to

  • open an issue if you run into any problem.
  • fork the project and submit pull request.

orderedset's People

Contributors

divinedominion avatar eddiekaiger avatar gkamelo avatar jaceconflenti avatar johnclayton avatar ketzusaka avatar lucasmpaim avatar moyoteg avatar mxcl avatar nolanw avatar romanpodymov avatar t0rst avatar woollim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orderedset's Issues

didSet property observer doesn't work on OrderedSet

Here is my sample code:

var set = OrderedSet<Int>() {
    didSet {
        print("didSet was called")
    }
}

set.append(1)
set.append(2)
set.append(3)

the print messages is never called and printed event though the set was changed.

Maybe I am doing this incorrectly. Any advice would help.

Problems with MutableCollection implementation

Maybe I misunderstand the subscript usage or there are issues with the MutableCollection implementation. The problems arise when using the subscript to set values already contained in the set. Example:

let set = OrderedSet(sequence: [0, 1, 2])
print(set)  // [0, 1, 2]

set[1] = 0
set[2] = 0

print(set.count)  // 1
print(set)  // [0]
set.forEach { print($0) }  // 0, 0, 0

Here, the iterator returns repeated values, more than promised by count. I think this example could be resolved just by removing the custom Iterator here and just using the default one.

However, after digging into it, I found more issues, example:

let set = OrderedSet(sequence: [0, 1, 2])
print(set)  // [0, 1, 2]

set[1] = 0

print(set.count)  // 2
print(set)  // [0, 0]
set.forEach { print($0) }  // 0, 0, 2

The iterator again returns more than count values but also note that print(set)now contains duplicate values and omits 2!

The indices for contents and sequencedContents get out of sync. I haven't had time to find the exact issue but there are several problems:

  1. The type of iterator returned
  2. The implementations of startIndex, endIndex, and index(after:)
  3. The subscript setter doesn't/can't protect against already contained values

Support for Codable

Any chance of this supporting Codable? I tried digging in and updating T's generic constraints to be Hashable and Codable (which works fine) but am not familiar enough with UnsafeMutablePointer to know how to have it fit the Codable conformance. I imagine it could just converted in and out as Data but not sure. Thanks!

Swift 3 - xCode8b6 support

You know this probably, but she won't compile, I get 75-ish errors, some of which were beyond me to even come close to addressing.

Do you have a branch somewhere that is compatible?

I looked here -> swift3 but it's immutable

Thanx in advance

License

License file looks a bit corrupted by your last commit to it.

Upgrade to Swift 4

Swift 4 has been out for some time now and most libraries have made the transition. Is there a reason why you are keeping the legacy 3.x as the primary branch? If anything Swift 4 should be on master with 3.x on a separate legacy branch.

Error with Xcode 14.3 because of deployment_target (9.0)

I am using fmdb as a transitive dependency of a Flutter package (flutter_inappwebview).

Whenever I try to compile the application, Xcode complains about FMDB pod with this error:

Error (Xcode): File not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Could not build the application for the simulator.
Error launching application on iPhone 14 Pro Max.

According to SO this issue is connected to deployment_target being too low (requires 11.0 at least).

I'm hesitating to accept the solution being mentioned in the SO post as it uncontrollably overrides all the deployment_target properties of every pod (this doesn't seem right).

A better solution would be for the author every pod with outdated deployment_target to willingly increase it.

License issues

The phrase "all rights reserved" appears in both LICENSE and OrderedSet.swift. This is confusing, since it seems to contradict the intended license terms.

Also, the text of LICENSE doesn't match any common formulation of the MIT license. Could you use a more standard version, such as https://opensource.org/licenses/MIT?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.