1
(************************************************************************)
2
(* v * The Coq Proof Assistant / The Coq Development Team *)
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
4
(* \VV/ **************************************************************)
5
(* // * This file is distributed under the terms of the *)
6
(* * GNU Lesser General Public License Version 2.1 *)
7
(************************************************************************)
9
(* $Id: nbtermdn.ml 11282 2008-07-28 11:51:53Z msozeau $ *)
19
(* Named, bounded-depth, term-discrimination nets.
21
Term-patterns are stored in discrimination-nets, which are
22
themselves stored in a hash-table, indexed by the first label.
23
They are also stored by name in a table on-the-side, so that we can
24
override them if needed. *)
26
(* The former comments are from Chet.
27
See the module dn.ml for further explanations.
31
mutable table : ('na,constr_pattern * 'a) Gmap.t;
32
mutable patterns : (global_reference option,'a Btermdn.t) Gmap.t }
34
type ('na,'a) frozen_t =
35
('na,constr_pattern * 'a) Gmap.t
36
* (global_reference option,'a Btermdn.t) Gmap.t
40
patterns = Gmap.empty }
43
try Gmap.find hkey dnm with Not_found -> Btermdn.create ()
45
let add dn (na,(pat,valu)) =
46
let hkey = Option.map fst (Termdn.constr_pat_discr pat) in
47
dn.table <- Gmap.add na (pat,valu) dn.table;
48
let dnm = dn.patterns in
49
dn.patterns <- Gmap.add hkey (Btermdn.add None (get_dn dnm hkey) (pat,valu)) dnm
52
let (pat,valu) = Gmap.find na dn.table in
53
let hkey = Option.map fst (Termdn.constr_pat_discr pat) in
54
dn.table <- Gmap.remove na dn.table;
55
let dnm = dn.patterns in
56
dn.patterns <- Gmap.add hkey (Btermdn.rmv None (get_dn dnm hkey) (pat,valu)) dnm
58
let in_dn dn na = Gmap.mem na dn.table
60
let remap ndn na (pat,valu) =
62
add ndn (na,(pat,valu))
66
match (Termdn.constr_val_discr valu) with
67
| Dn.Label(l,_) -> Some l
70
try Btermdn.lookup None (Gmap.find hkey dn.patterns) valu with Not_found -> []
72
let app f dn = Gmap.iter f dn.table
74
let dnet_depth = Btermdn.dnet_depth
76
let freeze dn = (dn.table, dn.patterns)
78
let unfreeze (fnm,fdnm) dn =
83
dn.table <- Gmap.empty;
84
dn.patterns <- Gmap.empty
87
(Gmap.to_list dn.table, Gmap.to_list dn.patterns)