commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10368 - gnuradio/trunk/grc/src/utils


From: jblum
Subject: [Commit-gnuradio] r10368 - gnuradio/trunk/grc/src/utils
Date: Sat, 31 Jan 2009 20:37:18 -0700 (MST)

Author: jblum
Date: 2009-01-31 20:37:13 -0700 (Sat, 31 Jan 2009)
New Revision: 10368

Modified:
   gnuradio/trunk/grc/src/utils/__init__.py
Log:
insert for odict

Modified: gnuradio/trunk/grc/src/utils/__init__.py
===================================================================
--- gnuradio/trunk/grc/src/utils/__init__.py    2009-02-01 03:27:50 UTC (rev 
10367)
+++ gnuradio/trunk/grc/src/utils/__init__.py    2009-02-01 03:37:13 UTC (rev 
10368)
@@ -46,6 +46,32 @@
                copy_dict._keys = list(self._keys)
                return copy_dict
 
+       def insert_after(self, pos_key, key, val):
+               """
+               Insert the new key, value entry after the entry given by the 
position key.
+               If the positional key is None, insert at the end.
+               @param pos_key the positional key
+               @param key the key for the new entry
+               @param val the value for the new entry
+               """
+               index = (pos_key is None) and len(self._keys) or 
self._keys.index(pos_key)
+               assert key not in self._keys
+               self._keys.insert(index+1, key)
+               self._data[key] = val
+
+       def insert_before(self, pos_key, key, val):
+               """
+               Insert the new key, value entry before the entry given by the 
position key.
+               If the positional key is None, insert at the begining.
+               @param pos_key the positional key
+               @param key the key for the new entry
+               @param val the value for the new entry
+               """
+               index = (pos_key is not None) and self._keys.index(pos_key) or 
0 
+               assert key not in self._keys
+               self._keys.insert(index, key)
+               self._data[key] = val
+
 def exists_or_else(d, key, alt):
        if d.has_key(key): return d[key]
        else: return alt





reply via email to

[Prev in Thread] Current Thread [Next in Thread]