There are two aspects to this question that are inter-related.
- Change I've made to the
triemodule in python (PyPI, GitHub) to make it serialisable (and deserialisable).
The change I made is visible on GitHub. I added two functions to the
Node class used in serialisation.
def __getstate__(self): return (self.parent, self.key, self.nodes, self.value) def __setstate__(self, state): (self.parent, self.key, self.nodes, self.value) = state if type(self.value) == object: self.value = Node.no_value
Node class uses an instance of
object to signify that there is no value for that
Node. If you serialise and deserialise a
Nodes then the values are set to different instances of
object, this is why I added a check for the type being
object and replacing it with
Is this a reasonable way of doing things? Is anyone likely to want to store an actual instance of
- Is there a better way of signifying that a
Nodehas no value, that is more robust to serialisation?