# Refinement

> USearch for Swift

`refine` re-selects the neighbors of every stored entry against the finished graph and returns a `DenseRefineReport`: the entries re-selected and changed, the islands found and reconnected, and the closing audit.
A cheap insertion pass followed by one refinement reaches a better graph in less total time than one expensive insertion pass.
Zero `changed` means the graph has settled, and searches may run throughout.

```swift
while try index.on(executor).refine(config: DenseRefineConfig(expansionFactor: 128)).changed != 0 {}
```

### Absorbing & Splitting

Bigger indexes come from absorbing, never mutating: `absorb` appends every donor's entries with its graph, then refines across the appended part.
It consumes every donor it absorbs, so every later verb on one reports `uninitialized`, and an absorb stopped early hands the rest back to their indexes.

```swift
try index.on(executor).absorb([shard])
```

`split` is the inverse: it hands graph-local parts of the index to empty receivers of the same configuration, one part each, keeping their edges and leaving the index empty but live.
Both report the closing refines as `refine` does.

```swift
let report = try index.on(executor).split(into: [left, right], config: DenseSplitConfig(seed: 42))
```

`import USearch`

## DenseRefineReport

What one [`refine`](https://www.unum.cloud/docs/usearch/swift/metrics.md#refine), [`absorb`](https://www.unum.cloud/docs/usearch/swift/metrics.md#absorb) or [`split`](https://www.unum.cloud/docs/usearch/swift/metrics.md#split) did to the graph.

```swift
struct DenseRefineReport
```

Conforms to: `Equatable`, `Sendable`

## reselected

The entries whose neighbors were selected again, the islands of every heal round included.

```swift
var reselected: Int
```

## changed

Of those, the entries whose neighbor set gained a member it lacked; zero means settled.

```swift
var changed: Int
```

## islandsFound

The entries the first audit found not reached both ways.

```swift
var islandsFound: Int
```

## islandsReconnected

The links written between an island and an entry the audit reached both ways.

```swift
var islandsReconnected: Int
```

## reachability

The audit closing the heal, as a fresh [`health`](https://www.unum.cloud/docs/usearch/swift/metrics.md#health) right after would take it.

```swift
var reachability: DenseReachability
```

## DenseRefineConfig

The knobs of [`refine`](https://www.unum.cloud/docs/usearch/swift/metrics.md#refine).

```swift
struct DenseRefineConfig
```

Every zeroed field derives.

## expansionFactor

The breadth of the candidates the re-selection walk explores; zero derives it from the geometry.

```swift
var expansionFactor: Int
```

## progress

Called with nodes swept; a stop leaves the graph correct and merely less improved.

```swift
var progress: Progress?
```

## progressSteps

Reports the call makes at most, the last at completion; zero derives to ten.

```swift
var progressSteps: Int
```

## stats

The traversal telemetry to write.

```swift
var stats: DenseTraversalStats?
```

## init

```swift
init(expansionFactor: Int = 0, progress: Progress? = nil, progressSteps: Int = 0, stats: DenseTraversalStats? = nil)
```

## DenseAbsorbConfig

The knobs of [`absorb`](https://www.unum.cloud/docs/usearch/swift/metrics.md#absorb).

```swift
struct DenseAbsorbConfig
```

## progress

Called with donors absorbed.

```swift
var progress: Progress?
```

## progressSteps

Reports the call makes at most, the last at completion; zero derives to ten.

```swift
var progressSteps: Int
```

## init

```swift
init(progress: Progress? = nil, progressSteps: Int = 0)
```

## DenseSplitConfig

The knobs of [`split`](https://www.unum.cloud/docs/usearch/swift/metrics.md#split).

```swift
struct DenseSplitConfig
```

Every zeroed field derives.

## seed

Picks the part roots: equal seeds over an unchanged index split equally.

```swift
var seed: UInt64
```

## expansionFactor

The breadth of the candidates of the closing refines' walks; zero derives.

```swift
var expansionFactor: Int
```

## progress

Called with nodes the closing refines re-selected; a stop never undoes a move.

```swift
var progress: Progress?
```

## progressSteps

Reports the call makes at most, the last at completion; zero derives to ten.

```swift
var progressSteps: Int
```

## stats

The traversal telemetry to write.

```swift
var stats: DenseTraversalStats?
```

## init

```swift
init(seed: UInt64 = 0, expansionFactor: Int = 0, progress: Progress? = nil, progressSteps: Int = 0, stats: DenseTraversalStats? = nil)
```

