Mercurial > hg > WSGraph
diff wsgraph/model.py @ 39:d1e9602145fa
rudimentary deletion and notes to self
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 25 Dec 2012 12:46:39 -0800 |
parents | df2a719a9b6e |
children |
line wrap: on
line diff
--- a/wsgraph/model.py Mon Dec 24 22:57:02 2012 -0800 +++ b/wsgraph/model.py Tue Dec 25 12:46:39 2012 -0800 @@ -104,9 +104,11 @@ # TODO: is this possible without super or other black magicks? -class MemoryCache(Graph): +class MemoryCache(Graph): # TODO -> MemoryCacheGraph """volatile in-memory representation of a graph""" + # TODO: a subclass that pegs the type(s?) to something specific + def __init__(self, node_type=dict): self._edges = {} self._nodes = {} @@ -138,6 +140,17 @@ def edges(self): return self._edges.keys() + def delete(self, node1, node2=None): + if node2 is not None: + # delete an edge + key = node1, node2 + del self._edges[key] + return + + # delete a node + # TODO: if a node is deleted, all edges to it should be deleted + del self._nodes[node1] + class FileCache(MemoryCache): """on-disk JSON file cache"""