Vid generation and usage

How is vid generated for a vertex? Isn’t it just a random number generated internally by TG? The reason I am asking is that I see usage of comparing two vids like below, which doesn’t seem to make sense if vid is just pure random.

IF getvid(t) < getvid(s) THEN
do-something;

vid’s are unique integers, with no relationship to the primary key beyond a guarantee that the same key will get the same id. Internally it probably uses a hash, but it turns out that is not relevant to your question.

The code you see above is where we want to only perform an operation once per pair of vertices, so the problem is to select one of the pair, and it doesn’t matter which one. This can avoid cycles, or simply avoid redundant calculations.

Hey rik,

Just curious. Wouldn’t “IF t != s THEN” do the job ?

No. We usually want it to work only once per pair, and exclude self-edges.

With != we’d only exclude self-edges with undirected edges.

1 Like