Concerning "weighted": What exactly is the semantics? Is it the case that a weighted graph has positive integral edge weights, that could be taken as the multiplicity of this edge? But then, do we want that a weighted graph is equal to a multigraph with the corresponding multiplicity of edges?
In any case, the hash is currently broken, since it does not take into account weightedness, but equality check does.
It seems to me that the following is the easiest way to go:
- We keep equality test as it currently is. Here, I am being egoistic: As long as the edge labels and the multiplicity of edges count in equality testing, I simply don't care whether _weighted counts or not. I just need immutable graphs with an unbroken hash.
- In order to fix the hash, it must take into account precisely the data that are used in
__eq__
.
- We want that graphs using the immutable graph backend are immutable in the sense stated above. Hence, we must disallow
G.weighted(True/False)
if G
is supposed to be immutable. Hence, G.weighted
should check for the G._immutable
flag. Similarly, we must proceed with all other non-underscore methods that could potentially change the ==-class of G
.
- In particular, we want that that
G._immutable
is set when the immutable backend is in use.