summaryrefslogtreecommitdiff
path: root/otherlibs/labltk/browser/jg_memo.ml
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/labltk/browser/jg_memo.ml')
-rw-r--r--otherlibs/labltk/browser/jg_memo.ml17
1 files changed, 17 insertions, 0 deletions
diff --git a/otherlibs/labltk/browser/jg_memo.ml b/otherlibs/labltk/browser/jg_memo.ml
new file mode 100644
index 0000000000..43a5eb15b4
--- /dev/null
+++ b/otherlibs/labltk/browser/jg_memo.ml
@@ -0,0 +1,17 @@
+(* $Id$ *)
+
+class ['a,'b] c fun:(f : 'a -> 'b) = object
+ val hash = Hashtbl.create 7
+ method get key =
+ try Hashtbl.find hash :key
+ with Not_found ->
+ let data = f key in
+ Hashtbl.add hash :key :data;
+ data
+ method clear = Hashtbl.clear hash
+ method reget key =
+ Hashtbl.remove :key hash;
+ let data = f key in
+ Hashtbl.add hash :key :data;
+ data
+end