Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've used XOR for undo/redo when I had limited memory in a painting app:

- You have the canvas in state S before you draw on it and the canvas in state T after you draw on it.

- Store (S XOR T). XOR this against T to undo back to S and XOR again to redo back to T.

So if you want to have 10 levels of undo, you only need to store the final state and the 10 XOR diffs that got you there. The diffs will compress well too because most of the pixels on them will be blank (where nothing changed).

All fairly easy to implement too e.g. compared to storing and replaying high-level commands to redo.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: