Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Serialization of Graph-like C++ Structures

0 views
Skip to first unread message

Nordlöw

unread,
Jul 9, 2009, 7:16:01 AM7/9/09
to
Does anyone know of any convenient interface/API (Database) that
transparently encodes/decodes (serialization) graph-like C++
structures and relations between them to and from disk?

Of course the programmer needs explicitly specify the serialization
of
the data-members of the struct/class typically using the member
functions

- Obj::encode(std::ostream & os) const
- Obj::decode(std::istream & is) const

I have also implemented "automatic management" of two-way-relations
to
realized unordered graph structures.

These are realized as enum-typed double-linked/way pointers.
These could be (un)serialized automatically

Could we reuse boost::graph and boost::serialization somehow?
If not, what structures (balanced tree, hashmap, sorted arrays, ...)
should I use to construct file-format?

Thanks in advance,
Nordlöw

Jonathan Lee

unread,
Jul 9, 2009, 9:31:35 AM7/9/09
to
On Jul 9, 7:16 am, Nordlöw <per.nord...@gmail.com> wrote:
> Does anyone know of any convenient interface/API (Database) that
> transparently encodes/decodes (serialization) graph-like C++
> structures and relations between them to and from disk?

No, but I recently wrote a serialization routine for my own Graph
class. It wrote the class as an adjacency list with the form (using
grammar notation -- not pointer notation)

((sourceNode)(destNodeID*) Terminator1)* Terminator2

Then I (naively) iterate over every node:

void Graph::serialize(ostream& o) {
for (int i = 0; i < numNodes; ++i) {
o << node[i]; // assume node is serializable
for (int j = 0; j < numNodes; ++j) {
if (adjacent(i,j)) encode(o, j);
}
o << Terminator1;
}
o << Terminator2;
}

In practice encode(o,j) writes j as a UTF-8 like variable length
integer. Then Terminator1 == '\0xFE' and Terminator2 == '\0xFF' for
the simple reason that 0xFE and 0xFF cannot occur in that encoding.

--Jonathan

Lynette Angley

unread,
Jul 9, 2009, 9:40:46 AM7/9/09
to
Is this some kinda next gen P2P application? 'Coz bittorrents have this feature.
0 new messages