-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[enhance] db3: add ralist module, with map interface
- Loading branch information
Raja
committed
Jul 6, 2011
1 parent
7d965b9
commit b82f33d
Showing
5 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# -*- conf -*- (for emacs) | ||
|
||
<tabMap.ml>: with_mlstate_debug | ||
<{tabMap,simpleListMap}.ml>: with_mlstate_debug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
(* | ||
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/>. | ||
*) | ||
|
||
|
||
module RA = RAList | ||
module RAL = RAList.AsList | ||
module RAA = RAList.AsArray | ||
exception Found | ||
|
||
type key = Revision.t | ||
type 'a t = (Revision.t * 'a) RA.ra_list | ||
|
||
let empty = RAL.empty | ||
|
||
let is_empty = RAL.is_empty | ||
|
||
let add key value lst = | ||
try | ||
let kk,_ = RAL.head lst in | ||
(match Revision.compare key kk with | ||
| 0 -> RAA.update lst 0 (key,value) | ||
| 1 -> RAL.cons (key,value) lst | ||
| -1 -> ( | ||
(* TODO imlement *) | ||
assert false) | ||
| _ -> assert false) | ||
with RA.Empty -> | ||
RAL.cons (key,value) lst | ||
(* | ||
if not (RAL.is_empty lst) then | ||
assert (Revision.compare (fst (RAL.head lst)) key = -1 | ||
&& (error "Try to insert an older revision : %s, head is at %s" | ||
(Revision.to_string key) (Revision.to_string (fst (RAL.head lst))); false)); | ||
RAL.cons (key,value) lst | ||
*) | ||
let fold f lst acc = | ||
let f = fun (k,v) a -> f k v a in | ||
RAL.fold f lst acc | ||
|
||
let iter f lst = | ||
let f = fun k v () -> f k v in | ||
fold f lst () | ||
|
||
let rev_iter f lst = | ||
let f = fun (k,v) () -> f k v in | ||
RAL.rev_fold f lst () | ||
|
||
let find key lst = | ||
let res = ref None in | ||
let f = fun k v -> if Revision.equal key k then (res := Some v; raise Found) in | ||
try iter f lst; raise Not_found | ||
with Found -> Option.get !res | ||
|
||
let find_inf key lst = | ||
let res = ref None in | ||
let f = fun k v -> if Revision.compare key k =1 then (res := Some (k,v); raise Found) in | ||
try iter f lst; raise Not_found | ||
with Found -> Option.get !res | ||
|
||
let size = RAA.size | ||
|
||
let max = RAL.head | ||
|
||
let keys lst = | ||
let f = fun k _ a -> k :: a in | ||
fold f lst [] | ||
|
||
let remove_last = RAL.tail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
(* | ||
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/>. | ||
*) | ||
|
||
module type S = | ||
sig | ||
type key = Revision.t | ||
type 'a t | ||
|
||
val empty: 'a t | ||
val is_empty : 'a t -> bool | ||
val add: key -> 'a -> 'a t -> 'a t | ||
val fold: (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b | ||
val iter : (key -> 'a -> unit) -> 'a t -> unit | ||
val rev_iter : (key -> 'a -> unit) -> 'a t -> unit | ||
val find : key -> 'a t -> 'a | ||
val find_inf : key -> 'a t -> key * 'a | ||
val size : 'a t -> int | ||
val max : 'a t -> key * 'a | ||
val remove_last : 'a t -> 'a t | ||
val keys : 'a t -> key list | ||
|
||
end |