Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are dealing with purely text-based data, a basic versioned data structure could be as simple as an array or linked list of structures looking something like:</p> <pre><code>struct versioned_string { int version; char* data; }; </code></pre> <p>"Committing" a new entry would only involve allocating a new string to store the data in. Retrieving a specific version would involve walking the list looking for a particular <code>version</code> value (for a linked list) or indexing into the array (for an array). A "rollback" would involve clearing out an entry from the end of the list and freeing the associated string.</p> <p>You could also use a database (sqlite, for instance), store the information in a table, and let the DB engine handle the adds, deletes, and searches. This might be overkill, however.</p> <p>I don't really follow your example, though. I'm assuming the first code block you posted indicates a single input string (that is, a snapshot of what the text data looks like at a particular version)? If so, multiple "trees" shouldn't be a problem since the input is stored as raw text and not processed or interpreted in any way. I certainly don't understand your "Unix shell" example. Can you break that down in more detail? Specifically, for each line, clearly list what the input is, what the output is, and what you expect the "current version" of the data to look like at that point.</p> <p><strong>Update:</strong> Ignore my previous comment about rollback; I was thinking of it in terms of how this website uses the term (meaning to revert to a previous state), and you use the term differently (meaning to retrieve an older version).</p> <p>Each snapshot of the entire data set can be represented by a single C string since elements are separated by non-null characters (whitespace and/or curly braces). A simple data structure like the one I outlined above should give you the capabilities that you need if you create a linked list of them. Since the data is stored in it's string representation, commit and rollback operations would be as trivial as adding a new element to the list (for commit) or walking the list backwards and passing the string to <code>printf</code> (for rollback). The 'show' command is a different animal, because it doesn't really have much to do with the way you version the data. As far as the versioning system is concerned, all you would do is grab the last entry from the list. The real work there is done by whatever library functions you've created for parsing strings and manipulating data internally.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload