Dgraph
Dgraph copied to clipboard
Vertex/edge labels
Is it possible to label edges/vertices with arbitary data type? It'll be great to be able do so. E.g i want to represent path with graph and that graph should have vertices labeled with string type(like street name or whatever) and edges with int type(travel time). Ultimately it should be possible to instantinate these two types of labels(for edges and for vertices) with arbitrary type.
Imaginary code follows for better understandin what i mean.
// Vertex label type.
class Foo { ... };
// Edge label type.
enum Bar { ... };
auto graph = new Graph!(Foo, Bar)(...);
Not yet -- it will be implemented at some point but the core functionality is priority for now. The idea of Dgraph is that for any actual graph calculations, the vertices/edges should be labelled 0, 1, 2, ... but that there should be wrappers that can be used for data input/output. You can implement this manually doing something like:
size_t[LabelType] idMap;
LabelType[] idMapInverse;
... and then to add an edge (i, j) to the graph you could do something like:
if ((i in idMap) is null)
{
idMap[i] = idMapInverse.length;
idMapInverse ~= i;
assert(idMap.length == idMapInverse.length);
}
if ((j in idMap) is null)
{
idMap[j] = idMapInverse.length;
idMapInverse ~= j;
assert(idMap.length == idMapInverse.length);
}
if (idMap.length > graph.vertexCount)
{
// ... add appropriate number of vertices,
// I really must implement vertexCount as a
// writeable property ...
}
graph.addEdge(idMap[i], idMap[j]);
You can now do any and all calculations you need on the graph, and then filter vertex IDs back through idMapInverse when you need to write out any results.
Okay, thanks for an explanation.
Leave the issue open. It's a perfectly valid feature request :-)