-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrey Mokhov <amokhov@janestreet.com>
- Loading branch information
1 parent
b5e4081
commit 38d9339
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(* CR-someday amokhov: Switch from sets to "flat sets" backed by immutable arrays. *) | ||
type t = | ||
{ dir : Path.t | ||
; filenames : Filename.Set.t | ||
} | ||
|
||
let equal t { dir; filenames } = | ||
Path.equal t.dir dir && Filename.Set.equal filenames t.filenames | ||
;; | ||
|
||
let dir { dir; filenames = _ } = dir | ||
let filenames { dir = _; filenames } = filenames | ||
let empty ~dir = { dir; filenames = String.Set.empty } | ||
|
||
let create ?filter ~dir filenames = | ||
match filter with | ||
| None -> { dir; filenames } | ||
| Some f -> | ||
{ dir | ||
; filenames = | ||
Filename.Set.to_list filenames | ||
|> List.filter ~f:(fun basename -> f ~basename) | ||
|> Filename.Set.of_list | ||
} | ||
;; | ||
|
||
let to_list { dir; filenames } = Filename.Set.to_list_map filenames ~f:(Path.relative dir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(** Like [Path.Set.t] but tailored for representing sets of file names in a directory. *) | ||
|
||
type t | ||
|
||
val equal : t -> t -> bool | ||
|
||
(** The directory of the filename set. *) | ||
val dir : t -> Path.t | ||
|
||
(** The set of file names, all relative to [dir]. *) | ||
val filenames : t -> Filename.Set.t | ||
|
||
val empty : dir:Path.t -> t | ||
|
||
(* CR-soon amokhov: Decouple [create] from [filter]. *) | ||
val create : ?filter:(basename:string -> bool) -> dir:Path.t -> Filename.Set.t -> t | ||
val to_list : t -> Path.t list |