immutable functional data structure to represent graphs
Asked Answered
N

0

8

I (almost) fully understand the Zipper data structure for trees. However, in some publications I saw hints that it is also possible to use the Zipper idea to create immutable functional data structure for arbitrary graphs (which might have cycles as well).

What's the way to do it?

As soon as we have cycles, it means that any node can be reached via several paths. Hence, if I focus on a node, do some change to it, and move the focus away, I might later on come back to the same node via a different path, which means that it would be an 'old' version of the node, prior to the change made.

The only solution I came up with is to include to the context the list of changes to any node. Every time before the focus is changed to node X, it should be checked whether X is the member of the list of changes, and if so, it should be taken as the focused node.

If we also track the number of times N node X was copied from the list of changes, we can remove X from the list of changes, as soon as N = number of edges, inward to X.

Is there any better way to do it?

Neckband answered 25/9, 2017 at 8:13 Comment(3)
What are the papers you are refering too?Layamon
For example, this thread link speaks of it. And this paper link is actually describing a zipper-like structure for some specific cyclic graphs, but I can't see how it can be working for cycles...Neckband
A friend recently shared Huet Zippers with me – you might enjoy reading this tooScallion

© 2022 - 2024 — McMap. All rights reserved.