Skip to content

Commit

Permalink
Make Set.to_array use Enum instead of Dynarray
Browse files Browse the repository at this point in the history
This breaks the dependency Set -> Dynarray -> Int. A quick benchmark
also shows that the new function has comparable performances and can
avoid Out_of_memory.
  • Loading branch information
thizanne committed Feb 15, 2017
1 parent 86f5eb4 commit b10fc08
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/batSet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,6 @@ module Concrete = struct
let elements s = elements_aux [] s
let to_list = elements

let to_array s =
let acc = BatDynArray.create () in
iter (BatDynArray.add acc) s;
BatDynArray.to_array acc

let rec cons_iter s t = match s with
Empty -> t
| Node (l, e, r, _) -> cons_iter l (C (e, r, t))
Expand Down Expand Up @@ -365,6 +360,9 @@ module Concrete = struct
BatEnum.make ~next:(enum_next l) ~count:(enum_count l) ~clone
in make (cons_iter t E)

let to_array s =
BatArray.of_enum (enum s)

let backwards t =
let rec make l =
let l = ref l in
Expand Down

0 comments on commit b10fc08

Please sign in to comment.