Swiftpack.co - Package - ladislas/SwiftBinarySearch

Swift Binary Search

spm swift-version Build Status SonarCloud Coverage SwiftBinarySearch

About

Simple binary search methods for arrays.

Installation

With SPM, add the following to the dependencies of your Package.swift

.package(url: "https://github.com/ladislas/SwiftBinarySearch", from: "1.0.0")

Then in your code place at the top of the files where you need Swift Events:

import SwiftBinarySearch

Usage

See source code and tests for more documentation and more examples.

As standalone functions

let myArray = [0, 1, 2, 4]
let index = binarySearch(for: 3, in: myArray)
print(index) // --> "3"

// or

let myArray = [0, 1, 2, 4]
binarySearchAndInsert(for: 3, in: myArray)
print(myArray.description) // --> "[0, 1, 2, 3, 4]"

As Array extension

let myArray = [0, 1, 2, 4]
let index = myArray.binarySearch(for: 3)
print(index) // --> "3"

// or

var myArray = [0, 1, 2, 4] // declare array as var
myArray.binarySearchAndInsertInplace(element: 3)
print(myArray.description) // --> "[0, 1, 2, 3, 4]"

Authors

Made with ❤️ by:

License

MIT/Apache-2.0 @ Ladislas de Toldi

Github

link
Stars: 0
Help us keep the lights on

Dependencies

Used By

Total: 0