Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
|
|
@ -1,27 +1,20 @@
|
|||
let rec aux acc paths =
|
||||
if List.mem [] paths
|
||||
then (List.rev acc) else
|
||||
let heads = List.map List.hd paths in
|
||||
let item = List.hd heads in
|
||||
let all_the_same =
|
||||
List.for_all ((=) item) (List.tl heads)
|
||||
in
|
||||
if all_the_same
|
||||
then aux (item::acc) (List.map List.tl paths)
|
||||
else (List.rev acc)
|
||||
let rec common_prefix xs ys = match xs, ys with
|
||||
| x :: xs, y :: ys when x = y -> x :: common_prefix xs ys
|
||||
| _ -> []
|
||||
|
||||
let common_prefix sep = function
|
||||
| [] -> invalid_arg "common_prefix"
|
||||
| dirs ->
|
||||
let paths = List.map (Str.split (Str.regexp_string sep)) dirs in
|
||||
let res = aux [] paths in
|
||||
(sep ^ (String.concat sep res))
|
||||
let common_prefix_all = function
|
||||
| x :: xs -> List.fold_left common_prefix x xs
|
||||
| _ -> []
|
||||
|
||||
let () =
|
||||
let dirs = [
|
||||
let common_ancestor ~sep paths =
|
||||
List.map Str.(split_delim (regexp_string sep)) paths
|
||||
|> common_prefix_all
|
||||
|> String.concat sep
|
||||
|
||||
let _ = assert begin
|
||||
common_ancestor ~sep:"/" [
|
||||
"/home/user1/tmp/coverage/test";
|
||||
"/home/user1/tmp/covert/operator";
|
||||
"/home/user1/tmp/coven/members";
|
||||
] in
|
||||
print_endline (common_prefix "/" dirs);
|
||||
;;
|
||||
] = "/home/user1/tmp"
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue