-
Notifications
You must be signed in to change notification settings - Fork 49
Feature idea: equalv #314
Copy link
Copy link
Open
Description
I found that I wanted to compare two lists of cstructs if they each combined contained the same bytes. It can easily but inefficiently be implemented using Cstruct.equal (Cstruct.concat xs) (Cstruct.concat ys). Implementing it more efficiently is less straight forward.
let cstruct_equalv a b =
let rec loop a b =
match a, b with
| [], [] -> true
| [], _ | _, [] -> false
| a :: a', b :: b' ->
let l = min (Cstruct.length a) (Cstruct.length b) in
let remainder x xs =
if Cstruct.length x > l then
Cstruct.sub x l (Cstruct.length x - l) :: xs
else
xs
in
Cstruct.equal (Cstruct.sub a 0 l) (Cstruct.sub b 0 l) &&
loop (remainder a a') (remainder b b')
in
Cstruct.lenv a = Cstruct.lenv b &&
loop a bIt may be a slippery slope to add more and more *v functions.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels