C
call_me_anything
Hi,
I am looking for a good algorithm (in C/C++) for implementing undo/
redo on a data structure.
The data structure is basically a n-children tree somewhat of the
form :
class /* or struct */ node {
char *info1;
char *info2;
char *info3;
node *children;
node2 *pets;
node3 *furniture;
node *myparent;
}
and node2, node3 etc are also defined in more or less similar fashions
but are not same as node.
Now, we have a data structure of the above format and we provide a
user interface such that user can
modify any field in the tree.
So user can :
1) change char* fields to some other strings or make them NULL for any
node.
2) Add pets, children or furniture to any node.
And it is desired to have an undo/redo functionality for each of the
above operations.
What is the most efficient way in which this can be done ?
1) Saving each state to a file will be very time consuming.
2) Replicating each state in memory will also be very time consuming
and memory inefficient.
How can we store the changes in an incremental fashion ?
Do we need to add something more to the above structures for storing
incremental changes ?
I am looking for a good algorithm (in C/C++) for implementing undo/
redo on a data structure.
The data structure is basically a n-children tree somewhat of the
form :
class /* or struct */ node {
char *info1;
char *info2;
char *info3;
node *children;
node2 *pets;
node3 *furniture;
node *myparent;
}
and node2, node3 etc are also defined in more or less similar fashions
but are not same as node.
Now, we have a data structure of the above format and we provide a
user interface such that user can
modify any field in the tree.
So user can :
1) change char* fields to some other strings or make them NULL for any
node.
2) Add pets, children or furniture to any node.
And it is desired to have an undo/redo functionality for each of the
above operations.
What is the most efficient way in which this can be done ?
1) Saving each state to a file will be very time consuming.
2) Replicating each state in memory will also be very time consuming
and memory inefficient.
How can we store the changes in an incremental fashion ?
Do we need to add something more to the above structures for storing
incremental changes ?