msnlib-cvs Mailing List for msnlib
Status: Alpha
Brought to you by:
joarra
You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: Chang <pe...@us...> - 2002-07-18 17:39:24
|
perky 02/07/18 10:39:21
Modified: msnlib dictqueue.py
Log:
Add pure python implementation of DictQueue
Revision Changes Path
1.2 +123 -2 py-msnlib/msnlib/dictqueue.py
Index: dictqueue.py
===================================================================
RCS file: /cvsroot/msnlib/py-msnlib/msnlib/dictqueue.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- dictqueue.py 15 Apr 2002 16:29:44 -0000 1.1
+++ dictqueue.py 18 Jul 2002 17:39:21 -0000 1.2
@@ -1,3 +1,124 @@
-# $Id: dictqueue.py,v 1.1 2002/04/15 16:29:44 perky Exp $
+#
+# Testing Implementation in Pure Python for Sequential Dictionary
+#
+# XXX: This is only poor reference implementation for testing interface.
+# Please use _seqdictmodule.so instead of this.
+#
+# By Hye-Shik Chang <pe...@li...>
+#
+# $LinuxKorea: seqdict.py,v 1.3 2001/10/09 06:45:10 perky Exp $
+#
+
+class DictQueue:
+
+ def __init__(self):
+ self.__data = {}
+ self.__fifo = []
+
+ # Operators
+
+ def __setitem__(self, key, item):
+ if self.__data.has_key(key):
+ self.__fifo.remove(key)
+ self.__data[key] = item
+ self.__fifo.append(key)
+
+ def __delitem__(self, key):
+ del self.__data[key]
+ self.__fifo.remove(key)
+
+ def __getitem__(self, key):
+ return self.__data[key]
+
+ def __len__(self):
+ return len(self.__fifo)
+
+ def __repr__(self):
+ r = []
+ for k in self.__fifo:
+ r.append("%s : %s" % (repr(k), repr(self.__data[k])))
+ return '{' + ', '.join(r) + '}'
+
+ # Dictionary-Style Methods
+
+ def keys(self):
+ return self.__fifo
+
+ def items(self):
+ r = []
+ for k in self.__fifo:
+ r.append((k, self.__data[k]))
+ return r
+
+ def values(self):
+ r = []
+ for k in self.__fifo:
+ r.append(self.__data[k])
+ return r
+
+ def has_key(self, key):
+ return self.__data.has_key(key)
+
+ def popitem(self, seq=0):
+ r = self.peekitem(seq)
+ self.chop(seq)
+ return r
+
+ def peekitem(self, seq=0):
+ k = self.__fifo[seq]
+ return (k, self.__data[k])
+
+ # List-Style Methods
+
+ def append(self, key, item):
+ return self.__setitem__(key, item)
+
+ def pop(self, seq=0):
+ r = self.peek(seq)
+ self.chop(seq)
+ return r
+
+ def peek(self, seq=0):
+ return self.__data[self.__fifo[seq]]
+
+ def chop(self, seq=0):
+ k = self.__fifo[seq]
+ del self.__fifo[seq]
+ del self.__data[k]
+
+ def remove(self, data):
+ self.pop(self.values().index(data))
+
+ def index(self, data):
+ return self.values().index(data)
+
+
+if __name__ == "__main__":
+ s = DictQueue()
+ s[100] = "Anryung~"
+ s[10] = "Hello"
+ s['hmm'] = ("merong", "kenny")
+
+ print "1. ================================"
+ print s, s.keys(), s.items()
+ print s.values(), s[100]
+
+ print "2. ================================"
+ del s[100]
+ print s
+
+ print "3. ================================"
+ s.append(['memm', 1,2,3], 'they')
+ s.append("Arigato!", 'ryoko')
+ print s
+ s.remove('Hello')
+ print "REMOVED Hello", s
+ print "PEEK", s.peek()
+ print s
+ print "POPITEM", s.popitem()
+ print "PEEKITEM", s.peekitem()
+ print s
+ print "POP1", s.pop(1)
+ print s
+
-raise NotImplementedError, "Pure dictqueue isn't implemented yet"
|
|
From: Chang <pe...@us...> - 2002-04-15 17:52:34
|
perky 02/04/15 10:52:23 Modified: scripts scands.py Log: log accumulator test Revision Changes Path 1.2 +0 -0 py-msnlib/scripts/scands.py Index: scands.py =================================================================== RCS file: /cvsroot/msnlib/py-msnlib/scripts/scands.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 |