I just finished the key values class and its rolling pretty well. Lots of the same features as the one I wrote in C++ but this one I had the honor of designing, and design I did. The class in c# is has dynamic data structures, an array list, sorted list, writing this class over in C++ has been great because I got the chance to put some thought into an old data structure I hadn’t touched in a while.
First and foremost I have added the ability for keys to be quoted and include more than one word. It wasn’t too difficult, but it was definitely tricky enough to have a few of my hairs turn grey. Once I got it read in I used some bit manipulation stuff for storing some flags relating to how the file is written after the fact, and it all went as expected, which is a great thing because it means that the force is getting stronger within me.
The C# built in data structures are pretty complicated. They have a lot of overhead & features that go unused in most applications. There are so many different things that are built into them that it becomes mottled when you try to find a specific one. So for what its worth, C# is a great language to use when you want to develop something quickly, while still having the ability to use C syntax, since VB is just so damned tacky.
C++ has a lot going for it; for one it has a hell of a lot better control over your application, and less overhead and no .net dependency. It is great for applications like this because classes serve their purpose: grouping data and functions into meaningful objects. It never ceases to amaze me when an object is created how well it flows with a programmer. Similar to when you pick up a poem that you wrote back in grade school that opened your eyes to what you were able to do in a creative sense, writing a program correctly and looking back on it will often leave me feeling warm and tingly.
In order to store my data I chose a structure that is a little too complex for much anything other than show. There are three structures in fact, but they are all interesting in their own right and serve their own purposes very well.
The Key Value files are stored in a very simple file structure. Keys are first, values second, and each group of keys and values is stored in a section, named with a single word. Each section is also wrapped in curly braces for clarity I suppose. Tabbing and quotes are optional, whereas the format is mandatory. Using this as a starting point, I added the various functions to read in and store the data.
In order to make this as quick as I could I stored everything in a binary search tree or BST for short. One of the characteristics and more complicated things about a BST is that it is a very quick searched sorted data structure. It allows me to quickly grab a section and then its data without having to worry about hashing algorithms, or linked lists etc, but it loses its order. Reading this file in and writing it should always be the same, with no exceptions, so I had to add in a linked list in order to preserve that. My structure chart is becoming pretty crazy at this point, but as I said before, it all serves its purpose and I love it. I have one pair of pointers for the BST functionality and another for order preservation.