From 416d19a7638512c711995724d0581e3a0eae9bb0 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Tue, 24 Jan 2017 23:57:04 +0100 Subject: [PATCH] remove deprecated functions and modules - `CCList.{split,findi,find}` - `CCHashtbl.{MakeDefault,MakeCounter}` - `CCVector.flat_map'` --- src/core/CCHashtbl.ml | 182 -------------------------------------- src/core/CCHashtbl.mli | 100 --------------------- src/core/CCList.ml | 9 +- src/core/CCList.mli | 11 --- src/core/CCListLabels.mli | 12 --- src/core/CCOpt.mli | 10 --- src/core/CCVector.ml | 4 - src/core/CCVector.mli | 7 -- src/core/containers.ml | 2 - 9 files changed, 2 insertions(+), 335 deletions(-) diff --git a/src/core/CCHashtbl.ml b/src/core/CCHashtbl.ml index 1aa06286..1a08bb44 100644 --- a/src/core/CCHashtbl.ml +++ b/src/core/CCHashtbl.ml @@ -317,185 +317,3 @@ module Make(X : Hashtbl.HashedType) Format.fprintf fmt "}@]" end -(** {2 Default Table} *) - -module type DEFAULT = sig - type key - - type 'a t - (** A hashtable for keys of type [key] and values of type ['a] *) - - val create : ?size:int -> 'a -> 'a t - (** [create d] makes a new table that maps every key to [d] by default. - @param size optional size of the initial table *) - - val create_with : ?size:int -> (key -> 'a) -> 'a t - (** Similar to [create d] but here [d] is a function called to obtain a - new default value for each distinct key. Useful if the default - value is stateful. *) - - val get : 'a t -> key -> 'a - (** Unfailing retrieval (possibly returns the default value) *) - - val set : 'a t -> key -> 'a -> unit - (** Replace the current binding for this key *) - - val remove : 'a t -> key -> unit - (** Remove the binding for this key. If [get tbl k] is called later, the - default value for the table will be returned *) - - val to_seq : 'a t -> (key * 'a) sequence - (** Pairs of [(elem, count)] for all elements whose count is positive *) -end - -module MakeDefault(X : Hashtbl.HashedType) = struct - type key = X.t - - module T = Hashtbl.Make(X) - - type 'a t = { - default : key -> 'a; - tbl : 'a T.t - } - - let create_with ?(size=32) default = { default; tbl=T.create size } - - let create ?size d = create_with ?size (fun _ -> d) - - let get tbl k = - try T.find tbl.tbl k - with Not_found -> - let v = tbl.default k in - T.add tbl.tbl k v; - v - - let set tbl k v = T.replace tbl.tbl k v - - let remove tbl k = T.remove tbl.tbl k - - let to_seq tbl k = T.iter (fun key v -> k (key,v)) tbl.tbl -end - -(** {2 Count occurrences using a Hashtbl} *) - -module type COUNTER = sig - type elt - (** Elements that are to be counted *) - - type t - - val create : int -> t - (** A counter maps elements to natural numbers (the number of times this - element occurred) *) - - val incr : t -> elt -> unit - (** Increment the counter for the given element *) - - val incr_by : t -> int -> elt -> unit - (** Add or remove several occurrences at once. [incr_by c x n] - will add [n] occurrences of [x] if [n>0], - and remove [abs n] occurrences if [n<0]. *) - - val get : t -> elt -> int - (** Number of occurrences for this element *) - - val decr : t -> elt -> unit - (** Remove one occurrence of the element - @since 0.14 *) - - val length : t -> int - (** Number of distinct elements - @since 0.14 *) - - val add_seq : t -> elt sequence -> unit - (** Increment each element of the sequence *) - - val of_seq : elt sequence -> t - (** [of_seq s] is the same as [add_seq (create ())] *) - - val to_seq : t -> (elt * int) sequence - (** [to_seq tbl] returns elements of [tbl] along with their multiplicity - @since 0.14 *) - - val add_list : t -> (elt * int) list -> unit - (** Similar to {!add_seq} - @since 0.14 *) - - val of_list : (elt * int) list -> t - (** Similar to {!of_seq} - @since 0.14 *) - - val to_list : t -> (elt * int) list - (** @since 0.14 *) -end - -module MakeCounter(X : Hashtbl.HashedType) - : COUNTER - with type elt = X.t - and type t = int Hashtbl.Make(X).t -= struct - type elt = X.t - - module T = Hashtbl.Make(X) - - type t = int T.t - - let create size = T.create size - - let get tbl x = try T.find tbl x with Not_found -> 0 - - let length = T.length - - let incr tbl x = - let n = get tbl x in - T.replace tbl x (n+1) - - let incr_by tbl n x = - let n' = get tbl x in - if n' + n <= 0 - then T.remove tbl x - else T.replace tbl x (n+n') - - let decr tbl x = incr_by tbl 1 x - - let add_seq tbl seq = seq (incr tbl) - - let of_seq seq = - let tbl = create 32 in - add_seq tbl seq; - tbl - - let to_seq tbl yield = T.iter (fun x i -> yield (x,i)) tbl - - let add_list tbl l = - List.iter (fun (x,i) -> incr_by tbl i x) l - - let of_list l = - let tbl = create 32 in - add_list tbl l; - tbl - - let to_list tbl = - T.fold (fun x i acc -> (x,i) :: acc) tbl [] -end - -(*$inject - module C = MakeCounter(CCInt) - - let list_int = Q.(make - ~print:Print.(list (pair int int)) - ~small:List.length - ~shrink:Shrink.(list ?shrink:None) - Gen.(list small_int >|= List.map (fun i->i,1)) - ) - - *) - -(*$Q - list_int (fun l -> \ - l |> C.of_list |> C.to_list |> List.length = \ - (l |> CCList.sort_uniq |> List.length)) - list_int (fun l -> \ - l |> C.of_list |> C.to_seq |> Sequence.fold (fun n(_,i)->i+n) 0 = \ - List.fold_left (fun n (_,_) ->n+1) 0 l) -*) diff --git a/src/core/CCHashtbl.mli b/src/core/CCHashtbl.mli index 624c3f99..fea37cbf 100644 --- a/src/core/CCHashtbl.mli +++ b/src/core/CCHashtbl.mli @@ -189,103 +189,3 @@ end module Make(X : Hashtbl.HashedType) : S with type key = X.t and type 'a t = 'a Hashtbl.Make(X).t -(** {2 Default Table} - - A table with a default element for keys that were never added. - - @deprecated since 0.16, should be merged into [Make] itself *) - -module type DEFAULT = sig - type key - - type 'a t - (** A hashtable for keys of type [key] and values of type ['a] *) - - val create : ?size:int -> 'a -> 'a t - (** [create d] makes a new table that maps every key to [d] by default. - @param size optional size of the initial table *) - - val create_with : ?size:int -> (key -> 'a) -> 'a t - (** Similar to [create d] but here [d] is a function called to obtain a - new default value for each distinct key. Useful if the default - value is stateful. *) - - val get : 'a t -> key -> 'a - (** Unfailing retrieval (possibly returns the default value). This will - modify the table if the key wasn't present. *) - - val set : 'a t -> key -> 'a -> unit - (** Replace the current binding for this key *) - - val remove : 'a t -> key -> unit - (** Remove the binding for this key. If [get tbl k] is called later, the - default value for the table will be returned *) - - val to_seq : 'a t -> (key * 'a) sequence - (** Pairs of [(elem, value)] for all elements on which [get] was called *) -end - -module MakeDefault(X : Hashtbl.HashedType) : DEFAULT with type key = X.t - -(** {2 Count occurrences using a Hashtbl} - - @deprecated since 0.16, should be merged into [Make] itself *) - -module type COUNTER = sig - type elt - (** Elements that are to be counted *) - - type t - - val create : int -> t - (** A counter maps elements to natural numbers (the number of times this - element occurred) *) - - val incr : t -> elt -> unit - (** Increment the counter for the given element *) - - val incr_by : t -> int -> elt -> unit - (** Add or remove several occurrences at once. [incr_by c x n] - will add [n] occurrences of [x] if [n>0], - and remove [abs n] occurrences if [n<0]. *) - - val get : t -> elt -> int - (** Number of occurrences for this element *) - - val decr : t -> elt -> unit - (** Remove one occurrence of the element - @since 0.14 *) - - val length : t -> int - (** Number of distinct elements - @since 0.14 *) - - val add_seq : t -> elt sequence -> unit - (** Increment each element of the sequence *) - - val of_seq : elt sequence -> t - (** [of_seq s] is the same as [add_seq (create ())] *) - - val to_seq : t -> (elt * int) sequence - (** [to_seq tbl] returns elements of [tbl] along with their multiplicity - @since 0.14 *) - - val add_list : t -> (elt * int) list -> unit - (** Similar to {!add_seq} - @since 0.14 *) - - val of_list : (elt * int) list -> t - (** Similar to {!of_seq} - @since 0.14 *) - - val to_list : t -> (elt * int) list - (** @since 0.14 *) -end - -module MakeCounter(X : Hashtbl.HashedType) - : COUNTER - with type elt = X.t - and type t = int Hashtbl.Make(X).t -(** Create a new counter type - The type [t] is exposed - @since 0.14 *) diff --git a/src/core/CCList.ml b/src/core/CCList.ml index 65b55f72..e1d81548 100644 --- a/src/core/CCList.ml +++ b/src/core/CCList.ml @@ -521,8 +521,6 @@ let hd_tl = function let take_drop n l = take n l, drop n l -let split = take_drop - (*$Q (Q.pair (Q.list Q.small_int) Q.int) (fun (l,i) -> \ let i = abs i in \ @@ -614,14 +612,11 @@ let find_mapi f l = let find_map f l = find_mapi (fun _ -> f) l -let find = find_map -let findi = find_mapi - let find_idx p l = find_mapi (fun i x -> if p x then Some (i, x) else None) l (*$T - find (fun x -> if x=3 then Some "a" else None) [1;2;3;4] = Some "a" - find (fun x -> if x=3 then Some "a" else None) [1;2;4;5] = None + find_map (fun x -> if x=3 then Some "a" else None) [1;2;3;4] = Some "a" + find_map (fun x -> if x=3 then Some "a" else None) [1;2;4;5] = None *) let remove ?(eq=(=)) ~x l = diff --git a/src/core/CCList.mli b/src/core/CCList.mli index b6f01ecc..691448fb 100644 --- a/src/core/CCList.mli +++ b/src/core/CCList.mli @@ -126,10 +126,6 @@ val take_while : ('a -> bool) -> 'a t -> 'a t val drop_while : ('a -> bool) -> 'a t -> 'a t (** @since 0.13 *) -val split : int -> 'a t -> 'a t * 'a t -(** Synonym to {!take_drop} - @deprecated since 0.13: conflict with the {!List.split} standard function *) - val last : int -> 'a t -> 'a t (** [last n l] takes the last [n] elements of [l] (or less if [l] doesn't have that many elements *) @@ -158,17 +154,10 @@ val find_map : ('a -> 'b option) -> 'a t -> 'b option the call returns [None] @since 0.11 *) -val find : ('a -> 'b option) -> 'a list -> 'b option -(** @deprecated since 0.11 in favor of {!find_map}, for the name is too confusing *) - val find_mapi : (int -> 'a -> 'b option) -> 'a t -> 'b option (** Like {!find_map}, but also pass the index to the predicate function. @since 0.11 *) -val findi : (int -> 'a -> 'b option) -> 'a t -> 'b option -(** @deprecated since 0.11 in favor of {!find_mapi}, name is too confusing - @since 0.3.4 *) - val find_idx : ('a -> bool) -> 'a t -> (int * 'a) option (** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l], and [p x] holds. Otherwise returns [None] *) diff --git a/src/core/CCListLabels.mli b/src/core/CCListLabels.mli index 5d8b01c4..0d865010 100644 --- a/src/core/CCListLabels.mli +++ b/src/core/CCListLabels.mli @@ -126,10 +126,6 @@ val take_while : f:('a -> bool) -> 'a t -> 'a t val drop_while : f:('a -> bool) -> 'a t -> 'a t (** @since 0.13 *) -val split : int -> 'a t -> 'a t * 'a t -(** Synonym to {!take_drop} - @deprecated since 0.13: conflict with the {!List.split} standard function *) - val last : int -> 'a t -> 'a t (** [last n l] takes the last [n] elements of [l] (or less if [l] doesn't have that many elements *) @@ -158,18 +154,10 @@ val find_map : f:('a -> 'b option) -> 'a t -> 'b option the call returns [None] @since 0.11 *) -(* TODO remove *) -val find : f:('a -> 'b option) -> 'a list -> 'b option -(** @deprecated since 0.11 in favor of {!find_map}, for the name is too confusing *) - val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option (** Like {!find_map}, but also pass the index to the predicate function. @since 0.11 *) -val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option -(** @deprecated since 0.11 in favor of {!find_mapi}, name is too confusing - @since 0.3.4 *) - val find_idx : f:('a -> bool) -> 'a t -> (int * 'a) option (** [find_idx p x] returns [Some (i,x)] where [x] is the [i]-th element of [l], and [p x] holds. Otherwise returns [None] *) diff --git a/src/core/CCOpt.mli b/src/core/CCOpt.mli index 005d2875..1281fbe1 100644 --- a/src/core/CCOpt.mli +++ b/src/core/CCOpt.mli @@ -8,11 +8,6 @@ type +'a t = 'a option val map : ('a -> 'b) -> 'a t -> 'b t (** Transform the element inside, if any *) -val maybe : ('a -> 'b) -> 'b -> 'a t -> 'b -(** [maybe f x o] is [x] if [o] is [None], - otherwise it's [f y] if [o = Some y] - @deprecated, use {!map_or} *) - val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b (** [map_or ~default f o] is [f x] if [o = Some x], [default otherwise] @since 0.16 *) @@ -60,11 +55,6 @@ val exists : ('a -> bool) -> 'a t -> bool val for_all : ('a -> bool) -> 'a t -> bool (** @since 0.17 *) -val get : 'a -> 'a t -> 'a -(** [get default x] unwraps [x], but if [x = None] it returns [default] instead. - @since 0.4.1 - @deprecated use {!get_or} @since 0.18 *) - val get_or : default:'a -> 'a t -> 'a (** [get_or ~default o] extracts the value from [o], or returns [default] if [o = None]. diff --git a/src/core/CCVector.ml b/src/core/CCVector.ml index d8f0d283..ade9d89d 100644 --- a/src/core/CCVector.ml +++ b/src/core/CCVector.ml @@ -562,8 +562,6 @@ let flat_map_list f v = ) v; v' -let flat_map' = flat_map_seq - let (>>=) x f = flat_map f x let (>|=) x f = map f x @@ -581,8 +579,6 @@ let rev_in_place v = done ) -let rev' = rev_in_place - let rev v = let v' = copy v in rev_in_place v'; diff --git a/src/core/CCVector.mli b/src/core/CCVector.mli index 7454884e..2fb6806c 100644 --- a/src/core/CCVector.mli +++ b/src/core/CCVector.mli @@ -185,10 +185,6 @@ val flat_map_list : ('a -> 'b list) -> ('a,_) t -> ('b, 'mut) t intermediate collections. @since 0.14 *) -val flat_map' : ('a -> 'b sequence) -> ('a,_) t -> ('b, 'mut) t -(** Alias to {!flat_map_seq} - @deprecated since 0.14 , use {!flat_map_seq} *) - val (>>=) : ('a,_) t -> ('a -> ('b,_) t) -> ('b, 'mut) t (** Infix version of {!flat_map} *) @@ -214,9 +210,6 @@ val rev_in_place : ('a, rw) t -> unit (** Reverse the vector in place @since 0.14 *) -val rev' : ('a, rw) t -> unit -(** @deprecated since 0.14 old name for {!rev_in_place} *) - val rev_iter : ('a -> unit) -> ('a,_) t -> unit (** [rev_iter f a] is the same as [iter f (rev a)], only more efficient. @since 0.14 *) diff --git a/src/core/containers.ml b/src/core/containers.ml index e2829b89..ed16dd10 100644 --- a/src/core/containers.ml +++ b/src/core/containers.ml @@ -47,8 +47,6 @@ module Hashtbl = struct (* still unable to include CCHashtbl itself, for the polymorphic functions *) module type S' = CCHashtbl.S module Make' = CCHashtbl.Make - module Counter = CCHashtbl.MakeCounter - module MakeDefault = CCHashtbl.MakeDefault end module Heap = CCHeap module List = struct