package ringo

  1. Overview
  2. Docs
Caches (bounded-size key-value stores) and other bounded-size stores

Install

Dune Dependency

Authors

Maintainers

Sources

ringo-v0.6.tar.gz
md5=9e542555814d906bc8da0236e1adf815
sha512=db25e84ed67b6e55d630c372b33e61037bf197407e05ad5bf1b2b5ccf2719fab4437cbd2040d48fd15db590b52f0f1d4598105ca029749702e69e80f2ae15f51

doc/src/ringo/sized.ml.html

Source file sized.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.com>               *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

module EmptyMap (H: Hashtbl.HashedType)
: sig
   include Sigs.CACHE_MAP with type key = H.t
   val create : unit -> 'a t
end
= struct
   type key = H.t
   type 'a t = unit
   let create () = ()
   let replace () _ _ = ()
   let fold _ () acc = acc
   let fold_v _ () acc = acc
   let find_opt () _ = None
   let remove () _ = ()
   let length () = 0
   let capacity () = 0
   let clear () = ()
   module H = H
end

module SingletonMap (H: Hashtbl.HashedType)
: sig
   include Sigs.CACHE_MAP with type key = H.t
   val create : unit -> 'a t
end
= struct
   type key = H.t
   type 'a t = (key * 'a) option ref
   let create () = ref None
   let replace r k v = r := Some (k, v)
   let fold f r acc = match !r with | None -> acc | Some (k, v) -> f k v acc
   let fold_v f r acc = match !r with | None -> acc | Some (_, v) -> f v acc
   let find_opt r k =
      match !r with
      | None -> None
      | Some (kk, v) -> if H.equal k kk then Some v else None
   let remove r k =
      match !r with
      | None -> ()
      | Some (kk, _) -> if H.equal k kk then r := None
   let length r = match !r with None -> 0 | Some _ -> 1
   let capacity _ = 1
   let clear r = r := None
   module H = H
end

module EmptySet (H: Hashtbl.HashedType)
: sig
   include Sigs.CACHE_SET with type elt = H.t
   val create : t
end
= struct
   type elt = H.t
   type t = unit
   let create = ()
   let add () _ = ()
   let fold _ () acc = acc
   let mem () _ = false
   let remove () _ = ()
   let length () = 0
   let capacity () = 0
   let clear () = ()
end

module SingletonSet (H: Hashtbl.HashedType)
: sig
   include Sigs.CACHE_SET with type elt = H.t
   val create : unit -> t
end
= struct
   type elt = H.t
   type t = elt option ref
   let create () = ref None
   let add r elt = r := Some elt
   let fold f r acc = match !r with | None -> acc | Some e -> f e acc
   let mem r elt = match !r with | None -> false | Some e -> H.equal e elt
   let remove r elt =
      match !r with
      | None -> ()
      | Some e -> if H.equal e elt then r := None
   let length r = match !r with None -> 0 | Some _ -> 1
   let capacity _ = 1
   let clear r = r := None
end
OCaml

Innovation. Community. Security.