home
/
code
/
dups.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename Directory to Directory_tree
[dups.git]
/
dups.ml
diff --git
a/dups.ml
b/dups.ml
index
0bcc83a
..
84c0707
100644
(file)
--- a/
dups.ml
+++ b/
dups.ml
@@
-35,13
+35,12
@@
end = struct
)
end
)
end
-module Directory : sig
+module Directory
_tree
: sig
val find_files : string -> string Stream.t
end = struct
let find_files root =
let dirs = Queue.create () in
let files = Queue.create () in
val find_files : string -> string Stream.t
end = struct
let find_files root =
let dirs = Queue.create () in
let files = Queue.create () in
- Queue.add root dirs;
let explore parent =
Array.iter (Sys.readdir parent) ~f:(fun child ->
let path = Filename.concat parent child in
let explore parent =
Array.iter (Sys.readdir parent) ~f:(fun child ->
let path = Filename.concat parent child in
@@
-59,24
+58,16
@@
end = struct
()
)
in
()
)
in
- let next_dir () =
- match Queue.take dirs with
- | exception Queue.Empty ->
- ()
- | dir ->
- explore dir
+ explore root;
+ let rec next () =
+ match Queue.is_empty files, Queue.is_empty dirs with
+ | false, _ -> Some (Queue.take files)
+ | true , true -> None
+ | true , false ->
+ explore (Queue.take dirs);
+ next ()
in
in
- let next_file () =
- match Queue.take files with
- | exception Queue.Empty ->
- None
- | file_path ->
- Some file_path
- in
- Stream.create (fun () ->
- next_dir ();
- next_file ()
- )
+ Stream.create next
end
type input =
end
type input =
@@
-87,7
+78,7
@@
let main input =
let paths =
match input with
| Paths_on_stdin -> In_channel.lines stdin
let paths =
match input with
| Paths_on_stdin -> In_channel.lines stdin
- | Root_path root -> Directory.find_files root
+ | Root_path root -> Directory
_tree
.find_files root
in
let paths_by_digest = Hashtbl.create 1_000_000 in
let path_count = ref 0 in
in
let paths_by_digest = Hashtbl.create 1_000_000 in
let path_count = ref 0 in
@@
-121,5
+112,14
@@
let main input =
let () =
let input = ref Paths_on_stdin in
let () =
let input = ref Paths_on_stdin in
- Arg.parse [] (fun path -> input := Root_path path) "";
+ Arg.parse
+ []
+ (function
+ | path when Sys.file_exists path ->
+ input := Root_path path
+ | path ->
+ eprintf "File does not exist: %S\n%!" path;
+ exit 1
+ )
+ "";
main !input
main !input
This page took
0.019425 seconds
and
4
git commands to generate.