Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.programming    |    Programming issues that transcend langua    |    57,431 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 55,655 of 57,431    |
|    Malcolm McLean to All    |
|    Undo / Redo design pattern.    |
|    03 Apr 22 04:16:11    |
      From: malcolm.arthur.mclean@gmail.com              To implement a simple undo redo, you need two stacks, and a copyable       representation of the program state. You then push to the undo stack, with       straight forwards extensions for redo.              However this is memory greedy. So it is better to use the following pattern,       on stack push, take the difference between stack top and the object being       pushed. Then delete stack top, and replace with the difference between the       pushed object and stack top,        then push. To pop the stack, apply the difference to stack top, and set it as       new stack top.              This could be made generic, but it involves a user-supplied delta codec which       could be hard to write. Another way of doing it is to feed everything through       a tostring / fromstring representation.              The problem is now reduced to writing the delta codec for two strings. The       proper way to do this is to use a string alignment algorithm, but that is       likely to be overkill. The majority of changes will be either one character or       one indel. If we've got        more than few changes, we can simply resort to storing the entire string.                      --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca