3 ms·
I just had a project where we need to keep track of changes to a string as a series of insertions, deletions and substitutions. We don't want the whole history,
by tgb 8y ago
I just had a project where we need to keep track of changes to a string as a series of insertions, deletions and substitutions. We don't want the whole history, so if someone inserted then deleted the thing they inserted, we would track that there was no change. Using notation like that of an (abstract) algebra class computing "commutators" of the various operations (like D_n means "delete character at position n" or I_{n,string} means "insert 'string' before position n") helped me figure it out. This project is more complicated than it sounds: my earlier attempts had me repeatedly try to just intuitively write code but I kept running into problems and finding that my set-ups were insufficient and practically impossible to make bug-free. Having an algebraic notation made me make the order in which operations were performed explicit and helped finally give me a decent representation of them.