Source

spotlib / lib / xhashtbl.ml

let replace_list tbl kvs = 
  List.iter (fun (k,v) ->
    Hashtbl.replace tbl k v) kvs

let of_list size kvs =
  let tbl = Hashtbl.create size in
  List.iter (fun (k,v) ->
    Hashtbl.add tbl k v) kvs;
  tbl
  
let to_list tbl = Hashtbl.fold (fun k v st -> (k,v) :: st) tbl []

let find_opt tbl k = try Some (Hashtbl.find tbl k) with Not_found -> None

let find_default def tbl k = try Hashtbl.find tbl k with Not_found -> def

let find_or_add deff tbl k = 
  try Hashtbl.find tbl k with Not_found -> 
    let def = deff k in
    Hashtbl.replace tbl k def;
    def

let alter tbl k f =
  match f (find_opt tbl k) with
  | None -> Hashtbl.remove tbl k
  | Some v -> Hashtbl.replace tbl k v

let concat tbls =
  let t = Hashtbl.create 101 in (* CR jfuruse: fixed *)
  List.iter (Hashtbl.iter (Hashtbl.add t)) tbls;
  t
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.