๐Ÿ”จ Revolutionary Breakthrough

The Milkyway’s Best Diff Swift Package D1F

D1F MultiLineDiff makes Git diff, Myers algorithm, and traditional tools obsolete. Experience 10x faster performance, AI integration, and 100% accuracy with the most flexible diffing system in the Galaxy.

10x
Faster
4
Algorithms
100%
Accurate
๐Ÿค–
AI Ready
โœจ Live Example

See the Magic in Action

Instantly visualize every code change with beautiful emoji symbols. AI native diffs for humans and machines.

๐Ÿ“Ž Paperclip = Unchanged lines
โŒ Red X = Lines to delete
โœ… Green check = Lines to add
๐Ÿค– AI Ready = Perfect integration
D1F 3x Smarter than Git
HUE Readable by Humans
MCP Built For AI Integration
D1F MULTI LINE DIFF
๐Ÿ“Ž class TaskManager {
๐Ÿ“Ž     private var tasks: [Task] = []
โœ…     private var count: Int = 0
๐Ÿ“Ž     
โŒ     func add(name: String) -> Bool {
โœ…     func add(name: String) -> Result {
๐Ÿ“Ž         guard !name.isEmpty else {
โŒ             return false
โœ…             return .failure(.invalid)
๐Ÿ“Ž         }
๐Ÿ“Ž         
โŒ         let task = Task(name: name)
โœ…         let task = Task(id: UUID(), name: name)
๐Ÿ“Ž         tasks.append(task)
โŒ         return true
โœ…         count += 1
โœ…         return .success(task)
๐Ÿ“Ž     }
๐Ÿ“Ž }

Interactive Demo

Experience the power of D1F MultiLineDiff in real-time

โœ… Real JavaScript Implementation

Configuration

Diff Legend

๐Ÿ“Ž Retain
โœ… Insert
โŒ Delete

Source

Destination

๐Ÿ“Š

Generate a diff to see the output here

Four Powerful Algorithms

Choose the perfect algorithm for your specific needs

โšก Flash Algorithm

Fastest O(n) Swift Native

Lightning-fast prefix/suffix detection using Swift's native string methods. Perfect for speed-critical applications and real-time editing.

Create Time 14.5ms
Apply Time 6.6ms
Operations 3
Memory Minimal
// Flash: Fastest algorithm
let diff = MultiLineDiff.createDiff(
source: "Hello, world!",
destination: "Hello, Swift!",
algorithm: .flash
)
// Result: 3 operations, 21.0ms total

๐Ÿ” Zoom Algorithm

Simple O(n) Character-based

Simple and fast character-based algorithm for straightforward text changes. Minimal operations with excellent performance.

Create Time 23.9ms
Apply Time 9.1ms
Operations 4
Simplicity Maximum
// Zoom: Simple character-based
let diff = MultiLineDiff.createDiff(
source: simpleText,
destination: modifiedText,
algorithm: .zoom
)
// Result: Minimal operations, fast processing

๐Ÿค– Optimus Algorithm

Line-Aware O(n log n) CollectionDiff

Sophisticated CollectionDifference-based line analysis with semantic understanding. Ideal for code refactoring and structured text.

Create Time 43.7ms
Apply Time 6.6ms
Operations 1256
Detail High
// Optimus: Line-aware processing
let diff = MultiLineDiff.createDiff(
source: sourceCode,
destination: refactoredCode,
algorithm: .optimus
)
// Result: Detailed operations, semantic understanding

๐Ÿง  Megatron Algorithm

Semantic O(n log n) Balanced

Advanced semantic analysis with balanced performance and accuracy. The default choice for most applications requiring detailed diff analysis.

Create Time 47.8ms
Apply Time 7.0ms
Operations 1256
Accuracy Excellent
// Megatron: Semantic analysis (default)
let diff = MultiLineDiff.createDiff(
source: source,
destination: destination,
algorithm: .megatron
)
// Result: Balanced performance and accuracy

Documentation

Comprehensive guides and API reference

๐Ÿš€

Quick Start

Get up and running with MultiLineDiff in minutes. Installation, basic usage, and first examples.

๐Ÿค–

ASCII Diff Format

Learn the revolutionary ASCII diff format with ๐Ÿ“ŽโŒโœ… symbols for AI integration and human readability.

โšก

Flash & Optimus

Deep dive into the fastest algorithms: Flash (14.5ms) and Optimus (line-aware) with Swift native methods.

๐Ÿ”ง

Enhanced Parser

Advanced ASCII parser with metadata capture, source reconstruction, and location tracking.

๐ŸŒŸ

Revolutionary Features

Complete feature overview: cryptographic security, undo generation, and superiority over Git diff.

๐Ÿ“–

API Reference

Complete Swift API documentation with all methods, parameters, and return types.

๐Ÿš€ Quick Start Guide

Installation

// Add to Package.swift
dependencies: [
    .package(url: "https://github.com/codefreezeai/swift-multi-line-diff", from: "2.0.1")
]

Basic Usage

import MultiLineDiff

// Create a diff between two strings
let source = "Hello, world!"
let destination = "Hello, Swift!"

let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .flash  // Fastest algorithm
)

// Apply the diff
let result = try MultiLineDiff.applyDiff(to: source, diff: diff)
print(result) // "Hello, Swift!"

AI-Friendly ASCII Format

// Generate ASCII diff for AI
let asciiDiff = MultiLineDiff.createAndDisplayDiff(
    source: source,
    destination: destination,
    format: .ai
)

print(asciiDiff)
// Output:
// ๐Ÿ“Ž Hello, 
// โŒ world
// โœ… Swift
// ๐Ÿ“Ž !

Round-Trip Workflow

// Parse ASCII diff back to operations
let parsedDiff = try MultiLineDiff.parseDiffFromASCII(asciiDiff)

// Apply parsed diff
let finalResult = try MultiLineDiff.applyDiff(to: source, diff: parsedDiff)
// Result: 100% accuracy guaranteed!

๐Ÿค– ASCII Diff Format

Symbol Rules

IMPORTANT: All diff symbols are EXACTLY two characters:

  • ๐Ÿ“Ž (Paperclip + space): Retained/unchanged lines
  • โŒ (Red X + space): Lines to be removed
  • โœ… (Green checkmark + space): Lines to be added

Visual Meaning

Symbol Operation Visual Meaning Description
๐Ÿ“Ž Retain ๐Ÿ“Ž Paperclip Unchanged lines - "keeps code together"
โŒ Delete โŒ Red X Lines to be removed - "delete this"
โœ… Insert โœ… Green checkmark New lines to be added - "add this"

Exoplanet Example

๐Ÿ“Ž class UserManager {
๐Ÿ“Ž     private var users: [String: User] = [:]
โœ…     private var userCount: Int = 0
๐Ÿ“Ž     
โŒ     func addUser(name: String, email: String) -> Bool {
โœ…     func addUser(name: String, email: String, age: Int = 0) -> Result {
๐Ÿ“Ž         guard !name.isEmpty && !email.isEmpty else {
โŒ             return false
โœ…             return .failure(.invalidInput)
๐Ÿ“Ž         }
๐Ÿ“Ž         
โŒ         let user = User(name: name, email: email)
โœ…         let user = User(id: UUID(), name: name, email: email, age: age)
๐Ÿ“Ž         users[email] = user
โŒ         return true
โœ…         userCount += 1
โœ…         return .success(user)
๐Ÿ“Ž     }
๐Ÿ“Ž }

AI Integration Benefits

  • Human Readable: Instantly understand changes
  • AI Parseable: Perfect for LLM integration
  • Version Control: Git-friendly format
  • Documentation: Self-documenting patches
  • Debugging: Visual diff inspection

๐Ÿ“– View Complete ASCII Diff Documentation โ†’

โšก Flash & Optimus Algorithms

Performance Comparison

Algorithm Create (ms) Apply (ms) Total (ms) Operations Type
โšก Flash 14.5 6.6 21.0 3 Swift Native
๐Ÿค– Optimus 43.7 6.6 50.3 1256 CollectionDiff

โšก Flash Algorithm

The fastest diff algorithm using Swift's native string manipulation methods (commonPrefix, commonSuffix).

// Flash Algorithm Usage
let diff = MultiLineDiff.createDiff(
    source: "Hello, Universe!",
    destination: "Hello, Swift!",
    algorithm: .flash
)

// Flash identifies:
// Prefix: "Hello, " (7 chars) โ†’ RETAIN
// Middle: "world" โ†’ DELETE, "Swift" โ†’ INSERT  
// Suffix: "!" (1 char) โ†’ RETAIN

๐Ÿค– Optimus Algorithm

Combines the power of CollectionDifference with line-aware processing.

// Optimus Algorithm Usage
let diff = MultiLineDiff.createDiff(
    source: sourceCode,
    destination: modifiedCode,
    algorithm: .optimus
)

// Optimus Process:
// 1. Split text into lines preserving line endings
// 2. Use CollectionDifference to find line changes
// 3. Convert to character-based operations
// 4. Consolidate consecutive operations

Algorithm Selection Guide

๐Ÿš€ Choose Flash When:
  • Speed is critical
  • Simple character-level changes
  • Memory constrained environments
  • Want minimal operations
๐Ÿค– Choose Optimus When:
  • Working with code/structured text
  • Need detailed operation tracking
  • Want semantic understanding
  • Require line-aware processing

๐Ÿ“– View Complete Algorithm Documentation โ†’

๐Ÿ”ง Enhanced ASCII Parser

New Features Added

  • ๐Ÿ“ Source Content Capture: Reconstructs complete source text
  • ๐Ÿ“ Destination Content Capture: Reconstructs complete destination text
  • ๐Ÿ“ Preceding Context: Captures the first line of the source
  • ๐Ÿ“ Following Context: Captures the last line of the source
  • ๐ŸŽฏ Source Start Line: Identifies exactly where modifications begin
  • ๐Ÿ“Š Source Total Lines: Total number of lines in the source

Source Start Line Explanation

The sourceStartLine pinpoints exactly where modifications begin:

Line 1: ๐Ÿ“Ž class Calculator {        (retain)
Line 2: ๐Ÿ“Ž     private var result... (retain)
Line 3: โŒ     func add(_ value...   (delete) โ† MODIFICATIONS START HERE
Line 4: โŒ         result += value   (delete)
Line 5: โŒ     }                     (delete)
Line 6: โœ…     func add(_ value...   (insert)
Line 7: โœ…         result += value   (insert)
Line 8: โœ…         return result     (insert)
Line 9: โœ…     }                     (insert)

// Result: sourceStartLine = 2 (0-indexed, displayed as Line 3)

Enhanced Metadata Structure

DiffMetadata(
    sourceStartLine: 2,                    // NEW: Where modifications begin
    sourceTotalLines: 9,                   // Total source lines
    precedingContext: "class Calculator {", // First line of source
    followingContext: "}",                 // Last line of source
    sourceContent: "class Calculator {\n...", // Complete source
    destinationContent: "class Calculator {\n...", // Complete destination
    algorithmUsed: .megatron,
    applicationType: .requiresFullSource
)

Practical Benefits

๐Ÿค– AI Integration

Full source/destination content for validation and context information for intelligent patch application.

๐Ÿ“ Location Tracking

Precise positioning for patch application with context helps locate diffs in large files.

โœ… Verification

Complete source/destination reconstruction with checksum validation support.

โ†ฉ๏ธ Undo Operations

Create reverse diffs with stored content and full context preservation for rollback scenarios.

๐Ÿ“– View Complete Parser Documentation โ†’

๐ŸŒŸ Revolutionary Features

๐Ÿš€ Revolutionary Breakthrough

MultiLineDiff isn't just another diff toolโ€”it's a complete paradigm shift that makes Git diff, Myers algorithm, copy-paste, line-number edits, and search-replace look like stone-age tools.

๐Ÿ”ฎ Unique Innovations Not Found Anywhere Else

๐Ÿ”ฎ Intelligent Algorithm Convergence

FIRST: Two completely different algorithms (Flash & Optimus) produce identical character counts and results while using entirely different approaches.

// Flash: 3 operations, 14.5ms
// Optimus: 1256 operations, 43.7ms  
// IDENTICAL RESULTS: 100% character-perfect match
๐Ÿง  Automatic Source Type Detection

FIRST: Automatically detects whether you're applying a diff to full source document, truncated section, or partial content. No manual parameters needed.

๐Ÿ” Built-in SHA256 Integrity Verification

SECURITY BREAKTHROUGH: Every diff includes cryptographic verification with SHA256 hash, automatic integrity checking, tamper detection, and round-trip verification.

โ†ฉ๏ธ Automatic Undo Generation

FIRST: Automatic reverse diff creation for instant rollback capability with zero configuration.

let undoDiff = MultiLineDiff.createUndoDiff(from: originalDiff)
// Instant rollback capability with zero configuration

๐Ÿ† Superiority Over Existing Solutions

Feature Git Diff D1F MultiLineDiff
Accuracy Line-based approximation Character-perfect precision
Context Static line numbers Dynamic context matching
Verification None SHA256 + checksum
Undo Manual reverse patches Automatic undo generation
AI Integration None Native ASCII diff parsing

๐ŸŽฏ The Bottom Line

D1F MultiLineDiff isn't just better than Git diff, Myers algorithm, copy-paste, line edits, or search-replaceโ€”it makes them obsolete.

This is the first and only diffing system that:

  • โœ… Preserves every character perfectly
  • โœ… Handles truncated patches intelligently
  • โœ… Provides cryptographic verification
  • โœ… Generates automatic undo operations
  • โœ… Works seamlessly with AI systems
  • โœ… Offers multiple algorithms for any need
  • โœ… Supports all I/O formats
  • โœ… Maintains complete metadata

๐Ÿ“– View Complete Features Documentation โ†’

๐Ÿ“– API Reference

Core Methods

createDiff
public static func createDiff(
    source: String,
    destination: String,
    algorithm: DiffAlgorithm = .megatron,
    includeMetadata: Bool = true,
    sourceStartLine: Int? = nil,
    destStartLine: Int? = nil
) -> DiffResult

Creates a diff between two strings using advanced diffing algorithms.

applyDiff
public static func applyDiff(
    to source: String,
    diff: DiffResult
) throws -> String

Applies a diff to a source string with automatic truncated source detection.

createAndDisplayDiff
public static func createAndDisplayDiff(
    source: String,
    destination: String,
    format: DiffDisplayFormat,
    algorithm: DiffAlgorithm = .megatron
) -> String

Creates and displays a diff in one convenient call.

parseDiffFromASCII
public static func parseDiffFromASCII(_ asciiDiff: String) throws -> DiffResult

Parses ASCII diff text back into a DiffResult for AI integration.

Algorithms

public enum DiffAlgorithm {
    case flash      // โšก Fastest (14.5ms)
    case optimus    // ๐Ÿค– Line-aware CollectionDiff
    case megatron   // ๐Ÿง  Semantic analysis (default)
    case zoom       // ๐Ÿ” Simple character-based
}

Display Formats

public enum DiffDisplayFormat {
    case ai         // Plain ASCII output for AI models
}

Encoding Formats

public enum DiffEncoding {
    case base64     // Base64 encoded string
    case jsonString // JSON string representation
    case jsonData   // JSON data object
}

Example Usage

import MultiLineDiff

// Basic diff creation
let diff = MultiLineDiff.createDiff(
    source: "Hello, D1F!",
    destination: "Hello, Swift!",
    algorithm: .flash
)

// Apply diff
let result = try MultiLineDiff.applyDiff(to: source, diff: diff)

// ASCII format for AI
let asciiDiff = MultiLineDiff.createAndDisplayDiff(
    source: source,
    destination: destination,
    format: .ai
)

// Parse ASCII diff
let parsedDiff = try MultiLineDiff.parseDiffFromASCII(asciiDiff)

// Base64 encoding
let base64Diff = try MultiLineDiff.createBase64Diff(
    source: source,
    destination: destination
)

๐Ÿ“– View Complete Source Code โ†’

Performance Benchmarks

Out of this world testing

Environment: Mac Mini M4 โ€ข 16TB RAM โ€ข Xcode 16.3

Methodology: 1000 runs โ€ข 5000-line files

Range: 3-1256 operations

Created by: Todd Bruss, D1F.ai

Algorithm Performance Comparison

Detailed Benchmarks

Algorithm Create (ms) Apply (ms) Total (ms) Operations Complexity
โšก Flash 14.5 6.6 21.0 3 O(n)
๐Ÿ” Zoom 23.9 9.1 33.0 4 O(n)
๐Ÿค– Optimus 43.7 6.6 50.3 1256 O(n log n)
๐Ÿง  Megatron 47.8 7.0 54.8 1256 O(n log n)

Revolutionary Features

Innovations not found anywhere else in the Milkyway

โšก

Lightning Fast Performance

Flash algorithm delivers 10x faster performance than traditional methods with O(n) complexity and minimal memory usage.

14.5ms create 6.6ms apply
๐Ÿค–

AI-Native Integration

First diffing system designed for AI interaction with human-readable ASCII format and round-trip accuracy.

๐Ÿ“Ž โŒ โœ… symbols for instant AI understanding
๐Ÿ”

Cryptographic Security

Built-in SHA256 integrity verification, tamper detection, and automatic undo generation for enterprise security.

SHA256 + Checksum + Verification
๐ŸŽฏ

Intelligent Context Matching

Dual context matching with confidence scoring handles truncated patches and repeated content intelligently.

Auto-detects full vs. partial source
๐Ÿ”„

Perfect Round-Trip

100% accuracy with zero data loss through complete ASCII workflow: Create โ†’ Display โ†’ Parse โ†’ Apply.

Character-perfect preservation
๐Ÿ“Š

Multiple I/O Formats

JSON, Base64, ASCII formats with compact encoding and cross-platform compatibility for any use case.

JSON Base64 ASCII

๐Ÿš€ Algorithm Performance Showdown

D1F vs. Myers comparison

โšก Flash O(n)
๐Ÿค– Optimus O(n log n)
๐ŸŒ Myers Typical O(nโˆšn)
๐Ÿฆ• Myers Worst O(nยฒ)