Skip to content
This repository
Newer
Older
100644 82 lines (67 sloc) 2.018 kb
fccc6851 » MLstate
2011-06-21 Initial open-source release
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (**
19 Hashtbl with sorted wrt their input order.
20 @author Mathieu Barbin
21 *)
22
23 (**
24 this structure comes when :
25 + you don't need to remove elt, (just replace)
26 + you want to find quickly elt from keys
27 + you want to preserve input ordered in iter and fold
28 + you need both rev and normal quick and tail
29 + you dont care about the size of the table. (we use several redondant
30 structures for keeping the tail recusive for folding in both direction)
31 *)
32
33 type ('a, 'b) t
34 val create : int -> ('a, 'b) t
35 val clear : ('a, 'b) t -> unit
36 val add : ('a, 'b) t -> 'a -> 'b -> unit
37 val replace : ('a, 'b) t -> 'a -> 'b -> unit
38
39 (**
40 Same complexity than [Hashtbl.find]
41 *)
42 val find_opt : ('a, 'b) t -> 'a -> 'b option
43
44 (**
45 tail rec, O(n)
46 *)
47 val to_list : ('a, 'b) t -> ('a * 'b) list
48
49 (**
50 tail rec, O(n)
51 *)
52 val to_rev_list : ('a, 'b) t -> ('a * 'b) list
53
54 (**
55 Same complexity than [Hashtbl.mem]
56 *)
57 val mem : ('a, 'b) t -> 'a -> bool
58
59 (**
60 tail rec, O(n)
61 *)
62 val iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit
63
64 (**
65 tail rec, O(n)
66 *)
67 val rev_iter : ('a -> 'b -> unit) -> ('a, 'b) t -> unit
68
69 (**
70 tail rec, O(n)
71 *)
72 val fold_left : ('a -> 'b -> 'c -> 'a) -> 'a -> ('b, 'c) t -> 'a
73
74 (**
75 tail rec, O(n)
76 *)
77 val fold_right : ('a -> 'b -> 'c -> 'c) -> ('a, 'b) t -> 'c -> 'c
78
79 (**
80 Same complexity than [Hashtbl.length]
81 *)
82 val length : ('a, 'b) t -> int
Something went wrong with that request. Please try again.