Skip to content

Commit 1ee4dc0

Browse files
Initiate buckets
1 parent b68df11 commit 1ee4dc0

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/util/precCompare.ml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ struct
103103

104104
module CompareDump = MakeHashtbl (Key) (Dom) (RH)
105105

106+
let comparisons = ref []
107+
106108
let compare_dumps ({name = name1; results = lvh1}: result) ({name = name2; results = lvh2}: result) =
107-
CompareDump.compare ~verbose:true ~name1 lvh1 ~name2 lvh2
109+
let (c, d) = CompareDump.compare ~verbose:true ~name1 lvh1 ~name2 lvh2 in
110+
comparisons := (name1, name2, c) :: !comparisons;
111+
(c, d)
108112

109113
let count_locations (dumps: result list) =
110114
let module LH = Hashtbl.Make (CilType.Location) in
@@ -118,6 +122,29 @@ struct
118122
) dumps;
119123
(LH.length locations, RH.length location_vars)
120124

125+
let group () =
126+
let new_bucket_id = ref 0 in
127+
let equality_buckets = Hashtbl.create 113 in
128+
let sorted = List.sort (fun (n1, _, _) (n2, _, _) -> String.compare n1 n2) !comparisons in
129+
List.iter (fun (name1, name2, (c:Comparison.t)) ->
130+
(if not (Hashtbl.mem equality_buckets name1) then
131+
(* Make its own bucket if it does not appear yet *)
132+
(let bucket_id = !new_bucket_id in
133+
incr new_bucket_id;
134+
Hashtbl.add equality_buckets name1 bucket_id));
135+
if c.more_precise = 0 && c.less_precise = 0 && c.incomparable = 0 then
136+
Hashtbl.replace equality_buckets name2 (Hashtbl.find equality_buckets name1)
137+
else
138+
()
139+
) sorted;
140+
let bindings = Hashtbl.bindings equality_buckets in
141+
let buckets = List.group (fun (_, b) (_, b') -> compare b b') bindings in
142+
List.iter (fun bucket ->
143+
Logs.result "Bucket %d:" (snd (List.hd bucket));
144+
List.iter (fun (name, _) -> Logs.result " %s" name) bucket
145+
) buckets
146+
147+
121148
let main () =
122149
Util.init ();
123150
let filenames = List.tl (Array.to_list Sys.argv) in
@@ -131,5 +158,6 @@ struct
131158
|> List.map (uncurry compare_dumps)
132159
|> List.iter (fun (_, msg) -> Logs.result "%t" (fun () -> msg));
133160
Logs.newline ();
134-
Logs.result "Total locations: %d\nTotal %s: %d" locations_count (Key.name ()) location_vars_count
161+
Logs.result "Total locations: %d\nTotal %s: %d" locations_count (Key.name ()) location_vars_count;
162+
group ()
135163
end

0 commit comments

Comments
 (0)