diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..20e8d51 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,99 @@ +# Likewise - Floating Point Diff Implementation + +## Codebase Structure + +``` +src/ +├── lib.rs # Main entry, re-exports +├── types.rs # DiffOp, Change, ChangeTag, Algorithm enums +├── common.rs # capture_diff_slices(), get_diff_ratio() +├── algorithms/ # myers.rs, patience.rs, lcs.rs, hook.rs, utils.rs +├── text/ # TextDiff, DiffableStr trait +├── udiff.rs # Unified diff output +└── utils.rs # Text utilities +``` + +## Current Diff Flow + +1. `capture_diff_slices(alg, &old, &new)` → `Vec` +2. `DiffOp::iter_changes(&old, &new)` → `Iterator>` +3. Requires `T: Hash + Eq + Ord` + +## Key Types + +```rust +pub enum DiffOp { + Equal { old_index: usize, new_index: usize, len: usize }, + Delete { old_index: usize, old_len: usize, new_index: usize }, + Insert { old_index: usize, new_index: usize, new_len: usize }, + Replace { old_index: usize, old_len: usize, new_index: usize, new_len: usize }, +} + +pub struct Change { + pub(crate) tag: ChangeTag, + pub(crate) old_index: Option, + pub(crate) new_index: Option, + pub(crate) value: T, +} +``` + +## Algorithm Trait + +```rust +pub trait DiffHook { + type Error; + fn equal(&mut self, old: usize, new: usize, len: usize) -> Result<(), Self::Error>; + fn delete(&mut self, old: usize, old_len: usize, new: usize) -> Result<(), Self::Error>; + fn insert(&mut self, old: usize, new: usize, new_len: usize) -> Result<(), Self::Error>; + fn replace(&mut self, old: usize, old_len: usize, new: usize, new_len: usize) -> Result<(), Self::Error>; +} +``` + +## Task: FP Comparison + +Add eps/ulps floating point comparison for f32/f64 slices. + +### Implementation Points + +1. **New comparison trait** alongside existing `PartialEq` requirement +2. **Algorithm modification** to use FP-aware comparison in core loops +3. **API surface** for specifying epsilon/ulps parameters +4. **Testing** edge cases: NaN, infinity, subnormals, precision boundaries + +### Files to Modify + +- `src/algorithms/myers.rs` - Core comparison logic +- `src/algorithms/patience.rs` - Core comparison logic +- `src/algorithms/lcs.rs` - Core comparison logic +- `src/common.rs` - Add FP-aware `capture_diff_slices_fp()` +- `examples/floating_point.rs` - Usage demonstration + +### Example Usage Goal + +```rust +let old = vec![1.0, 2.0, 3.0]; +let new = vec![1.000001, 2.0, 3.1]; + +// Absolute epsilon +let ops = capture_diff_slices_fp_eps(Algorithm::Myers, &old, &new, 0.0001); + +// Relative ulps +let ops = capture_diff_slices_fp_ulps(Algorithm::Myers, &old, &new, 4); +``` + +### Testing Strategy + +Use existing `insta` snapshot testing framework. Test matrices: +- Normal values with various epsilon/ulps settings +- Edge cases: ±0.0, NaN, ±infinity +- Precision boundaries and subnormal values +- Mixed normal/edge case arrays + +### Status + +- [x] CI fixed (Rust 1.66 MSRV) +- [x] Codebase analysis complete +- [ ] Design FP comparison API +- [ ] Implement core FP comparison logic +- [ ] Add comprehensive tests +- [ ] Create usage examples \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 04a2e24..6f514c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" rust-version = "1.66" license = "Apache-2.0" description = "A diff library for Rust (fork of similar)" -repository = "https://github.com/barrett-ruth/likewise" +repository = "https://github.com/barrettruth/likewise" keywords = ["diff", "difference", "patience", "compare", "changes"] readme = "README.md" exclude = ["assets/*"] diff --git a/README.md b/README.md index 1e3576a..b2e6f5f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ > This crate is a fork of [similar](https://github.com/mitsuhiko/similar) library, which, as of 11/9/25, is rather inactive. [![Crates.io](https://img.shields.io/crates/d/likewise.svg)](https://crates.io/crates/likewise) -[![License](https://img.shields.io/github/license/barrett-ruth/likewise)](https://github.com/barrett-ruth/likewise/blob/main/LICENSE) +[![License](https://img.shields.io/github/license/barrettruth/likewise)](https://github.com/barrett-ruth/likewise/blob/main/LICENSE) [![rustc 1.66.0](https://img.shields.io/badge/rust-1.66%2B-orange.svg)](https://img.shields.io/badge/rust-1.65%2B-orange.svg) [![Documentation](https://docs.rs/likewise/badge.svg)](https://docs.rs/likewise) @@ -58,6 +58,6 @@ fn main() { ## License and Links * [Documentation](https://docs.rs/likewise/) -* [Issue Tracker](https://github.com/barrett-ruth/likewise/issues) -* [Examples](https://github.com/barrett-ruth/likewise/tree/main/examples) -* License: [Apache-2.0](https://github.com/barrett-ruth/likewise/blob/main/LICENSE) +* [Issue Tracker](https://github.com/barrettruth/likewise/issues) +* [Examples](https://github.com/barrettruth/likewise/tree/main/examples) +* License: [Apache-2.0](https://github.com/barrettruth/likewise/blob/main/LICENSE)