From 7f1c6ae66fb5ddcb8b8343e625799839ccbdfd23 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 11 Jun 2018 20:10:45 -0500 Subject: [PATCH] feat(intmap): add `is_empty` function --- src/data/CCIntMap.ml | 20 +++++++++++++++----- src/data/CCIntMap.mli | 6 +++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/data/CCIntMap.ml b/src/data/CCIntMap.ml index 292d7444..7174dbcd 100644 --- a/src/data/CCIntMap.ml +++ b/src/data/CCIntMap.ml @@ -73,20 +73,30 @@ end (Bit.highest x :> int) (highest2 x)) *) -type 'a t = +(*$inject + let _list_uniq l = CCList.sort_uniq ~cmp:(fun a b-> Pervasives.compare (fst a)(fst b)) l +*) + +type +'a t = | E (* empty *) | L of int * 'a (* leaf *) | N of int (* common prefix *) * Bit.t (* bit switch *) * 'a t * 'a t let empty = E +let is_empty = function + | E -> true + | _ -> false + +(*$Q + Q.(small_list (pair int int)) (fun l -> \ + let m = of_list l in \ + is_empty m = (cardinal m = 0)) + *) + let is_prefix_ ~prefix y ~bit = prefix = Bit.mask y ~mask:bit -(*$inject - let _list_uniq l = CCList.sort_uniq ~cmp:(fun a b-> Pervasives.compare (fst a)(fst b)) l -*) - (*$Q Q.int (fun i -> \ let b = Bit.highest i in \ diff --git a/src/data/CCIntMap.mli b/src/data/CCIntMap.mli index 4cd15d9a..178e617f 100644 --- a/src/data/CCIntMap.mli +++ b/src/data/CCIntMap.mli @@ -6,10 +6,14 @@ {b status: stable} @since 0.10 *) -type 'a t +type +'a t val empty : 'a t +val is_empty : _ t -> bool +(** Is the map empty? + @since NEXT_RELEASE *) + val singleton : int -> 'a -> 'a t val doubleton : int -> 'a -> int -> 'a -> 'a t