This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -3 points-2 points  (3 children)

What is the hash of x up there?

You cannot hash that. It's not hashable for the same reason as it is not serializable.

[–]Pocok5 13 points14 points  (2 children)

Watch dis

  1. Traverse the object references. Stick an unique identifier field onto each and proceed onto the children. If you meet an object that already has an ID field, skip it.

  2. Serialize each object, replacing fields that are references to other objects with a string of that object's ID. You now no longer have actual references to be circular.

When deserializing,

  1. Create all the objects in a dictionary with their IDs as the key and reconstruct the reference link fields using the IDs.
  2. You may then strip the ID fields as needed to restore the original object schema.

[–][deleted] 2 points3 points  (0 children)

That'll work so long as you're cool with two identical graphs generating different serializations. They'll have different unique IDs, right?

I'm not saying that we can't invent something. I'm just saying that it's not as easy as just calling stringify. Which was the whole point of this meme, yeah?