jacob-carlborg/orange

permanant hash

Aphexus opened this issue · 2 comments

One must have a consistent way to identify nodes for a various reasons. Id is not robust. If it changes then it can break code even though nothing else has changed.

It would be nice to have a hash of the structural path to an item. I was able to do this by post processing serialization and adding the a hash based on the path from the root to the item. This is unique unless the structure changes but is immune to basic rearranging of fields.

In the output the xml contains a hash attribute similar to the id and key attributes.

The problem is that the deserializer does read in the hash attribute when it reads the xml. I cannot found out where in the code this takes place.

Also, since the hash value does not persistet between a serializer and deserializer it must be computed properly for serialization. Since I compute it after works, it gets stuck in the xml file but does not allow one to use it such as with toData or some custom processing.

This would not be so bad as I could potentially compute the hash from the node/element structure. Unfortunately it seems that lastElement's parent is always null so there is no way to recurse from the child to the root to determine the path and hash it.

I'm not sure if this is a bug or. Seems like parent is not being set. For archiving I am able to use items to recursively go down the hierarchy so I don't need parent but for unarchiving I need to work back up from the current element and that requires knowing parent(or if items is correct I could search but that would be a huge waste of cycles).

It may be that parent is being set on the tail and it's not being updated before element is unarchived.

I was able to get this to work by setting the parent on lastElement.element creations. Not too much work. The hashes then can be computed.

Also, in your code there is a lot of redundancy. You can generate all those member functions that dispatch on type to the templated function with 2 lines of code using a static foreach or a string mixin.

Is this an enhancement request to add a permanent hash?

Code examples would help in understanding what you're trying to do.