changeset 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 00aee7b82657
files tests/doctest.txt wsgraph/model.py
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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()
+    []
 
--- 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"""