Swiftpack.co - Package - ole/SortedArray

SortedArray

A sorted array type for Swift 4.0+.

Provides the SortedArray type, an array that keeps its elements sorted according to a given sort predicate.

Written by Ole Begemann, February 2017.

For more info, see the GitHub repo and my accompanying blog article.

Status

Build Status

Supported Platforms

The current release supports Swift 4.0 and up.

If you need support for older Swift version, here's a list of the latest releases that support specific Swift versions:

| Swift version | Latest SortedArray release | | ------------- | -------------------------- | | 4.x | master | | 3.x | 0.6.0 | | 3.0 | 0.4 |

Since the code has no dependencies other than the Swift standard library (it doesn't even use Foundation), it should work on all platforms where Swift is available.

I tested it on macOS, iOS, tvOS, and Linux.

Usage

Swift Package Manager

Add this to your Package.swift file:

// Package.swift
import PackageDescription

let package = Package(
    name: "<Your package name>",
    dependencies: [
        .Package(url: "https://github.com/ole/SortedArray.git", majorVersion: 0)
    ]
)

Carthage

Add this to your Cartfile:

github "ole/SortedArray" ~> 0.7

Integration via Carthage should work for macOS, iOS, tvOS, and watchOS targets.

Manually

Clone the repository and add or copy SortedArray.swift to your project. It has no dependencies.

Dependencies

None.

License

MIT license.

Github

link
Stars: 126
Help us keep the lights on

Dependencies

Used By

Total: 0

Releases

0.7.0 - Jun 18, 2018

  • Drop Swift 3.x support. Please continue to use version 0.6.0 if you need Swift 3 compatibility. The lowest supported version is now Swift 4.0.

  • Compatibility with Swift 4.2.

  • SortedArray now conditionally conforms to Equatable (on Swift 4.1 and up) and Hashable (on Swift 4.2 and up) if its Element type is Equatable or Hashable. Note that the comparator function is not considered for determining equality.

  • Added SortedArray.firstIndex(of:) as an alias for index(of:) (following the standard library). The old method isn’t deprecated yet, but may be in a future release.

  • The binary search is now implemented using recursion, which (surprisingly to me) turned out to be faster (#21). Thanks @kareman.

  • General cleanup because we no longer need to support Swift 3. Thanks @klaaspieter.

  • The performance tests are now in a separate target and do no longer run by default when you hit Cmd+U in Xcode. This speeds up the test suite. On the command line, use swift test --parallel --filter UnitTests to only run the unit tests.

0.6.0 - Jan 10, 2018

  • Fix index(of:) when searching for duplicate elements. Previously, index(of:) was not guaranteed to return the index of the first matching element when the array contains duplicates. This is now fixed (#16). Thanks @Mamonaku!

  • Provide lastIndex(of:) and anyIndex(of:) (when it’s not important which of multiple matching elements is found) methods to complement index(of:).

0.5.1 - Aug 8, 2017

Switch back to legacy Xcode build system (required for Carthage compatibility) (#13). Thanks @klaaspieter!

0.5.0 - Jul 16, 2017

  • Compatible with Swift 3.2 and Swift 4.0.
  • Dropped support for Swift 3.0.
  • The methods for removing elements from the array now have the @discardableResult attribute, avoiding compiler warnings if you ignore the return value. Thanks @DivineDominion!

0.4.0 - Apr 28, 2017

Added equality operators == and != to SortedArray (#9). Thanks @klaaspieter!