Conversation
|
I'm not at all a fan of that API in the Lists module (neither of adding more functions and mutable state to Gmap). The first call to cardinal checks an invariant for tsig-keys (which contain a single dnskey, thus are there any other |
|
Why do you dislike the API in the Here's another example, similarly guarded with a "TODO" comment about LRU, but probably a better example of where this would shine:
I couldn't find other examples in I did a quick grep through my locally checked out code and found some uses of
Most of the other instances I saw was either
So basically no conclusive evidence that this is needed. It also seems like it is counter-intuitive to a lot of people that Anyway, here's a take on it without mutable state, but it's a lot more verbose than the mutable state version: let compare_with_length t num =
let rec loop seen = function
| Seq.Nil -> seen - num
| Seq.Cons _ when seen > num -> 1
| Seq.Cons ( _ , next) -> loop (succ seen) (next ())
in loop 0 (M.to_seq t ()) |
This PR provides a
compare_length_within the style ofList.compare_length_with(hence the name).It serves the same purpose as
List.compare_length_with: It can be used to replace instances like(which runs in
O(n)time and may be very slow with a larget) with(which runs in
O( min(cardinal t, 6+1) )time).Two examples of where this can be useful, but I suspect this is a fairly common use-case in code: