Set graph[vid] to VertexType(value). >>> g = Graph(VertexType=WVertex) >>> g[1] = {} #set g[1] to empty vertex (no out edges) >>> type(g[1]) is WVertex True >>> g[2] = {1: 4, 3: 9} #non-existent vertex values get created automatically >>> print g
(self, vid, value)
| 514 | return self.setdefault(vid, {}) #will convert plain {} to VertexType if necessary |
| 515 | |
| 516 | def __setitem__(self, vid, value): |
| 517 | """Set graph[vid] to VertexType(value). |
| 518 | |
| 519 | >>> g = Graph(VertexType=WVertex) |
| 520 | >>> g[1] = {} #set g[1] to empty vertex (no out edges) |
| 521 | >>> type(g[1]) is WVertex |
| 522 | True |
| 523 | >>> g[2] = {1: 4, 3: 9} #non-existent vertex values get created automatically |
| 524 | >>> print g #XXX what if VertexType==Vertex -> how to specify no edge value??? |
| 525 | {1: {}, 2: {1: 4, 3: 9}, 3: {}} |
| 526 | >>> g._validate() |
| 527 | >>> |
| 528 | """ |
| 529 | if isinstance(value, self.VertexType) and value._id == vid and value._graph == self: |
| 530 | dict.__setitem__(self, vid, value) |
| 531 | else: #convert to VertexType or create copy of VertexType |
| 532 | dict.__setitem__(self, vid, self.VertexType(self, vid, value)) #XXX shallow copy |
| 533 | |
| 534 | def __delitem__(self, head): |
| 535 | """Delete a single vertex and associated edges. |
no outgoing calls
no test coverage detected