We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 31455b0 commit 0674d64Copy full SHA for 0674d64
real-world-ocaml/counter.ml
@@ -0,0 +1,15 @@
1
+open Base
2
+
3
+type t = (string, int, String.comparator_witness) Map.t
4
5
+let empty = Map.empty (module String)
6
7
+let to_list t = Map.to_alist t
8
9
+let touch t s =
10
+ let count =
11
+ match Map.find t s with
12
+ | None -> 0
13
+ | Some x -> x
14
+ in
15
+ Map.set t ~key:s ~data:(count + 1)
real-world-ocaml/counter.mli
@@ -0,0 +1,14 @@
+(** A collection of string frequency counts *)
+type t
+(** The empty set of frequency counts *)
+val empty : t
+(** Bump the frequency count for the given string *)
+val touch : t -> string -> t
+(** Converts the set of frequency counts to an association list. A string shows
+ up at most once, and the counts are >= 1. *)
+val to_list : t -> (string * int) list
0 commit comments