Created
November 21, 2020 06:47
-
-
Save poga/7846a888ef7560f88d1d09bcfb130a11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let[@inline] get x i = String.unsafe_get x i |> Char.code | |
external unsafe_get_int16 : string -> int -> int = "%caml_string_get16u" | |
let[@inline] get16 x i = unsafe_get_int16 x i | |
let equal ~ln a b = | |
let l1 = ln asr 1 in | |
let r = ref 0 in | |
for i = 0 to pred l1 do r := !r lor (get16 a (i * 2) lxor get16 b (i * 2)) done ; | |
for _ = 1 to ln land 1 do r := !r lor (get a (ln - 1) lxor get b (ln - 1)) done ; | |
!r = 0 | |
let equal a b = | |
let al = String.length a in | |
let bl = String.length b in | |
if al <> bl | |
then false | |
else equal ~ln:al a b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment