aboutsummaryrefslogtreecommitdiff
path: root/pyecsca/ec/context.py
diff options
context:
space:
mode:
authorJ08nY2023-02-21 00:06:22 +0100
committerJ08nY2023-07-24 14:35:50 +0200
commitf5aaa6e0456628c4384ef498235549cc789ef9ca (patch)
treef864ddc27d667e99cc52d563c19297860594dfbd /pyecsca/ec/context.py
parent96d95c13fe9cdf72254c93406d723382b5e426fd (diff)
downloadpyecsca-f5aaa6e0456628c4384ef498235549cc789ef9ca.tar.gz
pyecsca-f5aaa6e0456628c4384ef498235549cc789ef9ca.tar.zst
pyecsca-f5aaa6e0456628c4384ef498235549cc789ef9ca.zip
Diffstat (limited to 'pyecsca/ec/context.py')
-rw-r--r--pyecsca/ec/context.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/pyecsca/ec/context.py b/pyecsca/ec/context.py
index 49c886d..dd609f8 100644
--- a/pyecsca/ec/context.py
+++ b/pyecsca/ec/context.py
@@ -15,7 +15,7 @@ A :py:class:`NullContext` does not trace any actions and is the default context.
from abc import abstractmethod, ABC
from collections import OrderedDict
from copy import deepcopy
-from typing import List, Optional, ContextManager, Any, Tuple, Sequence
+from typing import List, Optional, ContextManager, Any, Tuple, Sequence, Callable
from public import public
@@ -131,6 +131,17 @@ class Tree(OrderedDict):
result += "\t" * depth + str(key) + ":" + str(value) + "\n"
return result
+ def walk(self, callback: Callable[[Any], None]) -> None:
+ """
+ Walk the tree, depth-first, with the callback.
+
+ :param callback: The callback to call for all values in the tree.
+ """
+ for key, val in self.items():
+ callback(key)
+ if isinstance(val, Tree):
+ val.walk(callback)
+
def __repr__(self):
return self.repr()