Core.Std.String.Table

Reviewed By: cristianoc

Differential Revision: D4232447

fbshipit-source-id: 75e3ecd
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent 78ec954ae2
commit 900da595b1

@ -56,7 +56,7 @@ let link_exists s =
(* Table mapping directories to multilinks.
Used for the hashed directories where attrbute files are stored. *)
let multilinks_dir_table = StringHash.create 16
let multilinks_dir_table = String.Table.create ~size:16 ()
(* Add a multilink for attributes to the internal per-directory table.
@ -66,7 +66,7 @@ let add_multilink_attr ~stats src dst =
let attr_dir_name = Filename.basename attr_dir in
let multilinks =
try
StringHash.find multilinks_dir_table attr_dir_name
String.Table.find_exn multilinks_dir_table attr_dir_name
with
| Not_found ->
let multilinks = match Multilinks.read ~dir:attr_dir with
@ -75,7 +75,7 @@ let add_multilink_attr ~stats src dst =
multilinks
| None ->
Multilinks.create () in
StringHash.add multilinks_dir_table attr_dir_name multilinks;
String.Table.set multilinks_dir_table ~key:attr_dir_name ~data:multilinks;
multilinks in
Multilinks.add multilinks src;
stats.files_multilinked <- stats.files_multilinked + 1
@ -92,11 +92,11 @@ let create_link ~stats src dst =
stats.files_linked <- stats.files_linked + 1
let create_multilinks () =
let do_dir dir multilinks =
let do_dir ~key:dir ~data:multilinks =
let attributes_dir =
Filename.concat (Filename.concat Config.results_dir Config.attributes_dir_name) dir in
Multilinks.write multilinks ~dir:attributes_dir in
StringHash.iter do_dir multilinks_dir_table
String.Table.iteri ~f:do_dir multilinks_dir_table
(** Create symbolic links recursively from the destination to the source.

@ -14,16 +14,16 @@ let module L = Logging;
let multilink_file_name = "multilink.txt";
type t = StringHash.t string;
type t = String.Table.t string;
let add multilinks fname => StringHash.replace multilinks (Filename.basename fname) fname;
let add multilinks fname => String.Table.set multilinks key::(Filename.basename fname) data::fname;
let create () :t => StringHash.create 1;
let create () :t => String.Table.create size::1 ();
/* Cache of multilinks files read from disk */
let multilink_files_cache = StringHash.create 1;
let multilink_files_cache = String.Table.create size::1 ();
let reset_cache () => StringHash.reset multilink_files_cache;
let reset_cache () => String.Table.clear multilink_files_cache;
let read dir::dir :option t => {
let multilink_fname = Filename.concat dir multilink_file_name;
@ -31,8 +31,8 @@ let read dir::dir :option t => {
| None => None
| Some lines =>
let links = create ();
IList.iter (fun line => StringHash.add links (Filename.basename line) line) lines;
StringHash.add multilink_files_cache dir links;
IList.iter (fun line => String.Table.set links key::(Filename.basename line) data::line) lines;
String.Table.set multilink_files_cache key::dir data::links;
Some links
}
};
@ -41,12 +41,12 @@ let read dir::dir :option t => {
let write multilinks dir::dir => {
let fname = Filename.concat dir multilink_file_name;
let outc = open_out fname;
StringHash.iter (fun _ src => output_string outc (src ^ "\n")) multilinks;
String.Table.iteri f::(fun key::_ data::src => output_string outc (src ^ "\n")) multilinks;
close_out outc
};
let lookup dir::dir =>
try (Some (StringHash.find multilink_files_cache dir)) {
try (Some (String.Table.find_exn multilink_files_cache dir)) {
| Not_found => read dir::dir
};
@ -60,7 +60,7 @@ let resolve fname => {
switch (lookup dir::dir) {
| None => fname
| Some links =>
try (DB.filename_from_string (StringHash.find links base)) {
try (DB.filename_from_string (String.Table.find_exn links base)) {
| Not_found => fname
}
}

@ -87,9 +87,6 @@ let int_of_bool b = if b then 1 else 0
(** Set of integers *)
module IntSet = Set.Make(Int)
(** Hash table over strings *)
module StringHash = Hashtbl.Make (String)
(** Maps from integers *)
module IntMap = Map.Make (Int)

@ -75,9 +75,6 @@ val int_of_bool : bool -> int
(** Set of integers *)
module IntSet : Set.S with type elt = int
(** Hash table over strings *)
module StringHash : Hashtbl.S with type key = string
(** Maps from integers *)
module IntMap : Map.S with type key = int

Loading…
Cancel
Save