aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--mdpoly/abc.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mdpoly/abc.py b/mdpoly/abc.py
index 14026d6..0f51bbc 100644
--- a/mdpoly/abc.py
+++ b/mdpoly/abc.py
@@ -171,6 +171,27 @@ class Expr(ABC):
return replace_all(self)
+ def rotate_left(self) -> Expr:
+ """ Perform a left tree rotation. """
+ root = copy(self) # current root
+ pivot = copy(self.right) # new parent
+
+ root.right = pivot.left
+ pivot.left = root
+
+ return pivot
+
+ def rotate_right(self) -> Expr:
+ """ Perform a right tree rotation. """
+ root = copy(self) # current root
+ pivot = copy(root.left) # new parent
+
+ root.left = pivot.right
+ pivot.right = root
+
+ return pivot
+
+
# --- Private methods ---
@staticmethod