From 82826db011db098a667a58f2fd5706fdd539db39 Mon Sep 17 00:00:00 2001 From: Josh Berdine Date: Thu, 29 Oct 2020 13:27:27 -0700 Subject: [PATCH] [sledge] Add Trm.height Reviewed By: da319 Differential Revision: D24532357 fbshipit-source-id: 32fb92d91 --- sledge/src/trm.ml | 1 + sledge/src/trm.mli | 1 + 2 files changed, 2 insertions(+) diff --git a/sledge/src/trm.ml b/sledge/src/trm.ml index 93ad112e4..00405165c 100644 --- a/sledge/src/trm.ml +++ b/sledge/src/trm.ml @@ -496,3 +496,4 @@ let subtrms e = Iter.from_labelled_iter (iter_subtrms e) (** Query *) let fv e = Var.Set.of_iter (vars e) +let rec height e = 1 + Iter.fold ~f:(fun x -> max (height x)) (subtrms e) 0 diff --git a/sledge/src/trm.mli b/sledge/src/trm.mli index 67120bfe0..a7229fc2d 100644 --- a/sledge/src/trm.mli +++ b/sledge/src/trm.mli @@ -96,6 +96,7 @@ val map : t -> f:(t -> t) -> t val seq_size_exn : t -> t val seq_size : t -> t option val fv : t -> Var.Set.t +val height : t -> int (** Traverse *)