X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fmatita%2FmatitaMisc.ml;h=e1c55feb204e02ca0e3c9354d9b1aa7eaa48c2b2;hb=de4483296d06aac3df4da10d5401b1f97c4350ab;hp=41b96793884d88546a2cd42ce06101551ddeef44;hpb=3b5b254f2faa600a14a837e95f94f953dc9959c7;p=helm.git diff --git a/helm/matita/matitaMisc.ml b/helm/matita/matitaMisc.ml index 41b967938..e1c55feb2 100644 --- a/helm/matita/matitaMisc.ml +++ b/helm/matita/matitaMisc.ml @@ -76,17 +76,30 @@ class type ['a] history = method previous : 'a method load: 'a memento -> unit method save: 'a memento + method is_begin: bool + method is_end: bool end +class basic_history (head, tail, cur) = + object + val mutable hd = head (* insertion point *) + val mutable tl = tail (* oldest inserted item *) + val mutable cur = cur (* current item for the history *) + + method is_begin = cur <= tl + method is_end = cur >= hd + end + + class shell_history size = let size = size + 1 in let decr x = let x' = x - 1 in if x' < 0 then size + x' else x' in let incr x = (x + 1) mod size in object (self) val data = Array.create size "" - val mutable hd = 0 (* insertion point *) - val mutable tl = -1 (* oldest inserted item *) - val mutable cur = -1 (* current item for the history *) + + inherit basic_history (0, -1 , -1) + method add s = data.(hd) <- s; if tl = -1 then tl <- hd; @@ -112,9 +125,9 @@ class ['a] browser_history ?memento size init = object (self) initializer match memento with Some m -> self#load m | _ -> () val data = Array.create size init - val mutable hd = 0 - val mutable tl = 0 - val mutable cur = 0 + + inherit basic_history (0, 0, 0) + method previous = if cur = tl then raise History_failure; cur <- cur - 1;