Swiftpack.co - sciv-img/OSet as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by sciv-img.
sciv-img/OSet 0.7.0
Fast, idiomatic Ordered Set data structure for Swift
⭐️ 31
🕓 45 weeks ago
.package(url: "https://github.com/sciv-img/OSet.git", from: "0.7.0")

OSet

Build Status Swift Versions Platforms

Fast, idiomatic Ordered Set data structure for Swift.

Installation

Use Swift Package Manager:

.package(url: "https://github.com/sciv-img/OSet", from: "0.5.0")

If you don't want to/cannot use SwiftPM, you can always copy the source over (it's one file).

Usage

OSet supports all the same operations available in the standard Set, by implementing the SetAlgebra protocol. For example:

  1> import OSet
  2> let oset1 = OSet([1, 2, 3]); print(oset1)
OSet([1, 2, 3])
  3> let oset2 = OSet([3, 4, 5]); print(oset2)
OSet([3, 4, 5])
  4> print(oset1.union(oset2))
OSet([1, 2, 3, 4, 5])
  5> print(oset1.symmetricDifference(oset2))
OSet([1, 2, 4, 5])
  6> print(oset1.intersection(oset2))
OSet([3])

It also implements MutableCollection and RandomAccessCollection protocols. This gives access to iteration, subscript get/set, swapping, sorting, etc. For example:

  1> import OSet
  2> var oset = OSet([3, 1, 2]); print(oset)
OSet([3, 1, 2])
  3> print(oset[1])
1
  4> oset[1] = 7; print(oset[1])
7
  5> oset.swapAt(0, 2); print(oset)
OSet([2, 7, 3])
  6> oset.sort(); print(oset)
OSet([2, 3, 7])
  7> for item in oset { print(item) }
2
3
7

Complete documentation can be read directly in the source.

Benchmarks?

Are available here.

GitHub

link
Stars: 31
Last commit: 45 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics