Commit ff91b958 authored by POTTIER Francois's avatar POTTIER Francois

Added [TerminalSet.is_singleton].

parent 3b3071df
......@@ -102,6 +102,16 @@ and loop f qs i ss accu =
let iter f s =
fold (fun x () -> f x) s ()
let is_singleton s =
match s with
| C (_, ss, N) ->
(* Test whether only one bit is set in [ss]. We do this by turning
off the rightmost bit, then comparing to zero. *)
ss land (ss - 1) = 0
| C (_, _, C _)
| N ->
false
let cardinal s =
fold (fun _ m -> m + 1) s 0
......
......@@ -24,6 +24,10 @@ module type S = sig
val singleton: element -> t
(* [is_singleton s] tests whether [s] is a singleton set. *)
val is_singleton: t -> bool
(* [cardinal s] returns the cardinal of [s]. *)
val cardinal: t -> int
......
......@@ -593,6 +593,15 @@ module Domain = struct
let singleton x =
Leaf x
(* [is_singleton s] tests whether [s] is a singleton set. *)
let is_singleton = function
| Leaf _ ->
true
| Empty
| Branch _ ->
false
(* [choose s] returns an arbitrarily chosen element of [s], if [s]
is nonempty, and raises [Not_found] otherwise. *)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment