Check graph invariants. >>> g = Graph() >>> g[1] = {2: 3, 3: 9} >>> g._validate() >>> dict.__setitem__(g, 1, {2: 3, 3: 9}) #bypass Graph >>> g._validate() Traceback (most recent call last): AssertionError: vertex type not found on 1
(self)
| 589 | def copy(self): raise NotImplementedError |
| 590 | |
| 591 | def _validate(self): |
| 592 | """Check graph invariants. |
| 593 | |
| 594 | >>> g = Graph() |
| 595 | >>> g[1] = {2: 3, 3: 9} |
| 596 | >>> g._validate() |
| 597 | >>> dict.__setitem__(g, 1, {2: 3, 3: 9}) #bypass Graph |
| 598 | >>> g._validate() |
| 599 | Traceback (most recent call last): |
| 600 | AssertionError: vertex type not found on 1 |
| 601 | """ |
| 602 | #NOTE: calling this after each add/discard slows things down considerably! |
| 603 | for vid, v in self.iteritems(): |
| 604 | assert isinstance(v, self.VertexType), "vertex type not found on " + str(vid) |
| 605 | v._validate() |
| 606 | |
| 607 | |
| 608 | def gprofile(g, size=100): |