Skip to content

Commit 0c77f6b

Browse files
stersclaude
andcommitted
docs: Add Hungarian algorithm documentation for multi-document comparison
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1e5cb22 commit 0c77f6b

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A powerful cross-format diff tool that compares JSON, YAML, and other structured
1111
## Features
1212

1313
- **Cross-format comparison**: Compare files in different formats (JSON vs YAML)
14-
- **Multiple document support**: Handle multiple documents in a single file
14+
- **Multiple document support**: Handle multiple documents in a single file with optimal pairing using the Hungarian algorithm
1515
- **Smart array comparison**: Compare arrays by index or by value matching
1616
- **Multiple output formats**: Unified diff (default) or JSON Patch (RFC 6902)
1717
- **Detailed multiline string diffs**: Line-by-line comparison for multiline strings
@@ -156,6 +156,18 @@ doc1: value1
156156
doc2: value2
157157
```
158158
159+
#### Optimal Document Pairing with Hungarian Algorithm
160+
161+
When comparing files with multiple documents, diffnest uses the **Hungarian algorithm** to find the optimal pairing between documents. This ensures that similar documents are matched together, minimizing the total differences reported.
162+
163+
For Kubernetes-like resources, diffnest applies additional matching heuristics based on:
164+
- `kind` (highest priority - different kinds are strongly discouraged from matching)
165+
- `apiVersion`
166+
- `metadata.name`
167+
- `metadata.namespace`
168+
169+
This means when comparing two Kubernetes manifest files, a `Deployment` named "app" will preferentially match with another `Deployment` named "app", even if the documents appear in different orders in each file.
170+
159171
### Smart Array Comparison
160172

161173
Choose between two array comparison strategies:

0 commit comments

Comments
 (0)