home bbs files messages ]

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,664 of 57,431   
   Malcolm McLean to ju...@diegidio.name   
   Re: Undo / Redo design pattern.   
   04 Apr 22 06:46:09   
   
   From: malcolm.arthur.mclean@gmail.com   
      
   On Monday, 4 April 2022 at 14:02:24 UTC+1, ju...@diegidio.name wrote:   
   >   
   > In fact, a stack that does not implement access by index just wouldn't cut   
   it.   
   >   
   You can only undo the item on top of the stack. So if you just have undo, a   
   stack is   
   fine. If you have redo, you can only redo the last operation that was undone.   
   So   
   one way is to use a stack with an index indicating the current undo position.   
   The other way is to have two stacks, and push to the redo stack on every undo.   
      
   If you have two stacks, they can be true stacks, with only the top accessible.   
   and that has the advantage that we don't need to store whole objects in the   
   stacks.   
   We can store the top object, then the delta from the top to the next, and so   
   on. When we push the stack, we calculate the delta, and replace stack top with   
   the delta, then place the new object on the top.  When we pop the stack,   
   stack top is the object we return, and we apply the delta to create the new   
   stack top.   
      
   --- 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