I’ve been off LJ for a week. Both reading and writing. Not for any reason beyond, I’ve been a little too busy.

Last week was New Years Eve and this week saw me stepping in for a sick clergy member to do mass on short notice and also teaching the first part of my class on Hebrew. At the end of this week I am assisting with an initiation ritual for my church.

The reason I’m posting today and getting myself back on LJ is that I actually have something I want to babble about. I looked around the office and since I’m the only one here there was no one I could talk to about what I did.

When a performer performs or an artist creates you can show it to anyone and they can go ‘oooh’ or ‘ugh’… When you code and accomplish something, you just don’t have the same audience.

The below is some of what I do in a day and the feeling of accomplishment. Most of what’s here will probably make next to zero sense to my average reader. But I will confide that the accomplishment does give me the reaction of seeing my team make a touchdown in an important game.

And to think, my coworker said that I needed some code to get passionate about. He has no idea 😉

If you are curious about this and want me to further explain or would like to learn more about this, feel free to comment in this journal and I’ll answer questions as best I can. I will also attempt not to betray any NDA’s about what I’m actually working on 🙂

Sort of cross posted to macosxdev journals.

A precursor to this is that I am entirely self-taught. My experience in the industry over the last 10 years has kept me from the minutia of data-structures classes that I would have acquired had I actually been a CS major. Most of the stuff I would have gotten out of these classes comes from self-innovation rather than, “oh yeah, we learned that. Only die-hard unix’y geeks ever really deal with this.” Granted, if this is something really cool, I’d like to mark it patent pending right here and now and leave it at that. Personally, I think this may just be something others have done and I’ve gotten a warm fuzzy at least figuring it out on my own.

I am currently trying to wrap a set of C libraries and structures into an Obj-C framework. The data itself comes in a series of linked nodes:

typedef struct generic_node

int node-type // which subnode type it is
char * name // name of node
generic_node * child_head // first child of this node
generic_node * last_child // last child of node
generic_node * parent // node that this was a child of
generic_node * next_child // next sibling along the chain
generic_node * last_child // last sibling on the chain
foo struct bar members   // depends on the int for node-type

Now for every node, I want to create an Obj-C object. Unfortunately, since the list is linked backwards and forwards, I have to track every object I make. I don’t want to make a new one for a node’s prev if it has already been made. I just want to link to the previously made object.

So, I came up with the idea of a hash table that is divided into the hard hex address of the original data for the node as a string. And the data for that key being the object made for it. The idea would be that I would make a node, add the child info by recursively walking the child list, and then add the next info by walking the next chain. If I made a hash lookup of each object as it was created, when I got to a prev it would be by way of an object’s next that was already on my list.

I made the new node object, I made the child check (and set the new node’s child ), I made the next check (and set the new node’s next), I did the prev lookup (set it if found), and of course I added my new object onto the hash list. And sure enough…

It utterly failed.

Now, there are two ways to debug a concept that should have worked. I of course did them in the wrong order. In the order I researched my problem…

  1. Give lots of debug data to look over what you did.
  2. Close your eyes and contemplate what you did in code.

The failure was that none of the nodes were on my hash list at the time they were being looked for. Sometimes very late in the list.

And then I went to step 2.

I realized that once the new node object is made, regardless of whether I’ve set it’s child or next or what have you, it can now be put on the hash table. I moved the 5 lines of code up to right after the object creation but before the child lookup and…

No prev for item [388650]
Dictionary has 31 hashes.
Dictionary has 32 hashes.
Dictionary has 33 hashes.
No prev for item [3889a0]
Found previous addr [388890] in table for item [388960]
Found previous addr [388710] in table for item [388890]
Found previous addr [3885d0] in table for item [388710]

As a side note, // I really love .css

« »