Skip to content

Commit 416d19a

Browse files
committed
remove deprecated functions and modules
- `CCList.{split,findi,find}` - `CCHashtbl.{MakeDefault,MakeCounter}` - `CCVector.flat_map'`
1 parent 4821772 commit 416d19a

File tree

9 files changed

+2
-335
lines changed

9 files changed

+2
-335
lines changed

src/core/CCHashtbl.ml

Lines changed: 0 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -317,185 +317,3 @@ module Make(X : Hashtbl.HashedType)
317317
Format.fprintf fmt "}@]"
318318
end
319319

320-
(** {2 Default Table} *)
321-
322-
module type DEFAULT = sig
323-
type key
324-
325-
type 'a t
326-
(** A hashtable for keys of type [key] and values of type ['a] *)
327-
328-
val create : ?size:int -> 'a -> 'a t
329-
(** [create d] makes a new table that maps every key to [d] by default.
330-
@param size optional size of the initial table *)
331-
332-
val create_with : ?size:int -> (key -> 'a) -> 'a t
333-
(** Similar to [create d] but here [d] is a function called to obtain a
334-
new default value for each distinct key. Useful if the default
335-
value is stateful. *)
336-
337-
val get : 'a t -> key -> 'a
338-
(** Unfailing retrieval (possibly returns the default value) *)
339-
340-
val set : 'a t -> key -> 'a -> unit
341-
(** Replace the current binding for this key *)
342-
343-
val remove : 'a t -> key -> unit
344-
(** Remove the binding for this key. If [get tbl k] is called later, the
345-
default value for the table will be returned *)
346-
347-
val to_seq : 'a t -> (key * 'a) sequence
348-
(** Pairs of [(elem, count)] for all elements whose count is positive *)
349-
end
350-
351-
module MakeDefault(X : Hashtbl.HashedType) = struct
352-
type key = X.t
353-
354-
module T = Hashtbl.Make(X)
355-
356-
type 'a t = {
357-
default : key -> 'a;
358-
tbl : 'a T.t
359-
}
360-
361-
let create_with ?(size=32) default = { default; tbl=T.create size }
362-
363-
let create ?size d = create_with ?size (fun _ -> d)
364-
365-
let get tbl k =
366-
try T.find tbl.tbl k
367-
with Not_found ->
368-
let v = tbl.default k in
369-
T.add tbl.tbl k v;
370-
v
371-
372-
let set tbl k v = T.replace tbl.tbl k v
373-
374-
let remove tbl k = T.remove tbl.tbl k
375-
376-
let to_seq tbl k = T.iter (fun key v -> k (key,v)) tbl.tbl
377-
end
378-
379-
(** {2 Count occurrences using a Hashtbl} *)
380-
381-
module type COUNTER = sig
382-
type elt
383-
(** Elements that are to be counted *)
384-
385-
type t
386-
387-
val create : int -> t
388-
(** A counter maps elements to natural numbers (the number of times this
389-
element occurred) *)
390-
391-
val incr : t -> elt -> unit
392-
(** Increment the counter for the given element *)
393-
394-
val incr_by : t -> int -> elt -> unit
395-
(** Add or remove several occurrences at once. [incr_by c x n]
396-
will add [n] occurrences of [x] if [n>0],
397-
and remove [abs n] occurrences if [n<0]. *)
398-
399-
val get : t -> elt -> int
400-
(** Number of occurrences for this element *)
401-
402-
val decr : t -> elt -> unit
403-
(** Remove one occurrence of the element
404-
@since 0.14 *)
405-
406-
val length : t -> int
407-
(** Number of distinct elements
408-
@since 0.14 *)
409-
410-
val add_seq : t -> elt sequence -> unit
411-
(** Increment each element of the sequence *)
412-
413-
val of_seq : elt sequence -> t
414-
(** [of_seq s] is the same as [add_seq (create ())] *)
415-
416-
val to_seq : t -> (elt * int) sequence
417-
(** [to_seq tbl] returns elements of [tbl] along with their multiplicity
418-
@since 0.14 *)
419-
420-
val add_list : t -> (elt * int) list -> unit
421-
(** Similar to {!add_seq}
422-
@since 0.14 *)
423-
424-
val of_list : (elt * int) list -> t
425-
(** Similar to {!of_seq}
426-
@since 0.14 *)
427-
428-
val to_list : t -> (elt * int) list
429-
(** @since 0.14 *)
430-
end
431-
432-
module MakeCounter(X : Hashtbl.HashedType)
433-
: COUNTER
434-
with type elt = X.t
435-
and type t = int Hashtbl.Make(X).t
436-
= struct
437-
type elt = X.t
438-
439-
module T = Hashtbl.Make(X)
440-
441-
type t = int T.t
442-
443-
let create size = T.create size
444-
445-
let get tbl x = try T.find tbl x with Not_found -> 0
446-
447-
let length = T.length
448-
449-
let incr tbl x =
450-
let n = get tbl x in
451-
T.replace tbl x (n+1)
452-
453-
let incr_by tbl n x =
454-
let n' = get tbl x in
455-
if n' + n <= 0
456-
then T.remove tbl x
457-
else T.replace tbl x (n+n')
458-
459-
let decr tbl x = incr_by tbl 1 x
460-
461-
let add_seq tbl seq = seq (incr tbl)
462-
463-
let of_seq seq =
464-
let tbl = create 32 in
465-
add_seq tbl seq;
466-
tbl
467-
468-
let to_seq tbl yield = T.iter (fun x i -> yield (x,i)) tbl
469-
470-
let add_list tbl l =
471-
List.iter (fun (x,i) -> incr_by tbl i x) l
472-
473-
let of_list l =
474-
let tbl = create 32 in
475-
add_list tbl l;
476-
tbl
477-
478-
let to_list tbl =
479-
T.fold (fun x i acc -> (x,i) :: acc) tbl []
480-
end
481-
482-
(*$inject
483-
module C = MakeCounter(CCInt)
484-
485-
let list_int = Q.(make
486-
~print:Print.(list (pair int int))
487-
~small:List.length
488-
~shrink:Shrink.(list ?shrink:None)
489-
Gen.(list small_int >|= List.map (fun i->i,1))
490-
)
491-
492-
*)
493-
494-
(*$Q
495-
list_int (fun l -> \
496-
l |> C.of_list |> C.to_list |> List.length = \
497-
(l |> CCList.sort_uniq |> List.length))
498-
list_int (fun l -> \
499-
l |> C.of_list |> C.to_seq |> Sequence.fold (fun n(_,i)->i+n) 0 = \
500-
List.fold_left (fun n (_,_) ->n+1) 0 l)
501-
*)

src/core/CCHashtbl.mli

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -189,103 +189,3 @@ end
189189
module Make(X : Hashtbl.HashedType) :
190190
S with type key = X.t and type 'a t = 'a Hashtbl.Make(X).t
191191

192-
(** {2 Default Table}
193-
194-
A table with a default element for keys that were never added.
195-
196-
@deprecated since 0.16, should be merged into [Make] itself *)
197-
198-
module type DEFAULT = sig
199-
type key
200-
201-
type 'a t
202-
(** A hashtable for keys of type [key] and values of type ['a] *)
203-
204-
val create : ?size:int -> 'a -> 'a t
205-
(** [create d] makes a new table that maps every key to [d] by default.
206-
@param size optional size of the initial table *)
207-
208-
val create_with : ?size:int -> (key -> 'a) -> 'a t
209-
(** Similar to [create d] but here [d] is a function called to obtain a
210-
new default value for each distinct key. Useful if the default
211-
value is stateful. *)
212-
213-
val get : 'a t -> key -> 'a
214-
(** Unfailing retrieval (possibly returns the default value). This will
215-
modify the table if the key wasn't present. *)
216-
217-
val set : 'a t -> key -> 'a -> unit
218-
(** Replace the current binding for this key *)
219-
220-
val remove : 'a t -> key -> unit
221-
(** Remove the binding for this key. If [get tbl k] is called later, the
222-
default value for the table will be returned *)
223-
224-
val to_seq : 'a t -> (key * 'a) sequence
225-
(** Pairs of [(elem, value)] for all elements on which [get] was called *)
226-
end
227-
228-
module MakeDefault(X : Hashtbl.HashedType) : DEFAULT with type key = X.t
229-
230-
(** {2 Count occurrences using a Hashtbl}
231-
232-
@deprecated since 0.16, should be merged into [Make] itself *)
233-
234-
module type COUNTER = sig
235-
type elt
236-
(** Elements that are to be counted *)
237-
238-
type t
239-
240-
val create : int -> t
241-
(** A counter maps elements to natural numbers (the number of times this
242-
element occurred) *)
243-
244-
val incr : t -> elt -> unit
245-
(** Increment the counter for the given element *)
246-
247-
val incr_by : t -> int -> elt -> unit
248-
(** Add or remove several occurrences at once. [incr_by c x n]
249-
will add [n] occurrences of [x] if [n>0],
250-
and remove [abs n] occurrences if [n<0]. *)
251-
252-
val get : t -> elt -> int
253-
(** Number of occurrences for this element *)
254-
255-
val decr : t -> elt -> unit
256-
(** Remove one occurrence of the element
257-
@since 0.14 *)
258-
259-
val length : t -> int
260-
(** Number of distinct elements
261-
@since 0.14 *)
262-
263-
val add_seq : t -> elt sequence -> unit
264-
(** Increment each element of the sequence *)
265-
266-
val of_seq : elt sequence -> t
267-
(** [of_seq s] is the same as [add_seq (create ())] *)
268-
269-
val to_seq : t -> (elt * int) sequence
270-
(** [to_seq tbl] returns elements of [tbl] along with their multiplicity
271-
@since 0.14 *)
272-
273-
val add_list : t -> (elt * int) list -> unit
274-
(** Similar to {!add_seq}
275-
@since 0.14 *)
276-
277-
val of_list : (elt * int) list -> t
278-
(** Similar to {!of_seq}
279-
@since 0.14 *)
280-
281-
val to_list : t -> (elt * int) list
282-
(** @since 0.14 *)
283-
end
284-
285-
module MakeCounter(X : Hashtbl.HashedType)
286-
: COUNTER
287-
with type elt = X.t
288-
and type t = int Hashtbl.Make(X).t
289-
(** Create a new counter type
290-
The type [t] is exposed
291-
@since 0.14 *)

src/core/CCList.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,6 @@ let hd_tl = function
521521

522522
let take_drop n l = take n l, drop n l
523523

524-
let split = take_drop
525-
526524
(*$Q
527525
(Q.pair (Q.list Q.small_int) Q.int) (fun (l,i) -> \
528526
let i = abs i in \
@@ -614,14 +612,11 @@ let find_mapi f l =
614612

615613
let find_map f l = find_mapi (fun _ -> f) l
616614

617-
let find = find_map
618-
let findi = find_mapi
619-
620615
let find_idx p l = find_mapi (fun i x -> if p x then Some (i, x) else None) l
621616

622617
(*$T
623-
find (fun x -> if x=3 then Some "a" else None) [1;2;3;4] = Some "a"
624-
find (fun x -> if x=3 then Some "a" else None) [1;2;4;5] = None
618+
find_map (fun x -> if x=3 then Some "a" else None) [1;2;3;4] = Some "a"
619+
find_map (fun x -> if x=3 then Some "a" else None) [1;2;4;5] = None
625620
*)
626621

627622
let remove ?(eq=(=)) ~x l =

src/core/CCList.mli

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ val take_while : ('a -> bool) -> 'a t -> 'a t
126126
val drop_while : ('a -> bool) -> 'a t -> 'a t
127127
(** @since 0.13 *)
128128

129-
val split : int -> 'a t -> 'a t * 'a t
130-
(** Synonym to {!take_drop}
131-
@deprecated since 0.13: conflict with the {!List.split} standard function *)
132-
133129
val last : int -> 'a t -> 'a t
134130
(** [last n l] takes the last [n] elements of [l] (or less if
135131
[l] doesn't have that many elements *)
@@ -158,17 +154,10 @@ val find_map : ('a -> 'b option) -> 'a t -> 'b option
158154
the call returns [None]
159155
@since 0.11 *)
160156

161-
val find : ('a -> 'b option) -> 'a list -> 'b option
162-
(** @deprecated since 0.11 in favor of {!find_map}, for the name is too confusing *)
163-
164157
val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option
165158
(** Like {!find_map}, but also pass the index to the predicate function.
166159
@since 0.11 *)
167160

168-
val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option
169-
(** @deprecated since 0.11 in favor of {!find_mapi}, name is too confusing
170-
@since 0.3.4 *)
171-
172161
val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option
173162
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
174163
and [p x] holds. Otherwise returns [None] *)

src/core/CCListLabels.mli

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ val take_while : f:('a -> bool) -> 'a t -> 'a t
126126
val drop_while : f:('a -> bool) -> 'a t -> 'a t
127127
(** @since 0.13 *)
128128

129-
val split : int -> 'a t -> 'a t * 'a t
130-
(** Synonym to {!take_drop}
131-
@deprecated since 0.13: conflict with the {!List.split} standard function *)
132-
133129
val last : int -> 'a t -> 'a t
134130
(** [last n l] takes the last [n] elements of [l] (or less if
135131
[l] doesn't have that many elements *)
@@ -158,18 +154,10 @@ val find_map : f:('a -> 'b option) -> 'a t -> 'b option
158154
the call returns [None]
159155
@since 0.11 *)
160156

161-
(* TODO remove *)
162-
val find : f:('a -> 'b option) -> 'a list -> 'b option
163-
(** @deprecated since 0.11 in favor of {!find_map}, for the name is too confusing *)
164-
165157
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
166158
(** Like {!find_map}, but also pass the index to the predicate function.
167159
@since 0.11 *)
168160

169-
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
170-
(** @deprecated since 0.11 in favor of {!find_mapi}, name is too confusing
171-
@since 0.3.4 *)
172-
173161
val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option
174162
(** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l],
175163
and [p x] holds. Otherwise returns [None] *)

src/core/CCOpt.mli

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ type +'a t = 'a option
88
val map : ('a -> 'b) -> 'a t -> 'b t
99
(** Transform the element inside, if any *)
1010

11-
val maybe : ('a -> 'b) -> 'b -> 'a t -> 'b
12-
(** [maybe f x o] is [x] if [o] is [None],
13-
otherwise it's [f y] if [o = Some y]
14-
@deprecated, use {!map_or} *)
15-
1611
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b
1712
(** [map_or ~default f o] is [f x] if [o = Some x], [default otherwise]
1813
@since 0.16 *)
@@ -60,11 +55,6 @@ val exists : ('a -> bool) -> 'a t -> bool
6055
val for_all : ('a -> bool) -> 'a t -> bool
6156
(** @since 0.17 *)
6257

63-
val get : 'a -> 'a t -> 'a
64-
(** [get default x] unwraps [x], but if [x = None] it returns [default] instead.
65-
@since 0.4.1
66-
@deprecated use {!get_or} @since 0.18 *)
67-
6858
val get_or : default:'a -> 'a t -> 'a
6959
(** [get_or ~default o] extracts the value from [o], or
7060
returns [default] if [o = None].

0 commit comments

Comments
 (0)