Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[enhance] db3: add list module, with map interface

  • Loading branch information...
commit c36bfed2d6d6f1c0b2022340dbaca39636609cb6 1 parent b82f33d
Raja authored
View
1  database.mllib
@@ -73,4 +73,5 @@ database/Xml_dump
#Internal structs
database/db3/structs/SigListMap
database/db3/structs/RaListMap
+database/db3/structs/SimpleListMap
database/db3/structs/TabMap
View
81 database/db3/structs/simpleListMap.ml
@@ -0,0 +1,81 @@
+(*
+ Copyright © 2011 MLstate
+
+ This file is part of OPA.
+
+ OPA is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License, version 3, as published by
+ the Free Software Foundation.
+
+ OPA 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 Affero General Public License for
+ more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with OPA. If not, see <http://www.gnu.org/licenses/>.
+*)
+
+(* -- Normal log -- *)
+let debug fmt =
+ #<If:DEBUG_DB$minlevel 5> Printf.fprintf stdout ("[ListMap]"^^fmt^^"\n%!")
+ #<Else> Printf.ifprintf stderr ("[ListMap]"^^fmt^^"\n%!")
+ #<End>
+
+ let print fmt = Logger.info ("[ListMap] "^^fmt)
+
+let error fmt = Logger.error ("[ListMap] "^^fmt)
+
+(* -- *)
+
+type key = Revision.t
+type 'a t = (Revision.t * 'a) list
+
+let empty = []
+
+let is_empty = BaseList.is_empty
+
+let add k v lst =
+ match lst with
+ | [] -> [k,v]
+ | (kk,_)::tl ->
+ (match Revision.compare k kk with
+ | 0 -> (k,v) :: tl
+ | 1 -> (k,v) :: lst
+ | -1 ->
+ (debug "Try to insert an older revision : %s, head is %s"
+ (Revision.to_string k) (Revision.to_string kk);
+ BaseList.insert_sorted ~cmp:(fun (a,_) (b,_) -> (Revision.compare a b) * -1) ~conflict:(fun a _ -> [a]) (k,v) lst
+ )
+ | _ -> assert false)
+
+let fold f lst acc =
+ let f = fun a (k,v) -> f k v a in
+ List.fold_left f acc lst
+
+let iter f lst =
+ let f = fun (k,v) -> f k v in
+ List.iter f lst
+
+let rev_iter f lst =
+ iter f (List.rev lst)
+
+let find = List.assoc
+
+let find_inf key lst =
+ let rec aux = function
+ | [] -> raise Not_found
+ | (k,v)::y ->
+ if Revision.compare k key > 0 then aux y
+ else k,v
+ in aux lst
+
+let size = List.length
+
+let max = function
+ | [] -> raise Not_found
+ | x::_ -> x
+
+let keys lst = fst (List.split lst)
+
+let remove_last = List.tl
View
19 database/db3/structs/simpleListMap.mli
@@ -0,0 +1,19 @@
+(*
+ Copyright © 2011 MLstate
+
+ This file is part of OPA.
+
+ OPA is free software: you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License, version 3, as published by
+ the Free Software Foundation.
+
+ OPA 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 Affero General Public License for
+ more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with OPA. If not, see <http://www.gnu.org/licenses/>.
+*)
+
+include SigListMap.S
Please sign in to comment.
Something went wrong with that request. Please try again.