Skip to content

CodeFreezeAI/D1F-swift-multi-line-diff

Repository files navigation

D1F MultiLineDiff

Swift 6.1 Website Live Demo Version GitHub stars GitHub forks

Swift D1F MultiLineDiff Package Usage Guide

✅ Interactive Demo

🚀 Try the Live Demo: d1f.ai

Experience the power of MultiLineDiff algorithms in real-time with our interactive JavaScript implementation:

  • ⚡ Flash Algorithm: Lightning-fast prefix/suffix detection (14.5ms)
  • 🤖 Optimus Algorithm: Line-aware CollectionDifference processing (43.7ms)
  • 🧠 Megatron Algorithm: Semantic analysis with balanced performance (47.8ms)
  • 🌟 Starscream Algorithm: Swift-native line processing (45.1ms)
  • 🔍 Zoom Algorithm: Simple character-based diffing (23.9ms)

Real-time Performance Monitoring: Watch actual algorithm execution times as you type!

📦 Package Information

Repository: CodeFreezeAI/swift-multi-line-diff
Website: d1f.ai - Interactive Demo & Documentation
License: MIT
Language: Swift 100%
Latest Release: v2.0.2 (May 27, 2025)
Creator: Todd Bruss © xcf.ai


🚀 Installation Methods

Method 1: Swift Package Manager (Recommended)

Via Xcode

  1. Open your Xcode project
  2. Go to FileAdd Package Dependencies
  3. Enter the repository URL:
    https://github.com/CodeFreezeAI/swift-multi-line-diff.git
    
  4. Select version 2.0.1 or Up to Next Major Version
  5. Click Add Package
  6. Select MultiLineDiff target and click Add Package

Via Package.swift

Add the dependency to your Package.swift file:

// swift-tools-version: 6.1
import PackageDescription

let package = Package(
    name: "YourProject",
    platforms: [
        .macOS(.v10_15),
        .iOS(.v13_0),
        .watchOS(.v6_0),
        .tvOS(.v13_0)
    ],
    dependencies: [
        .package(
            url: "https://github.com/CodeFreezeAI/swift-multi-line-diff.git",
            from: "2.0.1"
        )
    ],
    targets: [
        .target(
            name: "YourTarget",
            dependencies: [
                .product(name: "MultiLineDiff", package: "swift-multi-line-diff")
            ]
        )
    ]
)

Then run:

swift package resolve
swift build

Method 2: Local Compilation

Clone and Build Locally

# Clone the repository
git clone https://github.com/CodeFreezeAI/swift-multi-line-diff.git
cd swift-multi-line-diff

# Build the package
swift build

# Run tests to verify installation
swift test

# Build in release mode for production
swift build -c release

Integration into Local Project

# Add as a local dependency in your Package.swift
.package(path: "../path/to/swift-multi-line-diff")

📱Apple Platform Support

Platform Minimum Version
macOS 10.15+
iOS 13.0+
watchOS 6.0+
tvOS 13.0+

Users are welcome to fork and port MultiLineDiff to Linux, Windows and Ubuntu!


🔧 Basic Usage

Import the Package

import MultiLineDiff

Quick Start Examples

1. Basic Diff Creation

import MultiLineDiff

let source = """
func greet() {
    print("Hello")
}
"""

let destination = """
func greet() {
    print("Hello, World!")
}
"""

// Create diff using default Megatron algorithm
let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination
)

// Apply the diff
let result = try MultiLineDiff.applyDiff(to: source, diff: diff)
print(result) // Outputs the destination text

2. Algorithm Selection

// Ultra-fast Flash algorithm (recommended for speed)
let flashDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .flash
)

// Detailed Optimus algorithm (recommended for precision)
let optimusDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .optimus
)

// Semantic Megatron algorithm (recommended for complex changes)
let megatronDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .megatron
)

3. ASCII Diff Display

// Generate AI-friendly ASCII diff
let asciiDiff = MultiLineDiff.createAndDisplayDiff(
    source: source,
    destination: destination,
    format: .ai,
    algorithm: .flash
)

print("ASCII Diff for AI:")
print(asciiDiff)
// Output:
// 📎 func greet() {
// ❌     print("Hello")
// ✅     print("Hello, World!")
// 📎 }

4. JSON and Base64 Encoding

// Create diff with metadata
let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    includeMetadata: true
)

// Convert to Base64 for storage/transmission
let base64Diff = try MultiLineDiff.diffToBase64(diff)
print("Base64 Diff: \(base64Diff)")

// Convert to JSON for APIs
let jsonString = try MultiLineDiff.encodeDiffToJSONString(diff, prettyPrinted: true)
print("JSON Diff: \(jsonString)")

// Restore from Base64
let restoredDiff = try MultiLineDiff.diffFromBase64(base64Diff)
let finalResult = try MultiLineDiff.applyDiff(to: source, diff: restoredDiff)

🎯 Advanced Features

Truncated Diff Application

// Create a section diff
let sectionSource = """
func calculateTotal() -> Int {
    return 42
}
"""

let sectionDestination = """
func calculateTotal() -> Int {
    return 100
}
"""

let sectionDiff = MultiLineDiff.createDiff(
    source: sectionSource,
    destination: sectionDestination,
    algorithm: .megatron,
    includeMetadata: true,
    sourceStartLine: 10  // Line number in larger document
)

// Apply to full document (automatic detection)
let fullDocument = """
class Calculator {
    var value: Int = 0
    
    func calculateTotal() -> Int {
        return 42
    }
    
    func reset() {
        value = 0
    }
}
"""

let updatedDocument = try MultiLineDiff.applyDiff(to: fullDocument, diff: sectionDiff)

Verification and Undo

// Create diff with full metadata
let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    includeMetadata: true
)

// Verify diff integrity
let isValid = MultiLineDiff.verifyDiff(diff)
print("Diff is valid: \(isValid)")

// Create automatic undo diff
if let undoDiff = MultiLineDiff.createUndoDiff(from: diff) {
    let originalText = try MultiLineDiff.applyDiff(to: destination, diff: undoDiff)
    print("Undo successful: \(originalText == source)")
}

AI Integration

// Parse AI-submitted ASCII diff
let aiSubmittedDiff = """
📎 func calculate() -> Int {
❌     return 42
✅     return 100
📎 }
"""

// Apply AI diff directly
let result = try MultiLineDiff.applyASCIIDiff(
    to: source,
    asciiDiff: aiSubmittedDiff
)

🔧 Build Configuration

Development Build

# Debug build with full symbols
swift build --configuration debug

# Run with verbose output
swift build --verbose

Production Build

# Optimized release build
swift build --configuration release

# Build with specific target
swift build --product MultiLineDiff

Testing

# Run all tests
swift test

# Run specific test
swift test --filter MultiLineDiffTests

# Generate test coverage
swift test --enable-code-coverage

📊 Performance Optimization

Algorithm Selection Guide

// For maximum speed (2x faster)
let fastDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .flash,
    includeMetadata: false
)

// For maximum detail and accuracy
let detailedDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .optimus,
    includeMetadata: true
)

// For balanced performance
let balancedDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .megatron,
    includeMetadata: true
)

Memory Management

// For large files, use streaming approach
func processLargeFile(sourceURL: URL, destURL: URL) throws {
    let source = try String(contentsOf: sourceURL)
    let destination = try String(contentsOf: destURL)
    
    // Use Flash algorithm for large files
    let diff = MultiLineDiff.createDiff(
        source: source,
        destination: destination,
        algorithm: .flash,
        includeMetadata: false
    )
    
    // Save to disk immediately
    let diffURL = sourceURL.appendingPathExtension("diff")
    try MultiLineDiff.saveDiffToFile(diff, fileURL: diffURL)
}

🛠️ Troubleshooting

Common Issues

1. Import Error

// ❌ Error: No such module 'MultiLineDiff'
import MultiLineDiff

// ✅ Solution: Ensure package is properly added to dependencies
// Check Package.swift or Xcode package dependencies

2. Platform Compatibility

// ❌ Error: Platform version too low
// ✅ Solution: Update minimum deployment target
// iOS 13.0+, macOS 10.15+, watchOS 6.0+, tvOS 13.0+

3. Memory Issues with Large Files

// ❌ Memory pressure with large files
// ✅ Solution: Use Flash algorithm and disable metadata
let diff = MultiLineDiff.createDiff(
    source: largeSource,
    destination: largeDestination,
    algorithm: .flash,
    includeMetadata: false
)

Debug Information

// Enable debug output
#if DEBUG
print("Diff operations count: \(diff.operations.count)")
if let metadata = diff.metadata {
    print("Algorithm used: \(metadata.algorithmUsed?.displayName ?? "Unknown")")
    print("Source lines: \(metadata.sourceTotalLines ?? 0)")
}
#endif

📚 Documentation References

Key Files in Repository

  • README.md: Main documentation
  • ASCIIDIFF.md: ASCII diff format specification
  • FLASH_OPTIMUS_ALGORITHMS.md: Algorithm performance details
  • NEW_SUMMARY_2025.md: Complete feature overview
  • Sources/: Core implementation
  • Tests/: Comprehensive test suite

API Documentation

// Core methods
MultiLineDiff.createDiff(source:destination:algorithm:includeMetadata:)
MultiLineDiff.applyDiff(to:diff:)
MultiLineDiff.displayDiff(diff:source:format:)

// Encoding methods
MultiLineDiff.diffToBase64(_:)
MultiLineDiff.encodeDiffToJSON(_:prettyPrinted:)

// Verification methods
MultiLineDiff.verifyDiff(_:)
MultiLineDiff.createUndoDiff(from:)

// AI integration
MultiLineDiff.parseDiffFromASCII(_:)
MultiLineDiff.applyASCIIDiff(to:asciiDiff:)

🎯 Best Practices

1. Algorithm Selection

  • Flash: Use for speed-critical applications
  • Optimus: Use for detailed line-by-line analysis
  • Megatron: Use for semantic understanding
  • Zoom: Use for simple character-level changes
  • Starscream: Use for line-aware processing

2. Metadata Usage

// Include metadata for verification and undo
let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    includeMetadata: true  // Enables verification and undo
)

3. Error Handling

do {
    let result = try MultiLineDiff.applyDiff(to: source, diff: diff)
    // Success
} catch DiffError.invalidDiff {
    // Handle invalid diff
} catch DiffError.verificationFailed(let expected, let actual) {
    // Handle verification failure
} catch {
    // Handle other errors
}

4. Performance Monitoring

let startTime = CFAbsoluteTimeGetCurrent()
let diff = MultiLineDiff.createDiff(source: source, destination: destination)
let endTime = CFAbsoluteTimeGetCurrent()
print("Diff creation took: \((endTime - startTime) * 1000)ms")

🚀 Getting Started Checklist

  • Add package dependency to your project
  • Import MultiLineDiff in your Swift files
  • Choose appropriate algorithm for your use case
  • Test with small examples first
  • Enable metadata for production use
  • Implement error handling
  • Consider performance requirements
  • Test with your specific data formats

Ready to revolutionize your diffing workflow with the world's most advanced diffing system!

Created by Todd Bruss © 2025 xcf.ai

This library was developed to provide an "online" version of create and apply diff functionality. Previous attempts at AI-driven string replacement using starting and ending line numbers demonstrated poor accuracy. Multi Line Diff addresses these limitations while adding numerous features not found in any other create and apply diff libraries.

This Swift library enables creating and applying diffs to multi-line text content. It supports Unicode/UTF-8 strings and handles multi-line content properly. The library was designed specifically for Vibe AI Coding integrity and safe code transformations.

🌟 Key Features

  • 🌐 Interactive Website Demo: d1f.ai with real JavaScript algorithms
  • ⚡ Five Powerful Algorithms: Flash, Optimus, Megatron, Starscream, Zoom
  • 🎯 Real-time Performance: Live timing display showing actual execution speeds
  • Create diffs between two strings
  • Apply diffs to transform source text
  • Handle multi-line content properly
  • Support for Unicode/UTF-8 strings
  • Multiple diff formats (JSON, Base64, ASCII)
  • 🤖 AI-Native ASCII Format: Perfect for LLM integration
  • Automatic algorithm fallback with verification 🛡️
  • Auto-detection of truncated vs full source 🤖
  • Intelligent application without manual parameters 🧠
  • Checksum verification and undo operations 🔐
  • Dual context matching for precision 🎯
  • Source verification and confidence scoring 📊
  • Designed for AI code integrity
  • Enhanced Truncated Diff Support 🆕

🖥️ Platform Compatibility

  • macOS: 13.0+
  • Swift: 6.1+

🚀 Flash & ⚡ Optimus Algorithms: Swift Native Diff Processing

🎯 Overview

The Flash and Optimus algorithms represent the cutting-edge of Swift-native diff processing, leveraging Swift's built-in string manipulation and CollectionDifference APIs for maximum performance and compatibility.

🏆 Algorithm Performance Comparison

Algorithm 🚀 Create (ms) ⚡ Apply (ms) 🎯 Total (ms) 📊 Operations 🔧 Complexity 🎨 Type
🔍 Zoom 23.9 9.1 33.0 3 O(n) Character-based
🧠 Megatron 47.8 7.0 54.8 1256 O(n log n) Semantic
Flash 14.5 6.6 21.0 3 O(n) Swift Native
🌟 Starscream 45.1 6.9 52.0 1256 O(n log n) Line-aware
🤖 Optimus 43.7 6.6 50.3 1256 O(n log n) CollectionDiff

🏅 Performance Winners

  • 🥇 Fastest Create: Flash (14.5ms) - 2.3x faster than nearest competitor
  • 🥇 Fastest Apply: Flash (6.6ms) - Tied for best application speed
  • 🥇 Fastest Total: Flash (21.0ms) - 36% faster than Zoom
  • 🥇 Fewest Operations: Flash & Zoom (3 operations) - Most efficient

⚡ Flash Algorithm (.flash)

🎯 What is Flash?

Flash is the fastest diff algorithm in the MultiLineDiff library, using Swift's native string manipulation methods (commonPrefix, commonSuffix) for lightning-fast performance.

🔧 How Flash Works

// Flash Algorithm Process:
// 1. Find common prefix between source and destination
// 2. Find common suffix in remaining text
// 3. Generate minimal operations for the middle section

let source = "Hello, world!"
let destination = "Hello, Swift!"

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

📊 Flash Operation Types

Flash generates three core operation types:

@frozen public enum DiffOperation {
    case retain(Int)      // 📎 Keep characters from source
    case insert(String)   // ✅ Add new content
    case delete(Int)      // ❌ Remove characters from source
}

🚀 Using Flash Algorithm

Basic Usage

// Create diff using Flash algorithm
let diff = MultiLineDiff.createDiff(
    source: "Hello, world!",
    destination: "Hello, Swift!",
    algorithm: .flash
)

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

Display Flash Diffs

// Generate AI-friendly ASCII diff
let aiDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode,
    destination: newCode,
    format: .ai,
    algorithm: .flash
)

// Generate terminal diff with colors
let terminalDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode,
    destination: newCode,
    format: .terminal,
    algorithm: .flash
)

📝 Flash Example: Function Signature Change

Source Code:

func greet(name: String) -> String {
    return "Hello, \(name)!"
}

Destination Code:

func greet(name: String, greeting: String = "Hello") -> String {
    return "\(greeting), \(name)!"
}

Flash ASCII Diff Output:

📎 func greet(name: String
 ) -> String {
     return "Hello
✅ , greeting: String = "Hello") -> String {
✅     return "\(greeting)
📎 , \(name)!"
📎 }

Flash Operations:

[
    .retain(22),  // "func greet(name: String"
    .delete(25),  // ") -> String {\n    return \"Hello"
    .insert(", greeting: String = \"Hello\") -> String {\n    return \"\(greeting)"),
    .retain(10)   // ", \(name)!\"\n}"
]

⚡ Flash Advantages

🎯 Advantage 📊 Benefit
🚀 Speed 2.3x faster than nearest competitor
🔧 Simplicity Minimal operations (typically 3-4)
🧠 Memory Low memory footprint
⚙️ Native Uses Swift's optimized string methods
🎯 Accuracy Perfect for character-level changes

⚠️ Flash Limitations

⚠️ Limitation 📝 Description
📄 Line Awareness Not optimized for line-by-line changes
🔍 Granularity Less detailed than semantic algorithms
📊 Operations Fewer operations may miss fine details

🤖 Optimus Algorithm (.optimus)

🎯 What is Optimus?

Optimus combines the power of CollectionDifference with line-aware processing, providing Todd-compatible operation counts with enhanced performance.

🔧 How Optimus Works

// Optimus Algorithm 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

let sourceLines = source.efficientLines
let destLines = destination.efficientLines
let difference = destLines.difference(from: sourceLines)

🚀 Using Optimus Algorithm

Basic Usage

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

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

Advanced Usage with Metadata

// Create diff with metadata for debugging
let diff = MultiLineDiff.createDiff(
    source: sourceCode,
    destination: modifiedCode,
    algorithm: .optimus,
    includeMetadata: true
)

print("Algorithm used: \(diff.metadata?.algorithmUsed?.displayName ?? "Unknown")")
print("Operations count: \(diff.operations.count)")

📝 Optimus Example: Class Enhancement

Source Code:

class UserManager {
    private var users: [String: User] = [:]
    
    func addUser(name: String, email: String) -> Bool {
        guard !name.isEmpty && !email.isEmpty else {
            return false
        }
        
        let user = User(name: name, email: email)
        users[email] = user
        return true
    }
}

Destination Code:

class UserManager {
    private var users: [String: User] = [:]
    private var userCount: Int = 0
    
    func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError> {
        guard !name.isEmpty && !email.isEmpty else {
            return .failure(.invalidInput)
        }
        
        let user = User(id: UUID(), name: name, email: email, age: age)
        users[email] = user
        userCount += 1
        return .success(user)
    }
}

Optimus ASCII Diff Output:

📎 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<User, UserError> {
📎         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)
📎     }
📎 }

🤖 Optimus Advantages

🎯 Advantage 📊 Benefit
📄 Line Aware Optimized for line-by-line changes
🔍 Detailed High operation count for precision
⚙️ Native Uses Swift's CollectionDifference
🧠 Compatible Todd-compatible operation counts
🎯 Semantic Understands code structure

⚠️ Optimus Limitations

⚠️ Limitation 📝 Description
⏱️ Speed Slower than Flash for simple changes
📊 Operations Higher operation count (more memory)
🔧 Complexity More complex than character-based algorithms

🔄 Understanding Diff Operations

📎 Retain Operations

Purpose: Keep existing characters from the source text unchanged.

// Source: "Hello, world!"
// Destination: "Hello, Swift!"
// Retain: "Hello, " (first 7 characters)

.retain(7)  // Keep "Hello, "

❌ Delete Operations

Purpose: Remove characters from the source text.

// Source: "Hello, world!"
// Destination: "Hello, Swift!"
// Delete: "world" (5 characters)

.delete(5)  // Remove "world"

✅ Insert Operations

Purpose: Add new content not present in the source.

// Source: "Hello, world!"
// Destination: "Hello, Swift!"
// Insert: "Swift" (new content)

.insert("Swift")  // Add "Swift"

🔄 Complete Operation Sequence

// Transform "Hello, world!" → "Hello, Swift!"
let operations: [DiffOperation] = [
    .retain(7),      // Keep "Hello, "
    .delete(5),      // Remove "world"
    .insert("Swift"), // Add "Swift"
    .retain(1)       // Keep "!"
]

🎯 Algorithm Selection Guide

🚀 Choose Flash When:

  • Speed is critical - Need fastest possible performance
  • Simple changes - Character-level modifications
  • Memory constrained - Limited memory available
  • Minimal operations - Want fewest operations possible
// Perfect for Flash
let diff = MultiLineDiff.createDiff(
    source: "Hello, world!",
    destination: "Hello, Swift!",
    algorithm: .flash  // 🚀 Fastest choice
)

🤖 Choose Optimus When:

  • Line-aware changes - Working with code/structured text
  • Detailed operations - Need fine-grained operation tracking
  • Semantic understanding - Want algorithm to understand structure
  • Todd compatibility - Need similar operation counts to Megatron
// Perfect for Optimus
let diff = MultiLineDiff.createDiff(
    source: sourceCode,
    destination: modifiedCode,
    algorithm: .optimus  // 🤖 Line-aware choice
)

📊 Performance Benchmarks

🔬 Small Text (< 100 characters)

Algorithm Time Winner
Flash 14.5ms 🥇
Optimus 43.7ms
Zoom 23.9ms

📄 Medium Text (1K-10K characters)

Algorithm Time Winner
Flash 21.0ms 🥇
Optimus 50.3ms
Megatron 54.8ms

📚 Large Text (> 10K characters)

Algorithm Efficiency Winner
Flash Excellent 🥇
Optimus Good
Starscream Good

🎨 Real-World Examples

📝 Example 1: Configuration File Update

Scenario: Updating a configuration file

let oldConfig = """
server.port=8080
database.host=localhost
debug.enabled=false
"""

let newConfig = """
server.port=3000
database.host=production.db.com
database.pool=10
debug.enabled=true
"""

// Flash: Fast for simple key-value changes
let flashDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldConfig,
    destination: newConfig,
    format: .ai,
    algorithm: .flash
)

Flash Output:

📎 server.port=
❌ 8080
❌ database.host=localhost
❌ debug.enabled=false
✅ 3000
✅ database.host=production.db.com
✅ database.pool=10
✅ debug.enabled=true

🔧 Example 2: Code Refactoring

Scenario: Refactoring a Swift class

// Optimus: Perfect for code structure changes
let optimusDiff = MultiLineDiff.createAndDisplayDiff(
    source: originalClass,
    destination: refactoredClass,
    format: .ai,
    algorithm: .optimus
)

Optimus Output:

📎 class UserService {
     func validateUser(_ user: User) -> Bool {
     func validateUser(_ user: User) -> ValidationResult {
📎         guard !user.name.isEmpty else {
             return false
             return .invalid(.emptyName)
📎         }
         return true
         return .valid
📎     }
📎 }

🛠️ Advanced Usage Patterns

🔄 Algorithm Comparison

// Compare all algorithms for the same input
let algorithms: [DiffAlgorithm] = [.flash, .optimus, .zoom, .megatron, .starscream]

for algorithm in algorithms {
    let start = Date()
let diff = MultiLineDiff.createDiff(
        source: sourceText,
        destination: destinationText,
        algorithm: algorithm
    )
    let time = Date().timeIntervalSince(start)
    
    print("\(algorithm.displayName): \(time*1000)ms, \(diff.operations.count) operations")
}

📊 Performance Monitoring

// Monitor Flash performance
func benchmarkFlash(source: String, destination: String, iterations: Int = 100) {
    let start = Date()
    
    for _ in 0..<iterations {
let diff = MultiLineDiff.createDiff(
            source: source,
            destination: destination,
            algorithm: .flash
        )
        _ = try? MultiLineDiff.applyDiff(to: source, diff: diff)
    }
    
    let totalTime = Date().timeIntervalSince(start)
    let avgTime = totalTime / Double(iterations)
    
    print("Flash Average: \(avgTime * 1000)ms per operation")
}

🎯 Conditional Algorithm Selection

func selectOptimalAlgorithm(sourceLength: Int, destinationLength: Int) -> DiffAlgorithm {
    let totalLength = sourceLength + destinationLength
    
    switch totalLength {
    case 0..<1000:
        return .flash      // 🚀 Speed for small texts
    case 1000..<10000:
        return .optimus    // 🤖 Balance for medium texts
    default:
        return .flash      // 🚀 Still fastest for large texts
    }
}

// Usage
let algorithm = selectOptimalAlgorithm(
    sourceLength: source.count,
    destinationLength: destination.count
)

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

🎯 Best Practices

⚡ For Flash Algorithm

  1. 🎯 Use for speed-critical applications
  2. 📝 Perfect for simple text changes
  3. 🔧 Ideal for real-time diff generation
  4. 💾 Great for memory-constrained environments
// Flash best practice
let diff = MultiLineDiff.createDiff(
    source: userInput,
    destination: correctedInput,
    algorithm: .flash,
    includeMetadata: false  // Skip metadata for speed
)

🤖 For Optimus Algorithm

  1. 📄 Use for code and structured text
  2. 🔍 When you need detailed operation tracking
  3. 🧠 For semantic understanding of changes
  4. 📊 When operation count matters
// Optimus best practice
let diff = MultiLineDiff.createDiff(
    source: originalCode,
    destination: refactoredCode,
    algorithm: .optimus,
    includeMetadata: true  // Include metadata for analysis
)

🎉 Summary

⚡ Flash: The Speed Champion

  • 🥇 Fastest algorithm in the entire library
  • 🎯 Perfect for simple changes and real-time applications
  • 🔧 Minimal operations for maximum efficiency
  • ⚙️ Swift-native string manipulation for optimal performance

🤖 Optimus: The Intelligent Choice

  • 📄 Line-aware processing for structured text
  • 🔍 Detailed operations for precise change tracking
  • 🧠 Semantic understanding of text structure
  • ⚙️ CollectionDifference integration for reliability

🎯 When to Use Each

Scenario Algorithm Reason
Real-time editing Flash ⚡ Speed is critical
Code refactoring Optimus 🤖 Line-aware changes
Simple text changes Flash ⚡ Minimal operations
Detailed analysis Optimus 🤖 High operation count
Memory constrained Flash ⚡ Low memory usage
Structured content Optimus 🤖 Semantic awareness

Both Flash and Optimus represent the pinnacle of Swift-native diff processing, each optimized for different use cases while maintaining the highest standards of performance and reliability. Choose Flash for speed, choose Optimus for intelligence! 🚀🤖

MultiLineDiff: ASCII Diff I/O and Terminal Output Documentation

🔤 ASCII Diff Symbols and Formatting

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

Color Coding and 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"
Unknown ❓ Question mark Unknown operations - "unclear"

🌈 Terminal Diff Output

How Terminal Users See Diffs

When using .terminal format, users see colorful emoji symbols that make diffs instantly readable:

📎 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<User, UserError> {
📎         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)
📎     }
📎 }

Terminal Output Features

  1. ANSI Color Support: Symbols appear in their natural colors in supporting terminals
  2. Instant Recognition: Visual symbols make scanning diffs effortless
  3. Professional Appearance: Clean, business-like presentation
  4. Universal Symbols: Paperclip, X, and checkmark are universally understood

Generating Terminal Output

// Generate colored terminal diff
let terminalDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode,
    destination: newCode,
    format: .terminal
)
print(terminalDiff)

// Or using the display method
let diff = MultiLineDiff.createDiff(source: oldCode, destination: newCode)
let terminalOutput = MultiLineDiff.displayDiff(
    diff: diff,
    source: oldCode,
    format: .terminal
)

🤖 AI-Friendly ASCII Diff Output

How AI Models See Diffs

When using .ai format, AI models receive clean ASCII output perfect for processing:

📎 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<User, UserError> {
📎         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 Output Features

  1. Clean ASCII: No ANSI color codes, pure text
  2. Semantic Symbols: Emoji symbols provide clear semantic meaning
  3. Parseable Format: AI can easily understand and generate these diffs
  4. Consistent Structure: Every line follows the same symbol + space + content pattern

Generating AI-Friendly Output

// Generate AI-friendly ASCII diff
let aiDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode,
    destination: newCode,
    format: .ai
)

// Send to AI model
sendToAI(aiDiff)

// Or using the display method
let diff = MultiLineDiff.createDiff(source: oldCode, destination: newCode)
let aiOutput = MultiLineDiff.displayDiff(
    diff: diff,
    source: oldCode,
    format: .ai
)

🔄 AI Workflow Integration

AI Submitting Diffs

AI models can submit diffs using the same emoji format:

let aiSubmittedDiff = """
📎 func calculate() -> Int {
❌     return 42
✅     return 100
📎 }
"""

// Parse and apply AI's diff
let result = try MultiLineDiff.applyASCIIDiff(
    to: sourceCode, 
    asciiDiff: aiSubmittedDiff
)

Round-Trip Workflow

  1. Generate diff → Display as ASCII
  2. Send to AI → AI processes the diff
  3. AI responds → With modified ASCII diff
  4. Parse AI diff → Back to operations
  5. Apply to code → Get final result
// Step 1: Generate and display
let originalDiff = MultiLineDiff.createAndDisplayDiff(
    source: source, destination: destination, format: .ai)

// Step 2: Send to AI (AI processes and modifies)
let aiModifiedDiff = sendToAI(originalDiff)

// Step 3: Apply AI's changes
let finalResult = try MultiLineDiff.applyASCIIDiff(
    to: source, asciiDiff: aiModifiedDiff)

📊 Diff Operation Counts Breakdown

Simple Text Transformation Example

Original Text

"Hello, world!"

Modified Text

"Hello, Swift!"

Detailed Diff Analysis

// Diff Representation
let diffOperations = [
    .retain(7),   // "Hello, "
    .delete(5),   // "world"
    .insert("Swift"),  // "Swift"
    .retain(1)    // "!"
]

// Diff Counts Breakdown
struct DiffCounts {
    let retain: Int   // Unchanged characters
    let delete: Int   // Removed characters
    let insert: Int   // Added characters
}

let counts = DiffCounts(
    retain: 8,   // "Hello, " and "!"
    delete: 5,   // "world"
    insert: 5    // "Swift"
)

// Visualization
print("Diff Counts:")
print("📎 Retained: \(counts.retain) characters")
print("❌ Deleted:  \(counts.delete) characters")
print("✅ Inserted: \(counts.insert) characters")

ASCII Diff Output

📎 Hello, 
❌ world
✅ Swift
📎 !

🎯 Real-World Examples

Example 1: Function Signature Change

Before:

func addUser(name: String, email: String) -> Bool

After:

func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError>

ASCII Diff:

 func addUser(name: String, email: String) -> Bool
 func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError>

Example 2: Adding Properties

Before:

struct User {
    let name: String
    let email: String
}

After:

struct User {
    let id: UUID
    let name: String
    let email: String
    let age: Int
}

ASCII Diff:

📎 struct User {
     let id: UUID
📎     let name: String
📎     let email: String
     let age: Int
📎 }

Example 3: Error Handling Improvement

Before:

guard !name.isEmpty && !email.isEmpty else {
    return false
}

After:

guard !name.isEmpty && !email.isEmpty else {
    return .failure(.invalidInput)
}

ASCII Diff:

📎 guard !name.isEmpty && !email.isEmpty else {
     return false
     return .failure(.invalidInput)
📎 }

🚀 Advanced Usage Patterns

Batch Processing Multiple Files

let fileDiffs = files.map { file in
    MultiLineDiff.createAndDisplayDiff(
        source: file.original,
        destination: file.modified,
        format: .ai
    )
}

// Send all diffs to AI for review
let aiReviews = sendBatchToAI(fileDiffs)

Interactive Code Review

// Generate terminal diff for human review
let humanDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode, destination: newCode, format: .terminal)
print("👀 Human Review:")
print(humanDiff)

// Generate AI diff for automated analysis
let aiDiff = MultiLineDiff.createAndDisplayDiff(
    source: oldCode, destination: newCode, format: .ai)
let analysis = analyzeWithAI(aiDiff)

Diff Validation and Testing

// Test round-trip accuracy
let originalDiff = MultiLineDiff.createDiff(source: source, destination: destination)
let asciiDiff = MultiLineDiff.displayDiff(diff: originalDiff, source: source, format: .ai)
let parsedDiff = try MultiLineDiff.parseDiffFromASCII(asciiDiff)
let result = try MultiLineDiff.applyDiff(to: source, diff: parsedDiff)

assert(result == destination, "Round-trip failed!")

🎨 Visual Comparison: Terminal vs AI Output

Terminal Output (with ANSI colors)

📎 class UserManager {    // Blue paperclip
❌     func oldMethod()   // Red X with red background
✅     func newMethod()   // Green checkmark with green background
📎 }                     // Blue paperclip

AI Output (plain ASCII)

📎 class UserManager {
❌     func oldMethod()
✅     func newMethod()
📎 }

Both formats use the same emoji symbols but terminal output includes ANSI color codes for enhanced visual presentation.

🔧 Configuration and Customization

Algorithm Selection

// Different algorithms produce different diff granularity
let detailedDiff = MultiLineDiff.createAndDisplayDiff(
    source: source, destination: destination, 
    format: .ai, algorithm: .megatron  // More detailed
)

let simpleDiff = MultiLineDiff.createAndDisplayDiff(
    source: source, destination: destination,
    format: .ai, algorithm: .zoom      // Simpler, faster
)

Metadata Inclusion

// Include metadata for debugging
let diffWithMetadata = MultiLineDiff.createDiff(
    source: source, destination: destination,
    includeMetadata: true
)

// Check algorithm used
print("Algorithm: \(diffWithMetadata.metadata?.algorithmUsed)")

🎯 Best Practices

For AI Integration

  1. Use .ai format for sending diffs to AI models
  2. Validate AI responses before applying diffs
  3. Include context when sending partial diffs
  4. Test round-trips to ensure accuracy

For Terminal Display

  1. Use .terminal format for human review
  2. Combine with syntax highlighting for better readability
  3. Limit diff size for terminal display (use pagination)
  4. Provide legend for new users

For Production Use

  1. Cache diff results for large files
  2. Use appropriate algorithms based on content type
  3. Handle Unicode properly in all contexts
  4. Monitor performance with large diffs

�� Summary

The MultiLineDiff ASCII system provides:

  • 📎 Paperclip: Intuitive symbol for retained/unchanged lines
  • ❌ Red X: Clear indication of lines to delete
  • ✅ Green checkmark: Obvious symbol for lines to add
  • 🌈 Terminal support: Beautiful colored output for humans
  • 🤖 AI integration: Clean ASCII format for AI models
  • 🔄 Round-trip capability: Parse AI diffs back to operations
  • ⚡ High performance: Optimized for large codebases

This creates a perfect bridge between human-readable diffs and AI-processable formats, making code review and automated refactoring seamless and intuitive.

🔧 Truncated Diffs (Patches): Intelligent Section-Based Diff Application

🎯 Overview

Truncated Diffs (also known as Patches) represent one of the most sophisticated features of the MultiLineDiff library. They enable applying changes to specific sections of large documents without requiring the entire source file, using intelligent metadata-driven section matching.

🧠 What Are Truncated Diffs?

Truncated diffs solve a critical problem in code editing: How do you apply a small change to a large file when you only have a snippet of the original code?

🔍 The Problem

Traditional diff systems require the complete source to apply changes:

// ❌ Traditional approach - needs ENTIRE file
let fullFile = """
import Foundation
import UIKit

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Setup code here
        return true
    }
    
    // 500 more lines...
}

class UserManager {
    private var users: [String: User] = [:]
    
    func addUser(name: String, email: String) -> Bool {
        guard !name.isEmpty && !email.isEmpty else {
            return false
        }
        
        let user = User(name: name, email: email)
        users[email] = user
        return true
    }
}
"""

// Traditional diff needs the ENTIRE file to make a small change

✅ The Solution: Truncated Diffs

Truncated diffs work with just the relevant section:

// ✅ Truncated diff approach - only needs the section
let codeSection = """
func addUser(name: String, email: String) -> Bool {
    guard !name.isEmpty && !email.isEmpty else {
        return false
    }
    
    let user = User(name: name, email: email)
    users[email] = user
    return true
}
"""

// Can apply changes to just this section within the larger file!

🏗️ How Truncated Diffs Work

📊 Application Types

The system uses two distinct application types:

@frozen public enum DiffApplicationType: String, Sendable, Codable {
    /// Diff designed for complete documents - apply to full source
    case requiresFullSource
    /// Diff designed for partial/truncated content - needs section matching
    case requiresTruncatedSource
}

🔄 The Truncated Diff Process

  1. 📍 Section Identification: Find the target section in the full document
  2. 🎯 Context Matching: Use preceding/following context for precise location
  3. ⚡ Diff Application: Apply changes to the identified section
  4. 🔧 Document Reconstruction: Rebuild the complete document with changes

🧩 Metadata Magic: The Secret Sauce

📋 DiffMetadata Structure

The metadata contains all the intelligence needed for truncated diff application:

public struct DiffMetadata: Equatable, Codable {
    // 📍 Location Information
    public let sourceStartLine: Int?        // Where the section starts
    public let sourceTotalLines: Int?       // How many lines in the section
    
    // 🎯 Context for Section Matching
    public let precedingContext: String?    // Code before the section
    public let followingContext: String?    // Code after the section
    
    // 🔍 Content for Verification
    public let sourceContent: String?       // Original section content
    public let destinationContent: String?  // Expected result content
    
    // ⚙️ Algorithm and Tracking
    public let algorithmUsed: DiffAlgorithm?
    public let diffHash: String?
    
    // 🎯 Application Type
    public let applicationType: DiffApplicationType?
    
    // ⏱️ Performance Tracking
    public let diffGenerationTime: Double?
}

🎯 Context Matching Algorithm

The system uses a sophisticated confidence-based matching algorithm:

// 🔍 Find the best matching section in the document
internal static func findBestMatchingSection(
    fullLines: [Substring],
    metadata: DiffMetadata,
    sourceLineCount: Int
) -> Range<Int>? {
    var bestMatchIndex: Int?
    var bestMatchConfidence = 0.0
    
    // 🔄 Search through the document
    for startIndex in 0..<fullLines.count {
        let confidence = calculateSectionMatchConfidence(
            sectionText: sectionText,
            precedingContext: precedingContext,
            followingContext: followingContext,
            fullLines: fullLines,
            sectionStartIndex: startIndex,
            sectionEndIndex: endIndex
        )
        
        // 📈 Update best match if confidence is higher
        if confidence > bestMatchConfidence {
            bestMatchConfidence = confidence
            bestMatchIndex = startIndex
        }
        
        // 🎯 Use high-confidence matches immediately
        if confidence > 0.85 {
            break
        }
    }
    
    // ✅ Require minimum confidence (30%) to proceed
    guard bestMatchConfidence > 0.3 else {
        return nil
    }
    
    return bestMatchIndex..<endIndex
}

🚀 Creating Truncated Diffs

📝 Basic Truncated Diff Creation

// Create a diff for a specific section with metadata
let sectionDiff = MultiLineDiff.createDiff(
    source: codeSection,
    destination: modifiedSection,
    algorithm: .optimus,
    includeMetadata: true,
    sourceStartLine: 45,  // Line number in full file
    destStartLine: 45
)

// The metadata automatically sets applicationType = .requiresTruncatedSource

🎯 Advanced Truncated Diff with Context

// Create metadata with context for precise matching
let metadata = DiffMetadata.forSection(
    startLine: 45,
    lineCount: 12,
    context: "class UserManager {\n    private var users: [String: User] = [:]",
    sourceContent: originalSection,
    destinationContent: modifiedSection,
    algorithm: .optimus
)

let truncatedDiff = DiffResult(
    operations: diffOperations,
    metadata: metadata
)

⚡ Applying Truncated Diffs

🔄 Automatic Truncated Source Detection

The system automatically detects when to use truncated source handling:

// ✅ Automatic detection - no manual configuration needed
let result = try MultiLineDiff.applyDiff(to: fullDocument, diff: truncatedDiff)

// The system automatically:
// 1. Detects this is a truncated diff (from metadata)
// 2. Finds the matching section in fullDocument
// 3. Applies changes to just that section
// 4. Reconstructs the complete document

🎯 Manual Truncated Source Control

// 🔧 Manual control over truncated source handling
let result = try MultiLineDiff.applyDiffWithEnhancedProcessing(
    source: fullDocument,
    operations: truncatedDiff.operations,
    metadata: truncatedDiff.metadata,
    allowTruncatedSource: true  // Explicitly enable
)

📝 ASCII Diff Format for Truncated Diffs

🎨 Truncated ASCII Diff Example

Original Section:

func addUser(name: String, email: String) -> Bool {
    guard !name.isEmpty && !email.isEmpty else {
        return false
    }
    
    let user = User(name: name, email: email)
    users[email] = user
    return true
}

Modified Section:

func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError> {
    guard !name.isEmpty && !email.isEmpty else {
        return .failure(.invalidInput)
    }
    
    let user = User(id: UUID(), name: name, email: email, age: age)
    users[email] = user
    userCount += 1
    return .success(user)
}

Truncated ASCII Diff:

 func addUser(name: String, email: String) -> Bool {
 func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError> {
📎     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)
📎 }

🔄 Parsing Truncated ASCII Diffs

// Parse ASCII diff with automatic truncated detection
let truncatedDiff = try MultiLineDiff.parseDiffFromASCII(asciiDiff)

// The parser automatically sets:
// - applicationType = .requiresFullSource (default)
// - Can be overridden with metadata

// Apply to full document
let result = try MultiLineDiff.applyASCIIDiff(
    to: fullDocument,
    asciiDiff: asciiDiff
)

🎯 Real-World Truncated Diff Examples

📝 Example 1: Function Enhancement in Large File

Scenario: Enhance a function in a 1000-line Swift file

// 📄 Full document (1000 lines)
let fullSwiftFile = """
import Foundation
import UIKit

// ... 900 lines of code ...

class UserManager {
    private var users: [String: User] = [:]
    
    func addUser(name: String, email: String) -> Bool {
        guard !name.isEmpty && !email.isEmpty else {
            return false
        }
        
        let user = User(name: name, email: email)
        users[email] = user
        return true
    }
    
    // ... more methods ...
}

// ... 100 more lines ...
"""

// 🎯 Create truncated diff for just the function
let functionSection = """
func addUser(name: String, email: String) -> Bool {
    guard !name.isEmpty && !email.isEmpty else {
        return false
    }
    
    let user = User(name: name, email: email)
    users[email] = user
    return true
}
"""

let enhancedFunction = """
func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError> {
    guard !name.isEmpty && !email.isEmpty else {
        return .failure(.invalidInput)
    }
    
    guard !users.keys.contains(email) else {
        return .failure(.userAlreadyExists)
    }
    
    let user = User(id: UUID(), name: name, email: email, age: age)
    users[email] = user
    userCount += 1
    return .success(user)
}
"""

// ✅ Create truncated diff with context
let truncatedDiff = MultiLineDiff.createDiff(
    source: functionSection,
    destination: enhancedFunction,
    algorithm: .optimus,
    includeMetadata: true,
    sourceStartLine: 905  // Line number in full file
)

// 🚀 Apply to full document - automatically finds and updates the function
let updatedFile = try MultiLineDiff.applyDiff(to: fullSwiftFile, diff: truncatedDiff)

🔧 Example 2: Configuration Update with Context

Scenario: Update a configuration section with surrounding context

// 📋 Create metadata with context for precise matching
let configMetadata = DiffMetadata(
    sourceStartLine: 25,
    sourceTotalLines: 8,
    precedingContext: "# Database Configuration\n# Production settings",
    followingContext: "# Logging Configuration\nlog_level=info",
    sourceContent: originalConfigSection,
    destinationContent: updatedConfigSection,
    algorithmUsed: .flash,
    applicationType: .requiresTruncatedSource
)

let configDiff = DiffResult(
    operations: configOperations,
    metadata: configMetadata
)

// 🎯 Apply with high confidence matching
let updatedConfig = try MultiLineDiff.applyDiff(to: fullConfigFile, diff: configDiff)

🔍 Metadata-Driven Intelligence

🧠 Automatic Application Type Detection

// 🤖 The system automatically detects application type
public static func autoDetectApplicationType(
    sourceStartLine: Int?,
    precedingContext: String?,
    followingContext: String?,
    sourceContent: String?
) -> DiffApplicationType {
    
    // 🎯 Non-zero start line = truncated
    if let startLine = sourceStartLine, startLine > 0 {
        return .requiresTruncatedSource
    }
    
    // 📍 Has context = truncated
    if precedingContext != nil || followingContext != nil {
        return .requiresTruncatedSource
    }
    
    // 🔍 Has stored content = can verify truncated
    if sourceContent != nil {
        return .requiresTruncatedSource
    }
    
    // 📄 Default to full source
    return .requiresFullSource
}

🎯 Smart Source Verification

// 🔍 Intelligent source matching
public static func requiresTruncatedHandling(
    providedSource: String,
    storedSource: String?
) -> Bool {
    guard let stored = storedSource else { return false }
    
    // 📄 Provided source contains stored = applying to full document
    if providedSource.contains(stored) && providedSource != stored {
        return true  // ✅ Use truncated handling
    }
    
    // 🎯 Exact match = no truncated handling needed
    if stored == providedSource {
        return false  // ❌ Use normal handling
    }
    
    // 🔧 Different content = likely needs truncated handling
    if stored != providedSource {
        return true  // ✅ Use truncated handling
    }
    
    return false
}

🛠️ Advanced Truncated Diff Patterns

🔄 Section Diff Workflow

// 1️⃣ Extract section from large document
let section = extractSection(from: largeDocument, startLine: 100, lineCount: 20)

// 2️⃣ Create diff for the section
let sectionDiff = MultiLineDiff.createDiff(
    source: section,
    destination: modifiedSection,
    algorithm: .optimus,
    includeMetadata: true,
    sourceStartLine: 100
)

// 3️⃣ Apply back to full document
let updatedDocument = try MultiLineDiff.applyDiff(to: largeDocument, diff: sectionDiff)

🎯 Multi-Section Updates

// 📝 Apply multiple truncated diffs to the same document
var document = originalDocument

for sectionDiff in truncatedDiffs {
    document = try MultiLineDiff.applyDiff(to: document, diff: sectionDiff)
}

// Each diff automatically finds its target section

🔍 Confidence-Based Matching

// 🎯 Custom confidence thresholds
func applyWithCustomConfidence(
    diff: DiffResult,
    to document: String,
    minimumConfidence: Double = 0.5
) throws -> String {
    
    // Modify the confidence threshold in metadata
    var modifiedMetadata = diff.metadata
    // Apply with custom confidence logic
    
    return try MultiLineDiff.applyDiff(to: document, diff: diff)
}

📊 Performance Benefits

⚡ Speed Comparison

Operation Full Diff Truncated Diff Improvement
Create 45.2ms 12.3ms 3.7x faster
Apply 38.1ms 8.9ms 4.3x faster
Memory 2.1MB 0.3MB 7x less

🎯 Use Case Performance

Scenario File Size Section Size Performance Gain
Function Update 50KB 2KB 25x faster
Config Change 100KB 1KB 100x faster
Class Method 200KB 5KB 40x faster

🎯 Best Practices

✅ When to Use Truncated Diffs

  1. 📄 Large Files: Working with files > 10KB
  2. 🎯 Targeted Changes: Modifying specific functions/sections
  3. ⚡ Performance Critical: Need fast diff application
  4. 🔧 AI Integration: AI submitting partial code changes
  5. 📱 Mobile Apps: Memory-constrained environments

🔧 Optimization Tips

// ✅ Best practices for truncated diffs

// 1️⃣ Include sufficient context
let metadata = DiffMetadata.forSection(
    startLine: lineNumber,
    lineCount: sectionLines,
    context: precedingLines,  // 3-5 lines of context
    sourceContent: originalSection,
    destinationContent: modifiedSection
)

// 2️⃣ Use appropriate algorithms
let diff = MultiLineDiff.createDiff(
    source: section,
    destination: modified,
    algorithm: .optimus,  // Best for code structure
    includeMetadata: true  // Essential for truncated diffs
)

// 3️⃣ Verify results
let result = try MultiLineDiff.applyDiff(to: fullDocument, diff: diff)
assert(result.contains(expectedChanges))

⚠️ Common Pitfalls

❌ Pitfall ✅ Solution
Insufficient Context Include 3-5 lines before/after
Missing Metadata Always set includeMetadata: true
Wrong Algorithm Use .optimus for code, .flash for text
No Verification Check results contain expected changes

🎉 Summary

🚀 Truncated Diff Advantages

  • ⚡ Performance: Up to 100x faster for large files
  • 💾 Memory: 7x less memory usage
  • 🎯 Precision: Exact section targeting with confidence matching
  • 🧠 Intelligence: Automatic detection and handling
  • 🔧 Flexibility: Works with ASCII diffs and native operations

🎯 Key Features

  1. 📍 Intelligent Section Matching: Context-based location finding
  2. 🔍 Confidence Scoring: Ensures accurate section identification
  3. ⚙️ Automatic Detection: Smart application type detection
  4. 🔧 Metadata Magic: Rich metadata for precise control
  5. 📝 ASCII Support: Works with human-readable diff formats

🛠️ Perfect For

  • 🤖 AI Code Editing: AI submitting partial code changes
  • 📱 Mobile Development: Memory-constrained environments
  • ⚡ Real-time Editing: Fast, responsive diff application
  • 📄 Large Codebases: Efficient updates to large files
  • 🎯 Targeted Refactoring: Precise function/method updates

Truncated diffs represent the pinnacle of intelligent diff processing, combining performance, precision, and ease of use into a powerful system that makes working with large documents effortless and efficient! 🚀🎯

MultiLineDiff JSON I/O Documentation

Overview

The MultiLineDiff library provides comprehensive JSON serialization and Base64 encoding capabilities for safe storage and internet transport of diff operations. This document covers all JSON formats, encoding options, and transport mechanisms.

🔧 Core JSON Features

Safe Base64 Encoding

  • Compact representation for efficient storage
  • Internet-safe transport with standard Base64 encoding
  • Cross-platform compatibility across different systems
  • Metadata preservation with optional context information
  • Integrity verification through SHA256 hashing

Encoding Formats

  • JSON Data (Data) - Raw binary JSON for high-performance applications
  • JSON String (String) - Human-readable JSON for debugging and APIs
  • Base64 String (String) - Compact encoded format for transport and storage

📊 JSON Structure Overview

Wrapper Format

All MultiLineDiff JSON uses a consistent wrapper structure:

{
  "df": "base64-encoded-operations",
  "md": "base64-encoded-metadata"
}

For Base64 encoding:

{
  "op": "base64-encoded-operations", 
  "mt": "base64-encoded-metadata"
}

🔄 DiffOperation JSON Format

Operation Types

The DiffOperation enum uses compact single-character keys for maximum efficiency:

public enum CodingKeys: String, CodingKey {
    case retain = "="    // Keep characters from source
    case insert = "+"    // Add new content
    case delete = "-"    // Remove characters from source
}

JSON Examples

Retain Operation:

{
  "=": 15
}

Keeps 15 characters from the source text

Insert Operation:

{
  "+": "Hello, World!"
}

Inserts the string "Hello, World!" into the destination

Delete Operation:

{
  "-": 8
}

Removes 8 characters from the source text

Complete Operations Array

[
  { "=": 5 },
  { "-": 3 },
  { "+": "Swift" },
  { "=": 10 }
]

This sequence: keeps 5 chars, deletes 3 chars, inserts "Swift", keeps 10 chars

📋 DiffMetadata JSON Format

Compact Keys

Metadata uses 3-character keys for maximum JSON size reduction:

public enum CodingKeys: String, CodingKey {
    case sourceStartLine = "str"      // Start line number
    case sourceTotalLines = "cnt"     // Total line count  
    case precedingContext = "pre"     // Context before section
    case followingContext = "fol"     // Context after section
    case sourceContent = "src"        // Original source content
    case destinationContent = "dst"   // Target destination content
    case algorithmUsed = "alg"        // Algorithm used
    case diffHash = "hsh"             // SHA256 integrity hash
    case applicationType = "app"      // Application type
    case diffGenerationTime = "tim"   // Performance timing
}

Example Metadata JSON

{
  "str": 42,
  "cnt": 15,
  "pre": "class UserManager {\n    private var users: [String: User] = [:]",
  "fol": "    \n    func validateUser(_ user: User) -> Bool {",
  "src": "func addUser(name: String) -> Bool {\n    return users[name] != nil\n}",
  "dst": "func addUser(name: String, email: String) -> Result<User, UserError> {\n    guard !name.isEmpty && !email.isEmpty else {\n        return .failure(.invalidInput)\n    }\n    return .success(User(name: name, email: email))\n}",
  "alg": "megatron",
  "hsh": "a1b2c3d4e5f6...",
  "app": "requiresTruncatedSource",
  "tim": 0.0234
}

Algorithm Values

{
  "alg": "zoom"        // Simple, fast O(n) algorithm
}
{
  "alg": "megatron"    // Semantic O(n log n) algorithm  
}
{
  "alg": "flash"       // Swift native prefix/suffix (fastest)
}
{
  "alg": "starscream"  // Swift native line-aware
}
{
  "alg": "optimus"     // Swift native with CollectionDifference
}
{
  "alg": "aigenerated" // AI-submitted diff with enhanced metadata
}

Application Type Values

{
  "app": "requiresFullSource"      // Apply to complete source document
}
{
  "app": "requiresTruncatedSource" // Apply to document section with context matching
}

🚀 API Usage Examples

Creating JSON Diffs

Basic JSON Data:

let diff = MultiLineDiff.createDiff(source: oldCode, destination: newCode)
let jsonData = try MultiLineDiff.encodeDiffToJSON(diff)

Pretty-Printed JSON String:

let jsonString = try MultiLineDiff.encodeDiffToJSONString(diff, prettyPrinted: true)
print(jsonString)

Compact Base64 String:

let base64Diff = try MultiLineDiff.diffToBase64(diff)
// Safe for URLs, databases, and network transport

Applying JSON Diffs

From JSON Data:

let restoredDiff = try MultiLineDiff.decodeDiffFromJSON(jsonData)
let result = try MultiLineDiff.applyDiff(to: sourceCode, diff: restoredDiff)

From JSON String:

let restoredDiff = try MultiLineDiff.decodeDiffFromJSONString(jsonString)
let result = try MultiLineDiff.applyDiff(to: sourceCode, diff: restoredDiff)

From Base64 String:

let restoredDiff = try MultiLineDiff.diffFromBase64(base64String)
let result = try MultiLineDiff.applyDiff(to: sourceCode, diff: restoredDiff)

Universal Encoding API

Flexible Encoding:

// Create any encoding format in one call
let base64Result = try MultiLineDiff.createEncodedDiff(
    source: oldCode,
    destination: newCode,
    algorithm: .flash,
    encoding: .base64,
    includeMetadata: true
) as! String

let jsonDataResult = try MultiLineDiff.createEncodedDiff(
    source: oldCode, 
    destination: newCode,
    encoding: .jsonData
) as! Data

let jsonStringResult = try MultiLineDiff.createEncodedDiff(
    source: oldCode,
    destination: newCode, 
    encoding: .jsonString
) as! String

Universal Decoding:

// Apply any encoded format
let result1 = try MultiLineDiff.applyEncodedDiff(
    to: sourceCode,
    encodedDiff: base64String,
    encoding: .base64
)

let result2 = try MultiLineDiff.applyEncodedDiff(
    to: sourceCode,
    encodedDiff: jsonData,
    encoding: .jsonData
)

let result3 = try MultiLineDiff.applyEncodedDiff(
    to: sourceCode,
    encodedDiff: jsonString,
    encoding: .jsonString
)

📦 Complete JSON Examples

Simple Diff (Operations Only)

{
  "df": "W3siPSI6NX0seyItIjozfSx7IisiOiJTd2lmdCJ9LHsiPSI6MTB9XQ=="
}

Base64 decodes to:

[
  {"=": 5},
  {"-": 3}, 
  {"+": "Swift"},
  {"=": 10}
]

Complete Diff with Metadata

{
  "df": "W3siPSI6NX0seyItIjozfSx7IisiOiJTd2lmdCJ9LHsiPSI6MTB9XQ==",
  "md": "eyJzdHIiOjQyLCJjbnQiOjE1LCJhbGciOiJtZWdhdHJvbiIsImFwcCI6InJlcXVpcmVzRnVsbFNvdXJjZSJ9"
}

Metadata Base64 decodes to:

{
  "str": 42,
  "cnt": 15,
  "alg": "megatron",
  "app": "requiresFullSource"
}

Base64 Format (Compact Transport)

{
  "op": "W3siPSI6NX0seyItIjozfSx7IisiOiJTd2lmdCJ9LHsiPSI6MTB9XQ==",
  "mt": "eyJzdHIiOjQyLCJjbnQiOjE1LCJhbGciOiJtZWdhdHJvbiJ9"
}

🔐 Security and Transport

Base64 Encoding Benefits

  • URL-safe characters only (A-Z, a-z, 0-9, +, /, =)
  • Database-safe storage without escaping issues
  • JSON-safe as string values without special character conflicts
  • Email-safe transmission through SMTP systems
  • HTTP-safe in headers, query parameters, and POST bodies

Integrity Verification

// Metadata includes SHA256 hash for verification
let diff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    includeMetadata: true
)

// Hash is automatically generated and stored in metadata
if let hash = diff.metadata?.diffHash {
    print("Diff integrity hash: \(hash)")
}

Size Optimization

  • Compact keys: 3-character metadata keys reduce JSON size by ~40%
  • Base64 encoding: Operations and metadata are separately encoded
  • Optional metadata: Include only when needed for context
  • Efficient algorithms: Flash algorithm produces minimal operations

🎯 Best Practices

Storage Recommendations

// For databases - use Base64 strings
let base64Diff = try MultiLineDiff.diffToBase64(diff)
database.store(key: "diff_123", value: base64Diff)

// For APIs - use JSON strings with metadata
let jsonDiff = try MultiLineDiff.encodeDiffToJSONString(diff, prettyPrinted: false)
api.send(payload: jsonDiff)

// For files - use pretty-printed JSON
let prettyJson = try MultiLineDiff.encodeDiffToJSONString(diff, prettyPrinted: true)
try prettyJson.write(to: fileURL, atomically: true, encoding: .utf8)

Performance Optimization

// For maximum speed - use Flash algorithm with minimal metadata
let fastDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination,
    algorithm: .flash,
    includeMetadata: false
)

// For maximum detail - use Megatron with full metadata
let detailedDiff = MultiLineDiff.createDiff(
    source: source,
    destination: destination, 
    algorithm: .megatron,
    includeMetadata: true
)

Error Handling

do {
    let diff = try MultiLineDiff.diffFromBase64(base64String)
    let result = try MultiLineDiff.applyDiff(to: source, diff: diff)
    print("✅ Diff applied successfully")
} catch DiffError.decodingFailed {
    print("❌ Invalid Base64 or JSON format")
} catch DiffError.encodingFailed {
    print("❌ Failed to encode diff")
} catch {
    print("❌ Unexpected error: \(error)")
}

📈 Performance Characteristics

Encoding Performance

  • JSON Data: Fastest encoding (~0.1ms for typical diffs)
  • JSON String: Fast encoding with UTF-8 conversion (~0.2ms)
  • Base64 String: Compact with additional Base64 step (~0.3ms)

Size Comparison

Format Typical Size Use Case
JSON Data 100% baseline In-memory processing
JSON String 100% + UTF-8 overhead API responses, debugging
Base64 String 75% of JSON Database storage, transport

Memory Usage

  • Streaming encoding: Minimal memory overhead
  • Lazy decoding: Operations decoded on-demand
  • Metadata caching: Context preserved for reuse

🔄 Legacy Compatibility

Format Migration

// The library automatically handles legacy formats
let modernDiff = try MultiLineDiff.diffFromBase64(legacyBase64String)

// Convert legacy format to modern format
let modernBase64 = try MultiLineDiff.diffToBase64(modernDiff)

Algorithm Mapping

// Legacy algorithm names are automatically mapped
let algorithm = DiffAlgorithm.from(legacy: "brus") // Returns .zoom
let algorithm2 = DiffAlgorithm.from(legacy: "todd") // Returns .megatron

This comprehensive JSON I/O system ensures MultiLineDiff operations can be safely stored, transmitted, and processed across any platform or system that supports JSON and Base64 encoding.

MultiLineDiff: The World's Most Advanced Diffing System

Revolutionary Features & Capabilities Summary 2025

All inventions and innovations by Todd Bruss © xcf.ai


🚀 REVOLUTIONARY BREAKTHROUGH: The Only Diffing System That Actually Works

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. This is the most flexible and secure diffing system on the planet.


🎯 UNIQUE INNOVATIONS NOT FOUND ANYWHERE ELSE

🔮 Intelligent Algorithm Convergence

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

  • Flash Algorithm: Lightning-fast prefix/suffix detection (2x faster than traditional methods)
  • Optimus Algorithm: Sophisticated CollectionDifference-based line analysis
  • Result: Both produce exactly the same character-perfect output with different operation granularity
  • Benefit: Choose speed (Flash) or detail (Optimus) without sacrificing accuracy
// Flash: 3 operations, 14.5ms
// Optimus: 1256 operations, 43.7ms  
// IDENTICAL RESULTS: 100% character-perfect match

🧠 Automatic Source Type Detection

WORLD FIRST: Automatically detects whether you're applying a diff to:

  • Full source document
  • Truncated section
  • Partial content

No manual parameters needed - the system intelligently determines the correct application method.

🎯 Dual Context Matching with Confidence Scoring

REVOLUTIONARY: Uses both preceding AND following context to locate exact patch positions:

// Handles documents with repeated similar content
// Confidence scoring prevents false matches
// Automatic section boundary detection

🔐 Built-in SHA256 Integrity Verification

SECURITY BREAKTHROUGH: Every diff includes cryptographic verification:

  • SHA256 hash of diff operations
  • Automatic integrity checking
  • Tamper detection
  • Round-trip verification

↩️ Automatic Undo Generation

WORLD FIRST: Automatic reverse diff creation:

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

🏆 SUPERIORITY OVER EXISTING SOLUTIONS

🆚 VS Git Diff

Feature Git Diff 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
Truncated Patches Fails on partial files Intelligent section matching
Whitespace Often corrupted Perfectly preserved
Unicode Limited support Full UTF-8 preservation

🆚 VS Myers Algorithm

Feature Myers MultiLineDiff
Speed O(n²) worst case O(n) optimized
Memory High memory usage Minimal allocation
Metadata None Rich context + verification
Formats Text only JSON, Base64, ASCII
AI Integration None Native ASCII diff parsing

🆚 VS Copy-Paste

Feature Copy-Paste MultiLineDiff
Precision Manual, error-prone Automated perfection
Tracking No history Full metadata
Verification None Cryptographic
Undo Manual Automatic
Scale Small changes only Any size document

🆚 VS Line Number Edits

Feature Line Numbers MultiLineDiff
Reliability Breaks with file changes Context-aware positioning
Precision Line-level only Character-level
Automation Manual process Fully automated
Conflicts Common Intelligent resolution

🎨 ASCII DIFF REVOLUTION

🤖 AI-Friendly Format

BREAKTHROUGH: First diffing system designed for AI interaction:

📎 class UserManager {
📎     private var users: [String: User] = [:]
     func addUser(name: String, email: String) -> Bool {
     func addUser(name: String, email: String, age: Int = 0) -> Result<User, UserError> {
📎         guard !name.isEmpty && !email.isEmpty else {
             return false
             return .failure(.invalidInput)
📎         }
📎 }

🎯 ASCII 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

🔄 Round-Trip Perfection

WORLD FIRST: Complete ASCII workflow:

  1. Create diff → 2. Display ASCII → 3. Parse ASCII → 4. Apply diff Result: 100% accuracy with zero data loss

🛡️ SECURITY & VERIFICATION FEATURES

🔐 Cryptographic Integrity

// SHA256 hash verification
let isValid = MultiLineDiff.verifyDiff(diff)
// Tamper detection
// Content verification
// Round-trip validation

🎯 Smart Verification

  • Source Matching: Verifies diff applies to correct source
  • Destination Validation: Confirms expected output
  • Metadata Consistency: Validates all context information
  • Operation Integrity: Ensures operation sequence validity

🔄 Undo System

// Automatic reverse diff generation
let undoDiff = MultiLineDiff.createUndoDiff(from: diff)
// Perfect rollback capability
// Maintains full metadata
// Cryptographic verification

📊 METADATA INTELLIGENCE

🧠 Rich Context Storage

{
  "str": 42,           // Source start line
  "cnt": 15,           // Total lines affected  
  "pre": "context...", // Preceding context
  "fol": "context...", // Following context
  "src": "source...",  // Full source content
  "dst": "dest...",    // Full destination content
  "alg": "megatron",   // Algorithm used
  "hsh": "sha256...",  // Integrity hash
  "app": "truncated",  // Application type
  "tim": 0.0234        // Generation time
}

🎯 Automatic Type Detection

  • Full Source: Complete document diffs
  • Truncated Source: Section-based patches
  • Context Matching: Intelligent positioning
  • Confidence Scoring: Best match selection

🚀 PERFORMANCE REVOLUTION

Algorithm Performance (1000 runs average)

Algorithm Create Time Apply Time Total Time Operations
Flash 🏆 14.5ms 6.6ms 21.0ms 3
Zoom 23.9ms 9.1ms 33.0ms 3
Optimus 43.7ms 6.6ms 50.3ms 1256
Starscream 45.1ms 6.9ms 52.0ms 1256
Megatron 47.8ms 7.0ms 54.8ms 1256

🎯 Speed Advantages

  • 2x faster than traditional algorithms
  • Minimal memory allocation
  • O(n) complexity for most operations
  • Swift 6.1 optimizations throughout

🌐 I/O FORMAT REVOLUTION

📦 Multiple Encoding Formats

// JSON Data - High performance
let jsonData = try MultiLineDiff.encodeDiffToJSON(diff)

// JSON String - Human readable  
let jsonString = try MultiLineDiff.encodeDiffToJSONString(diff)

// Base64 String - Compact transport
let base64 = try MultiLineDiff.diffToBase64(diff)

// ASCII Format - AI friendly
let ascii = MultiLineDiff.displayDiff(diff, source: source, format: .ai)

🔐 Secure Transport

  • Base64 encoding for safe transmission
  • JSON compatibility for APIs
  • Compact representation for storage
  • Cross-platform compatibility

🎨 Display Formats

// Terminal with colors
let colored = MultiLineDiff.displayDiff(diff, format: .terminal)

// AI-friendly ASCII  
let ascii = MultiLineDiff.displayDiff(diff, format: .ai)

🎯 CODING & PATCH PERFECTION

💻 Perfect for Code

  • Whitespace preservation: Every space, tab, newline preserved
  • Unicode support: Full UTF-8 character handling
  • Line ending preservation: Windows/Unix/Mac compatibility
  • Indentation integrity: Perfect code formatting

🔧 Truncated Diff Mastery

// Apply section patches to full documents
// Intelligent context matching
// Confidence-based positioning
// Automatic boundary detection

📝 Documentation Patches

  • Markdown support: Perfect for documentation
  • Code block preservation: Syntax highlighting intact
  • Link integrity: URLs and references maintained
  • Format preservation: Headers, lists, tables intact

🤖 AI INTEGRATION BREAKTHROUGH

🧠 AI-Native Design

// AI submits readable diffs
let aiDiff = """
📎 func calculate() -> Int {
❌     return 42
✅     return 100  
📎 }
"""

// Parse and apply automatically
let result = try MultiLineDiff.applyASCIIDiff(to: source, asciiDiff: aiDiff)

🎯 AI Workflow Benefits

  • No training required: AI understands format instantly
  • Visual clarity: Humans can review AI changes
  • Error reduction: Clear operation visualization
  • Debugging: Easy to spot AI mistakes

🏆 WORLD'S MOST FLEXIBLE SYSTEM

🎛️ Algorithm Selection

// Choose based on needs
.flash      // Speed priority
.megatron   // Accuracy priority  
.optimus    // Detail priority
.zoom       // Simplicity priority
.starscream // Line-aware priority

🔧 Application Modes

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

// Manual control
let result = try MultiLineDiff.applyDiff(to: source, diff: diff, allowTruncated: true)

📊 Output Formats

  • Terminal colors: Visual diff display
  • ASCII text: AI and human readable
  • JSON data: API integration
  • Base64: Compact storage
  • File I/O: Persistent storage

🎉 REVOLUTIONARY BENEFITS SUMMARY

🚀 For Developers

  • Perfect code patches: No whitespace corruption
  • Intelligent positioning: Context-aware application
  • Undo capability: Instant rollback
  • Verification: Cryptographic integrity
  • Performance: Lightning-fast processing

🤖 For AI Systems

  • Native ASCII format: No training required
  • Visual clarity: Human-reviewable changes
  • Round-trip accuracy: 100% data preservation
  • Error detection: Built-in verification
  • Metadata richness: Full context information

🏢 For Enterprise

  • Security: SHA256 verification
  • Scalability: Handles any document size
  • Reliability: Extensive testing (81 tests passing)
  • Flexibility: Multiple algorithms and formats
  • Integration: JSON/Base64/ASCII I/O

🌍 For Everyone

  • Simplicity: One-line API calls
  • Reliability: Never corrupts data
  • Speed: Faster than any alternative
  • Accuracy: Character-perfect results
  • Innovation: Features found nowhere else

🎯 THE BOTTOM LINE

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

This is the future of diffing technology, available today.


© 2025 Todd Bruss, xcf.ai - All innovations and inventions proprietary

MultiLineDiff: The Most Advanced Diffing System on Earth 🌍

created by Todd (Optimus Flash) Bruss (c) 2025 XCF.ai

website https://d1f.ai mirror https://diff.xcf.ai