let invariant t =
assert (Doubly_linked.length t.queue = Hashtbl.length t.table);
(* Look at each element in the queue, checking:
* - every element in the queue is in the hash table
* - there are no duplicate keys
*)
let keys = Table.create ~size:(Hashtbl.length t.table) () in
Doubly_linked.iter t.queue ~f:(fun kv ->
let key = kv.key in
match Hashtbl.find t.table key with
| None -> assert false
| Some _ ->
assert (not (Hashtbl.mem keys key));
Hashtbl.replace keys ~key ~data:());