https://github.com/ladislas/swiftbinarysearch
Simple binary search methods for arrays
https://github.com/ladislas/swiftbinarysearch
Last synced: 7 months ago
JSON representation
Simple binary search methods for arrays
- Host: GitHub
- URL: https://github.com/ladislas/swiftbinarysearch
- Owner: ladislas
- License: apache-2.0
- Created: 2018-09-30T10:02:56.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2019-11-20T11:21:52.000Z (almost 6 years ago)
- Last Synced: 2025-01-28T08:55:29.892Z (9 months ago)
- Language: Swift
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Swift Binary Search
[](https://github.com/apple/swift-package-manager)
[](swift.org)
[](https://travis-ci.org/ladislas/SwiftBinarySearch)
[](https://sonarcloud.io/dashboard?id=ladislas_SwiftBinarySearch)
[](https://sonarcloud.io/dashboard?id=ladislas_SwiftBinarySearch)
[](https://github.com/ladislas/SwiftBinarySearch/blob/master/LICENSE)## About
Simple binary search methods for arrays.
## Installation
With SPM, add the following to the dependencies of your `Package.swift`
```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:
```swift
import SwiftBinarySearch
```## Usage
See source code and tests for more documentation and more examples.
### As standalone functions
```swift
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
```swift
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:
* **Ladislas de Toldi** - [ladislas](https://github.com/ladislas)
## License
MIT/Apache-2.0 @ Ladislas de Toldi