finnvoor / FindFaster

Quickly find matches in a Swift collection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FindFaster

CI

Fast asynchronous swift collection search using the Boyer–Moore string-search algorithm. fastSearch can be used with any BidirectionalCollection where Element is Hashable, and is especially useful for searching large amounts of data or long strings and displaying the results as they come in.

FindFaster is used for find and replace in HextEdit, a fast and native macOS hex editor.

Usage

Async

import FindFaster

let text = "Lorem ipsum dolor sit amet"
let search = "or"

for await index in text.fastSearchStream(for: search) {
    print("Found match at: \(index)")
}

// Prints:
//  Found match at: 1
//  Found match at: 15

Sync

import FindFaster

let text = "Lorem ipsum dolor sit amet"
let search = "or"

let results = text.fastSearch(for: search)
print("Results: \(results)")

// Prints:
//  Results: [1, 15]

Closure-based

import FindFaster

let text = "Lorem ipsum dolor sit amet"
let search = "or"

text.fastSearch(for: search) { index in
    print("Found match at: \(index)")
}

// Prints:
//  Found match at: 1
//  Found match at: 15

About

Quickly find matches in a Swift collection

License:Creative Commons Zero v1.0 Universal


Languages

Language:Swift 100.0%