From 37956bccead5f3322c7630b1c892751bdcaad494 Mon Sep 17 00:00:00 2001 From: Jacques-Pascal Deplaix Date: Fri, 1 Dec 2017 12:17:32 +0000 Subject: [PATCH] Remove CCCache.default_eq_ --- benchs/run_benchs.ml | 14 +++++++------- src/data/CCCache.ml | 9 ++++----- src/data/CCCache.mli | 8 ++++---- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/benchs/run_benchs.ml b/benchs/run_benchs.ml index 4eb98522..b9c060c3 100644 --- a/benchs/run_benchs.ml +++ b/benchs/run_benchs.ml @@ -366,16 +366,16 @@ module Cache = struct let bench_fib n = let l = - [ "replacing_fib (128)", make_fib (C.replacing 128), n - ; "LRU_fib (128)", make_fib (C.lru 128), n - ; "replacing_fib (16)", make_fib (C.replacing 16), n - ; "LRU_fib (16)", make_fib (C.lru 16), n - ; "unbounded", make_fib (C.unbounded 32), n + [ "replacing_fib (128)", make_fib (C.replacing ~eq:CCInt.equal 128), n + ; "LRU_fib (128)", make_fib (C.lru ~eq:CCInt.equal 128), n + ; "replacing_fib (16)", make_fib (C.replacing ~eq:CCInt.equal 16), n + ; "LRU_fib (16)", make_fib (C.lru ~eq:CCInt.equal 16), n + ; "unbounded", make_fib (C.unbounded ~eq:CCInt.equal 32), n ] in let l = if n <= 20 - then [ "linear_fib (5)", make_fib (C.linear 5), n - ; "linear_fib (32)", make_fib (C.linear 32), n + then [ "linear_fib (5)", make_fib (C.linear ~eq:CCInt.equal 5), n + ; "linear_fib (32)", make_fib (C.linear ~eq:CCInt.equal 32), n ; "dummy_fib", make_fib C.dummy, n ] @ l else l diff --git a/src/data/CCCache.ml b/src/data/CCCache.ml index 1ad77bdc..6f680e60 100644 --- a/src/data/CCCache.ml +++ b/src/data/CCCache.ml @@ -6,7 +6,6 @@ type 'a equal = 'a -> 'a -> bool type 'a hash = 'a -> int -let default_eq_ = Pervasives.(=) let default_hash_ = Hashtbl.hash (** {2 Value interface} *) @@ -124,7 +123,7 @@ module Linear = struct !r end -let linear ?(eq=default_eq_) size = +let linear ~eq size = let size = max size 1 in let arr = Linear.make eq size in { get=(fun x -> Linear.get arr x); @@ -176,7 +175,7 @@ module Replacing = struct let size c () = c.c_size end -let replacing ?(eq=default_eq_) ?(hash=default_hash_) size = +let replacing ~eq ?(hash=default_hash_) size = let c = Replacing.make eq hash size in { get=(fun x -> Replacing.get c x); set=(fun x y -> Replacing.set c x y); @@ -298,7 +297,7 @@ module LRU(X:HASH) = struct H.iter (fun x node -> f x node.value) c.table end -let lru (type a) ?(eq=default_eq_) ?(hash=default_hash_) size = +let lru (type a) ~eq ?(hash=default_hash_) size = let module L = LRU(struct type t = a let equal = eq @@ -360,7 +359,7 @@ module UNBOUNDED(X:HASH) = struct let iter c f = H.iter f c end -let unbounded (type a) ?(eq=default_eq_) ?(hash=default_hash_) size = +let unbounded (type a) ~eq ?(hash=default_hash_) size = let module C = UNBOUNDED(struct type t = a let equal = eq diff --git a/src/data/CCCache.mli b/src/data/CCCache.mli index e689f090..881835ac 100644 --- a/src/data/CCCache.mli +++ b/src/data/CCCache.mli @@ -79,13 +79,13 @@ val add : ('a, 'b) t -> 'a -> 'b -> bool val dummy : ('a,'b) t (** Dummy cache, never stores any value *) -val linear : ?eq:'a equal -> int -> ('a, 'b) t +val linear : eq:'a equal -> int -> ('a, 'b) t (** Linear cache with the given size. It stores key/value pairs in an array and does linear search at every call, so it should only be used with small size. @param eq optional equality predicate for keys *) -val replacing : ?eq:'a equal -> ?hash:'a hash -> +val replacing : eq:'a equal -> ?hash:'a hash -> int -> ('a,'b) t (** Replacing cache of the given size. Equality and hash functions can be parametrized. It's a hash table that handles collisions by replacing @@ -93,12 +93,12 @@ val replacing : ?eq:'a equal -> ?hash:'a hash -> entry with the same hash (modulo size) is added). Never grows wider than the given size. *) -val lru : ?eq:'a equal -> ?hash:'a hash -> +val lru : eq:'a equal -> ?hash:'a hash -> int -> ('a,'b) t (** LRU cache of the given size ("Least Recently Used": keys that have not been used recently are deleted first). Never grows wider than the given size. *) -val unbounded : ?eq:'a equal -> ?hash:'a hash -> +val unbounded : eq:'a equal -> ?hash:'a hash -> int -> ('a,'b) t (** Unbounded cache, backed by a Hash table. Will grow forever unless {!clear} is called manually. *)