Skip to content
Snippets Groups Projects
Commit be6dff13 authored by Suzanne Dupéron's avatar Suzanne Dupéron
Browse files

find_default function for Red-Black trees

parent 201eb8c9
Branches
Tags
Loading
......@@ -31,6 +31,10 @@ let find key map =
let find_opt key map =
try Some (find key map) with Not_found -> None
let find_default key make_default_v map =
try find key map, map with
Not_found -> let v = make_default_v () in v, add key v map
let has_key key map =
match find_opt key map with
Some _ -> true
......
......@@ -57,6 +57,13 @@ val find : 'key -> ('key, 'value) t -> 'value
val find_opt : 'key -> ('key, 'value) t -> 'value option
(* The value of the call [find_default key make_default_v map] is
[value] if the key [key] is bound to [value] in the map [map], and
[make_default_v ()] otherwise. In the first case, the
[make_default_v] function is not executed *)
val find_default : 'key -> (unit -> 'value) -> ('key, 'value) map -> 'value * ('key, 'value) map
(* The value of the call [find_opt key map] is [true] if the key
[key] is bound to some value in the map [map], and [None]
otherwise. *)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment