How to serialize a graph structure?

前端 未结 6 900
一整个雨季
一整个雨季 2021-02-02 08:11

Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data.

But many problems are b

6条回答
  •  [愿得一人]
    2021-02-02 08:55

    One example you might be familiar is Java serialization. This effectively serializes by graph, with each object instance being a node, and each reference being an edge. The algorithm used is recursive, but skipping duplicates. So the pseudo code would be:

    serialize(x):
        done - a set of serialized objects
        if(serialized(x, done)) then return
        otherwise:
             record properties of x
             record x as serialized in done
             for each neighbour/child of x: serialize(child)
    

    Another way of course is as a list of nodes and edges, which can be done as XML, or in any other preferred serialization format, or as an adjacency matrix.

提交回复
热议问题