Mercurial > hg > WSGraph
diff wsgraph/model.py @ 37:f17a6577cc0d
make default type configurable
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sat, 15 Dec 2012 23:22:19 -0800 |
parents | 16673636dcb6 |
children | df2a719a9b6e |
line wrap: on
line diff
--- a/wsgraph/model.py Fri Dec 14 20:53:41 2012 -0800 +++ b/wsgraph/model.py Sat Dec 15 23:22:19 2012 -0800 @@ -85,12 +85,18 @@ return tuple(key) in self.edges() +class DirectedGraph(Graph): + """mix-in class for directed graphs""" + # TODO: is this possible without super or other black magicks? + + class MemoryCache(Graph): """volatile in-memory representation of a graph""" - def __init__(self): + def __init__(self, node_type=dict): self._edges = {} self._nodes = {} + self.node_type = node_type def node(self, name, value=None): if value is not None: @@ -109,7 +115,7 @@ # setter self._edges[(node1, node2)] = deepcopy(value) for node in node1, node2: - self._nodes.setdefault(node, {}) + self._nodes.setdefault(node, self.node_type()) else: # getter # TODO: deepcopy @@ -118,6 +124,7 @@ def edges(self): return self._edges.keys() + class FileCache(MemoryCache): """on-disk JSON file cache"""