c++ - Efficient lookup of a buffer with stack of data modifications applied -


i trying write c++11 library part of wider project implements stack of changes (modification, insertion , deletion) implemented on top of original buffer. then, aim able "through" changes , modified data out.

my current approach is:

  • maintain ordered list of changes, ordered offset of start of change
  • also maintain stack of same changes, can rolled in order
  • new changes pushed onto stack , inserted list @ right place
  • the changes-by-offset list may modified if change interacts others
    • for example, modification of bytes 5-10 invalidates start of earlier modification 8-12
    • also, insertion or deletion changes change apparent offset of data occurring after them (deleting bytes 5-10 means used byte 20 found @ 15)
  • to find modified data, can though list change applies (and offset within change applies - change might have invalidated of it), or find right offset in original data if no change touched offset
    • the aim here make lookup fast - adding change might take effort mess list, lookups later, outnumber modifications greatly, in ordered list should pretty straightforward.
    • also don't need continuously copy data - each change's data kept it, , original data untouched
  • undo implemented popping last change off stack , rolling changes made change's addition.

this seems quite difficult task - there lot of things take care of , piling complex code!

i feel sure must problem has been dealt in other software, looking around various hex editors , on hasn't pointed me useful implementation. there name problem ("data undo stack" , friends hasn't got me far!), or library can used, reference, kind of thing?

i believe common approach (one have used in past) store original state , put each change operation (what's being done + arguments) on undo stack. then, particular prior state start original , apply changes except ones want undone.

this lot easier implement trying identify parts of data changed, , works unless operations time-consuming (and therefore slow "replay" onto original state).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -