-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgeneric_util_hash.ml
More file actions
23 lines (20 loc) · 607 Bytes
/
generic_util_hash.ml
File metadata and controls
23 lines (20 loc) · 607 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(** Extra functions on hashtables *)
open Generic_util
(** [safe_find], catches the [Not_found] exception with a
default value:
{[
safe_find table key some none =
try some (Hashtbl.find table key)
with Not_found -> none
]}
*)
let safe_find table key some none =
try some (Hashtbl.find table key)
with Not_found -> none
(** Update a hashtable entry.
[update table key f x0] will either initialise [table[key]] with [f x0]
or update it with [f (table[key])].
*)
let update table key upd init_val =
let new_val = upd (safe_find table key Fun.id init_val)
in Hashtbl.replace table key new_val