I'm currently writing a program that deals with the manipulation of graphs. For simplicity, the label of each vertex is a positive integer (i.e. 1, 2, ...). For one of the algorithms I'm trying to implement, I need to write a function edgeId(u, v) that takes two vertex numbers u and v and maps the edge (u, v) to a unique positive integer.
Since my algorithm must handle directed and undirected graphs, I have the following stipulations. For directed graphs, edgeId(u, v) must be injective (i.e. edgeId(a, b) = edgeId(c, d) if and only if a = c and b = d). For undirected graphs, it must be symmetric (i.e. edgeId(u, v) = edgeId(v, u), but only those two can map to that positive integer).
Does anyone have an idea on how to implement such a function? Every idea I've had so far has failed because I have no knowledge of the number of vertices in the graph.
Any help would be greatly appreciated!