Objects can be joined using join
, tested for connectedness using joined
, and all disjoint sets can be retrieved by using the object as an iterator.
The objects being joined must be hashable and weak-referenceable.
A disjoint-set data structure.
>>> from matplotlib.cbook import Grouper
... class Foo:
... def __init__(self, s):
... self.s = s
... def __repr__(self):
... return self.s ...
>>> a, b, c, d, e, f = [Foo(x) for x in 'abcdef']
... grp = Grouper()
... grp.join(a, b)
... grp.join(b, c)
... grp.join(d, e)
... list(grp) [[a, b, c], [d, e]]
>>> grp.joined(a, b) True
>>> grp.joined(a, c) True
>>> grp.joined(a, d) FalseSee :
The following pages refer to to this document either explicitly or contain code examples using this.
matplotlib.cbook.Grouper
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them