# Filtered Search

> USearch for Swift

The predicate runs on the executor's threads, so it must be `@Sendable` and safe for concurrent use; an error it throws rejects that key.
Non-matching entries still route the traversal, so recall does not collapse at low selectivity.
`DenseSearchConfig(traversal: .scan)` skips the walk and scores every entry exactly, on RAM and NVMe handles, the fallback for a filter too selective for a walk to cross.

```swift
let even = try index.on(executor).search(queries, wanted: 10, arena: arena, config: DenseSearchConfig(
    predicate: { key in key.integerIdentity.map { $0 % 2 == 0 } ?? false }))
```

Every long verb's config, and every lifecycle config that reports, takes a `progress` handler, called with the units finished so far and the units the call finishes if it runs to the end; returning `.cancel` stops it with `cancelled` wherever the verb can stop, which an `insert` cannot.
A handler never runs on two threads at once, so it may carry a counter or a deadline without a lock, but it may run on whichever thread advanced the work, hence `@Sendable`.
A predicate, handler or value lookup that throws never unwinds into C; the first error stops the call where it can and is thrown once the call is final, a `USearchError` as it was and any other as the `cause` of a `cancelled` one.

```swift
let deadline = ContinuousClock.now + .seconds(30)
try index.on(executor).refine(config: DenseRefineConfig(
    expansionFactor: 128,
    progress: { _, _ in ContinuousClock.now < deadline ? .continue : .cancel }))
```

`import USearch`

## Progress

A periodic report of a long call's advance - units finished and units in total, in whatever the verb consumes - and the caller's chance to stop it.

```swift
typealias Progress = @Sendable (_ completed: Int, _ total: Int) throws -> Continuation
```

Never invoked concurrently, however many threads perform the work, so the handler needs no
synchronization of its own; an error it throws never unwinds into the engine, but stops the call
as `.cancel` would and is thrown once the call is final. It runs on whichever thread advanced the
work, hence `@Sendable`.

## Continuation

Whether the operation a progress handler is watching carries on or unwinds.

```swift
enum Continuation
```

- `continue`: Carry on to the next unit of work.
- `cancel`: Stop; what the finished increments leave behind is each verb's own contract.

Conforms to: `Equatable`, `Hashable`, `Sendable`

