Add a table.zero() function to bcc.TableBase
authorBrenden Blanco <bblanco@plumgrid.com>
Tue, 23 Feb 2016 21:10:50 +0000 (13:10 -0800)
committerBrenden Blanco <bblanco@plumgrid.com>
Tue, 23 Feb 2016 21:10:50 +0000 (13:10 -0800)
It is sometimes useful to zero out the entries of table without erasing
the keys. Add a zero() function to make this easy.

Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
src/python/bcc/table.py

index a364e32..26fa868 100644 (file)
@@ -186,6 +186,10 @@ class TableBase(MutableMapping):
         for k in self.keys():
             self.__delitem__(k)
 
+    def zero(self):
+        for k in self.keys():
+            self[k] = self.Leaf()
+
     def __iter__(self):
         return TableBase.Iter(self, self.Key)