]> xenbits.xensource.com Git - xenclient/toolstack.git/commitdiff
add varmap
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 18 May 2009 23:28:06 +0000 (16:28 -0700)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Mon, 18 May 2009 23:28:06 +0000 (16:28 -0700)
libs/stdext/Makefile
libs/stdext/varmap.ml [new file with mode: 0644]
libs/stdext/varmap.mli [new file with mode: 0644]

index 2b444044547398e2bac86527f850c03c7843e65e..95d5b9ace503e23b4d21ae04f3685d25421063c4 100644 (file)
@@ -6,7 +6,7 @@ OCAMLINCLUDE += -I ../uuid
 OCAML_TEST_INC = -I $(shell ocamlfind query oUnit)
 OCAML_TEST_LIB = $(shell ocamlfind query oUnit)/oUnit.cmxa
 
-OBJS = filenameext stringext hashtblext listext pervasiveext threadext ring qring trie opt unixext bigbuffer vIO
+OBJS = filenameext stringext hashtblext listext pervasiveext threadext ring qring trie opt unixext bigbuffer vIO varmap
 INTF = $(foreach obj, $(OBJS),$(obj).cmi)
 LIBS = stdext.cma stdext.cmxa
 
diff --git a/libs/stdext/varmap.ml b/libs/stdext/varmap.ml
new file mode 100644 (file)
index 0000000..3704305
--- /dev/null
@@ -0,0 +1,26 @@
+(*
+ * Copyright (C) 2009      Citrix Ltd.
+ * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+exception Failed_assoc of string
+exception Failed_revassoc
+
+type 'a table = (string * 'a) list
+
+let assoc (table: 'a table) x =
+       try snd (List.find (fun (a, b) -> x = a) table)
+       with Not_found -> raise (Failed_assoc x)
+
+let rev_assoc (table: 'a table) y =
+       try fst (List.find (fun (a, b) -> y = b) table)
+       with Not_found -> raise Failed_revassoc 
diff --git a/libs/stdext/varmap.mli b/libs/stdext/varmap.mli
new file mode 100644 (file)
index 0000000..8ce5ebf
--- /dev/null
@@ -0,0 +1,22 @@
+(*
+ * Copyright (C) 2009      Citrix Ltd.
+ * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *)
+
+exception Failed_assoc of string
+exception Failed_revassoc
+
+type 'a table = (string * 'a) list
+
+val assoc : 'a table -> string -> 'a
+val rev_assoc : 'a table -> 'a -> string