Skip to content

Commit

Permalink
KeyMerge: tail-recursive flatten
Browse files Browse the repository at this point in the history
ref #78
  • Loading branch information
ygrek committed May 7, 2021
1 parent ca98434 commit 8af4cfc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions keyMerge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,22 @@ let packets_equal p1 p2 = p1 = p2
(*******************************************************************)
(** Code for flattening out the above structure back to the original key *)

let rec flatten_sigpair_list list = match list with
[] -> []
| (pack,sigs)::tl -> pack :: (sigs @ flatten_sigpair_list tl)
let rec flatten_sigpair_list list =
match list with
| [] -> []
| (pack,sigs)::tl -> pack :: (List.rev_append sigs (flatten_sigpair_list tl)) (* order of sigs doesn't matter *)

(* stack proportional to [List.length l] which is constant in our case *)
let rec list_concat l =
match l with
| [] -> []
| h::tl -> List.rev_append (List.rev h) (list_concat tl)

let flatten key =
key.key :: List.concat [ key.selfsigs;
key.key :: list_concat [ key.selfsigs;
flatten_sigpair_list key.uids;
flatten_sigpair_list key.subkeys ]


(************************************************************)

let nr_packets l = List.fold_left ~f:(fun acc (_,l) -> acc + List.length l) ~init:0 l
Expand Down

0 comments on commit 8af4cfc

Please sign in to comment.