aboutsummaryrefslogtreecommitdiff
path: root/tactics/nbtermdn.ml
diff options
context:
space:
mode:
authorfilliatr1999-11-19 09:11:35 +0000
committerfilliatr1999-11-19 09:11:35 +0000
commit5865d4d79f052cfb190e728e8618cb05e2ac845f (patch)
tree530892b92888f132d18c799d2a3ad221dcaa965c /tactics/nbtermdn.ml
parentf9f2c2bc695033f93a0b7352027678c4ca305ccd (diff)
discriminations nets
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@123 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'tactics/nbtermdn.ml')
-rw-r--r--tactics/nbtermdn.ml75
1 files changed, 75 insertions, 0 deletions
diff --git a/tactics/nbtermdn.ml b/tactics/nbtermdn.ml
new file mode 100644
index 0000000000..ec5de39c03
--- /dev/null
+++ b/tactics/nbtermdn.ml
@@ -0,0 +1,75 @@
+
+(* $Id$ *)
+
+open Util
+open Names
+open Generic
+open Term
+open Libobject
+open Library
+
+(* Named, bounded-depth, term-discrimination nets.
+ Implementation:
+ Term-patterns are stored in discrimination-nets, which are
+ themselves stored in a hash-table, indexed by the first label.
+ They are also stored by name in a table on-the-side, so that we can
+ override them if needed. *)
+
+(* The former comments are from Chet.
+ See the module dn.ml for further explanations.
+ Eduardo (5/8/97) *)
+
+type ('na,'a) t = {
+ mutable table : ('na,constr * 'a) Gmap.t;
+ mutable patterns : (Termdn.lbl option,'a Btermdn.t) Gmap.t }
+
+type ('na,'a) frozen_t =
+ ('na,constr * 'a) Gmap.t * (Termdn.lbl option,'a Btermdn.t) Gmap.t
+
+let create () =
+ { table = Gmap.empty;
+ patterns = Gmap.empty }
+
+let get_dn dnm hkey =
+ try Gmap.find hkey dnm with Not_found -> Btermdn.create ()
+
+let add dn (na,(pat,valu)) =
+ let hkey = option_app fst (Termdn.constr_pat_discr pat) in
+ dn.table <- Gmap.add na (pat,valu) dn.table;
+ let dnm = dn.patterns in
+ dn.patterns <- Gmap.add hkey (Btermdn.add (get_dn dnm hkey) (pat,valu)) dnm
+
+let rmv dn na =
+ let (pat,valu) = Gmap.find na dn.table in
+ let hkey = option_app fst (Termdn.constr_pat_discr pat) in
+ dn.table <- Gmap.remove na dn.table;
+ let dnm = dn.patterns in
+ dn.patterns <- Gmap.add hkey (Btermdn.rmv (get_dn dnm hkey) (pat,valu)) dnm
+
+let in_dn dn na = Gmap.mem na dn.table
+
+let remap ndn na (pat,valu) =
+ rmv ndn na;
+ add ndn (na,(pat,valu))
+
+let lookup dn valu =
+ let hkey = option_app fst (Termdn.constr_val_discr valu) in
+ try Btermdn.lookup (Gmap.find hkey dn.patterns) valu with Not_found -> []
+
+let app f dn = Gmap.iter f dn.table
+
+let dnet_depth = Btermdn.dnet_depth
+
+let freeze dn = (dn.table, dn.patterns)
+
+let unfreeze (fnm,fdnm) dn =
+ dn.table <- fnm;
+ dn.patterns <- fdnm
+
+let empty dn =
+ dn.table <- Gmap.empty;
+ dn.patterns <- Gmap.empty
+
+let to2lists dn =
+ (Gmap.to_list dn.table, Gmap.to_list dn.patterns)
+