# HG changeset patch # User Jeff Hammel # Date 1356468399 28800 # Node ID d1e9602145fac5a9a6291c5910735b32b55cef56 # Parent df2a719a9b6e8ba6d8d69ac056d988f7d9864467 rudimentary deletion and notes to self diff -r df2a719a9b6e -r d1e9602145fa tests/doctest.txt --- a/tests/doctest.txt Mon Dec 24 22:57:02 2012 -0800 +++ b/tests/doctest.txt Tue Dec 25 12:46:39 2012 -0800 @@ -69,4 +69,7 @@ >>> graph[('a', 'b')] = {'key': 'value'} >>> graph.edges() [('a', 'b')] + >>> del graph[('a', 'b')] + >>> graph.edges() + [] diff -r df2a719a9b6e -r d1e9602145fa wsgraph/model.py --- 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"""