JadenGeller / Orderly

Sorted array types in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Orderly

Orderly defines a sorted array type that implements optimized forms of insert(_:), index(of:), contains(_:), and more by taking advantage of binary search. This type is also useful for maintaining queues where constant-time min() or max() lookup is important.

var queue: SortedArray = [18, 1, 2, 20, 6].sorted()
queue.insert(3)
queue.insert(12)
print(queue) // -> [1, 2, 3, 6, 12, 18, 20]

In addition to SortedArray, Orderly also provides a LazyMapSortedArray type for sorting on arbitrary properties or transforms and a DescriptorSortedArray type for sorting by an arbitrary predicate.

let x: LazyMapSortedArray = arr.sorted(on: { $0.foo })
let y: DescriptorSortedArray = arr.sortedy(by: { $0.foo < $1.foo || $0.bar < $0.bar })

GYB

This package is implemented using Generate Your Boilerplate to codegen the 3 array types. If you'd like to contribute to this package, please modify the gyb file in the Templates directory and then run the compile script from that directory.

About

Sorted array types in Swift

License:MIT License


Languages

Language:Swift 65.1%Language:Python 34.6%Language:Shell 0.3%