janestreet / base

Standard library for OCaml
MIT License
848 stars 124 forks source link

Add remove_duplicates function to the List module. #155

Closed Ameen2000 closed 1 year ago

Ameen2000 commented 1 year ago

Notice the list module had a lot of functions for lists with duplicates in them such as contains_dup, find_dup, and remove_consecutive_duplicates. However, there is no function that removes_duplicates all together from what I have seen in the list module. So, I added one with a simple implementation.The first commit wasn't signed off using my real name by accident to I made a second commit message signed off with my real name.

bcc32 commented 1 year ago

List.stable_dedup is the function you were looking for. It uses a set to improve performance from O(n^2) to O(n log n).

(** Returns the original list, dropping all occurrences of duplicates after the first. *)
val stable_dedup : 'a t -> compare:(('a -> 'a -> int)[@local]) -> 'a t
Ameen2000 commented 1 year ago

Thank you for the swift reply.

On Tue, 11 Jul 2023 at 5:22 pm, Aaron Zeng @.***> wrote:

List.stable_dedup is the function you were looking for. It uses a set to improve performance from O(n^2) to O(n log n).

( Returns the original list, dropping all occurrences of duplicates after the first. ) val stable_dedup : 'a t -> compare:(('a -> 'a -> @.) -> 'a t

— Reply to this email directly, view it on GitHub https://github.com/janestreet/base/pull/155#issuecomment-1631123300, or unsubscribe https://github.com/notifications/unsubscribe-auth/APO22KLTDTFW7Z4OOUAVDADXPV4STANCNFSM6AAAAAA2GF3I6M . You are receiving this because you authored the thread.Message ID: @.***>