Coccinelle release 1.0.0-rc13
[bpt/coccinelle.git] / bundles / menhirLib / menhir-20120123 / src / stringMap.ml
1 (**************************************************************************)
2 (* *)
3 (* Menhir *)
4 (* *)
5 (* François Pottier, INRIA Rocquencourt *)
6 (* Yann Régis-Gianas, PPS, Université Paris Diderot *)
7 (* *)
8 (* Copyright 2005-2008 Institut National de Recherche en Informatique *)
9 (* et en Automatique. All rights reserved. This file is distributed *)
10 (* under the terms of the Q Public License version 1.0, with the change *)
11 (* described in file LICENSE. *)
12 (* *)
13 (**************************************************************************)
14
15 include Map.Make (String)
16
17 let cardinal s =
18 fold (fun _ _ x -> x + 1) s 0
19
20 let filter pred map =
21 fold (fun key value map ->
22 if pred key value then
23 add key value map
24 else
25 map) map empty
26
27 let restrict domain map =
28 filter (fun k _ -> StringSet.mem k domain) map
29
30 let domain map =
31 fold (fun key _ acu -> StringSet.add key acu) map StringSet.empty