Permalink
Browse files

[enhance] db3: Use TabMap instead of Map for eids

  • Loading branch information...
1 parent 20bbd87 commit 5929a5eeca324ea4baa4d78af2f34d932049b948 Raja committed Jun 30, 2011
Showing with 65 additions and 40 deletions.
  1. +20 −12 database/db3/eidMap.ml
  2. +29 −12 database/db3/eidMap.mli
  3. +12 −12 database/db3/hldb.ml
  4. +3 −3 database/db3/ioManager.ml
  5. +1 −1 database/db3/revisionMachine.ml
View
32 database/db3/eidMap.ml
@@ -1,18 +1,26 @@
(*
- Copyright © 2011 MLstate
+ Copyright © 2011 MLstate
- This file is part of OPA.
+ 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 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.
+ 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/>.
+ 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 Eid.Map
+
+module EidTabMap =
+ TabMap.Make(struct
+ type key = Eid.t
+ let value = Eid.value
+ let make = Eid.make
+ end)
+
+include EidTabMap
View
41 database/db3/eidMap.mli
@@ -1,18 +1,35 @@
(*
- Copyright © 2011 MLstate
+ Copyright © 2011 MLstate
- This file is part of OPA.
+ 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 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.
+ 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/>.
+ 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 BaseMapSig.S with type key = Eid.t
+
+type key = Eid.t
+type 'a t
+
+val empty : unit -> 'a t
+val is_empty : 'a t -> bool
+val add : key -> 'a -> 'a t -> 'a t
+
+val find : key -> 'a t -> 'a
+val find_opt : key -> 'a t -> 'a option
+
+val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
+val iter : (key -> 'a -> unit) -> 'a t -> unit
+
+val keys : 'a t -> key list
+val max : 'a t -> key * 'a
+val size : 'a t -> int
+val resize : 'a t -> int -> unit
View
24 database/db3/hldb.ml
@@ -41,7 +41,7 @@ type t = {
uid_of_eid : (Uid.t RevisionMap.t) EidMap.t ;
node_of_uid : node_map ;
index : index ;
- tmp_uid_of_eid : Uid.t EidMap.t ;
+ tmp_uid_of_eid : Uid.t Eid.Map.t ;
tmp_node_of_uid : Node.t Uid.Map.t ;
}
@@ -81,9 +81,9 @@ type t = {
) db.tmp_node_of_uid "\n"
let print_tmp_uid_map db =
- if db.tmp_uid_of_eid = EidMap.empty
+ if Eid.Map.is_empty db.tmp_uid_of_eid
then "Empty"
- else EidMap.fold (
+ else Eid.Map.fold (
fun eid uid acc -> Printf.sprintf "%s\t%d -> %s\n"
acc (Eid.value eid) (Uid.to_string uid)
) db.tmp_uid_of_eid "\n"
@@ -99,7 +99,7 @@ type t = {
) map ("", ""))
let print_uid_map db =
- if db.uid_of_eid = EidMap.empty then "Empty"
+ if EidMap.is_empty db.uid_of_eid then "Empty"
else
EidMap.fold (
fun eid map acc -> Printf.sprintf "%s%d -> %s"
@@ -177,7 +177,7 @@ type t = {
if rev < db.rev then _get_uid_of_eid db rev eid
else
- try EidMap.find eid db.tmp_uid_of_eid
+ try Eid.Map.find eid db.tmp_uid_of_eid
with Not_found -> _get_uid_of_eid db rev eid
(* looking for an uid from an eid into the different maps of the db,
@@ -255,7 +255,7 @@ type t = {
writen on disk. *)
let clean_tmp_maps db =
{ db with
- tmp_uid_of_eid = EidMap.empty ;
+ tmp_uid_of_eid = Eid.Map.empty ;
tmp_node_of_uid = Uid.Map.empty ;
}
@@ -275,13 +275,13 @@ type t = {
let eid_0 = Eid.make 0 in
let rev_0 = Revision.make 0 in
let content = RevisionMap.add rev_0 uid_0 RevisionMap.empty in
- EidMap.add eid_0 content EidMap.empty in
+ EidMap.add eid_0 content (EidMap.empty ()) in
let node_of_uid, tmp_node_of_uid = (UidMap.add uid_0 t (UidMap.empty ())), Uid.Map.empty in
let tcount = Eid.make 0 in
let next_uid = uid_1 in
let index = StringMap.empty in
- let tmp_uid_of_eid = EidMap.empty in
+ let tmp_uid_of_eid = Eid.Map.empty in
{ rev;
tcount;
next_uid;
@@ -301,7 +301,7 @@ type t = {
uid_of_eid;
node_of_uid;
index;
- tmp_uid_of_eid = EidMap.empty;
+ tmp_uid_of_eid = Eid.Map.empty;
tmp_node_of_uid = Uid.Map.empty;
}
@@ -389,7 +389,7 @@ type t = {
let eid, _= get_eid_of_path db cur_rev path in
let revisions = RevisionMap.keys (EidMap.find eid db.uid_of_eid) in
let revisions =
- if Option.is_some (EidMap.find_opt eid db.tmp_uid_of_eid)
+ if Option.is_some (Eid.Map.find_opt eid db.tmp_uid_of_eid)
then cur_rev::revisions else revisions in
revisions
with Not_found | UnqualifiedPath ->
@@ -433,10 +433,10 @@ type t = {
let map = EidMap.find eid db.uid_of_eid in
let new_map = RevisionMap.add rev uid map in
EidMap.add eid new_map acc1,
- EidMap.add eid uid acc2
+ Eid.Map.add eid uid acc2
with Not_found ->
EidMap.add eid (RevisionMap.add rev uid RevisionMap.empty) acc1,
- EidMap.add eid uid acc2
+ Eid.Map.add eid uid acc2
) (db.uid_of_eid, db.tmp_uid_of_eid) uid_list
let update_node_of_uid db node_list =
View
6 database/db3/ioManager.ml
@@ -899,13 +899,13 @@ let read_dbstate fm =
logfm fm "Read dbstate at %d (length %d)" (F.position_in fm F.Db_state) length;
let uidmap =
- let mappumulator = ref (EidMap.empty, 0) in
- if is_empty then EidMap.empty
+ let mappumulator = ref ((EidMap.empty ()), 0) in
+ if is_empty then (EidMap.empty ())
else (
try
iscorrupted (F.read_char fm F.Db_state) cc0;
let size = F.read_int fm F.Db_state in
- Loop.For.range 0 size EidMap.empty (
+ Loop.For.range 0 size (EidMap.empty ()) (
fun _ uidmap -> (
let _lastpos = F.position_in fm F.Db_state in
let eid, rev_size =
View
2 database/db3/revisionMachine.ml
@@ -59,7 +59,7 @@ let purge_eidmap lastrevision uidmap lasteid =
neweidmap
else
EidMap.add eid map neweidmap)
- ) uidmap EidMap.empty
+ ) uidmap (EidMap.empty ())
let purge_nodemap lastuid nodemap =

0 comments on commit 5929a5e

Please sign in to comment.