johannhof / difference.rs

Rust text diffing and assertion library
https://docs.rs/difference
MIT License
242 stars 33 forks source link

Method for efficient representation #43

Open jmqd opened 4 years ago

jmqd commented 4 years ago

I'm still looking into the details, so this is more for opening a discussion on whether people think this is worth adding. I understand that it may considered as outside the scope of this crate.

I'm looking into sending Changesets serialized over the wire, and I'm interested in minimizing the payload size. What are your thoughts on introducing a new method (and possibly types) to represent something along the lines of "skip forward this many tokens"?

e.g., Instead of

Same("Two roads diverged in a yellow wood,\n"),
Same("And be one traveler, long I stood\n"),
Rem("And sorry I could not travel both\n"),
Add("And looked down one as far as I could")

Perhaps something like this?

ContiguouslySame(2),
Rem("And sorry I could not travel both\n"),
Add("And looked down one as far as I could")

Instead of adding a new Difference enum value, which would obviously cause pain, I was thinking it could be offered in a separate method so that users can opt-in to a more efficient representation if they want.

teymour-aldridge commented 4 years ago

I think this would be really useful.