Add fold_left/right functions to the set interface (iterate in
[tatoo.git] / src / ptset.ml
index 87ca2a5..08332b3 100644 (file)
@@ -289,11 +289,17 @@ struct
   | Leaf k -> f k
   | Branch (_,_,t0,t1) -> iter f t0; iter f t1
 
-  let rec fold f s accu = match s.Node.node with
+  let rec fold_left f s accu = match s.Node.node with
   | Empty -> accu
   | Leaf k -> f k accu
-  | Branch (_,_,t0,t1) -> fold f t1 (fold f t0 accu)
+  | Branch (_,_,t0,t1) -> fold_left f t1 (fold_left f t0 accu)
 
+  let rec fold_right f s accu = match s.Node.node with
+  | Empty -> accu
+  | Leaf k -> f k accu
+  | Branch (_,_,t0,t1) -> fold_right f t0 (fold_right f t1 accu)
+
+  let fold f s accu = fold_left f s accu
 
   let rec for_all p n = match n.Node.node with
   | Empty -> true