Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 63 lines (47 sloc) 1.675 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 type id_to_id = Ident.t IdentMap.t
20
21 type t = {
22 map : id_to_id;
23 rev : id_to_id;
24 }
25
26 let empty = {
27 map = IdentMap.empty;
28 rev = IdentMap.empty;
29 }
30
31 let add t original_id new_id = {
32 map = IdentMap.add original_id new_id t.map;
33 rev = IdentMap.add new_id original_id t.rev;
34 }
35
36 let from_map map = {
37 map = map;
38 rev = IdentMap.fold (fun k v acc -> IdentMap.safe_add v k acc) map IdentMap.empty;
39 }
40
41 let original_from_new t new_id =
42 IdentMap.find new_id t.rev
43
44 let original_from_new_opt t new_id =
45 IdentMap.find_opt new_id t.rev
46
47 let new_from_original t original_id =
48 IdentMap.find original_id t.map
49
50 let new_from_original_opt t original_id =
51 IdentMap.find_opt original_id t.map
52
53 let filter t filter =
54 IdentMap.fold
55 (fun original_id new_id filtered ->
56 match filter original_id new_id with
57 | true -> add filtered original_id new_id
58 | false -> filtered)
59 t.map empty
60
61 let pp f m =
62 IdentMap.iter (fun k v -> Format.fprintf f "%s <-> %s@ " (Ident.to_string k) (Ident.to_string v)) m.map
Something went wrong with that request. Please try again.