ocaml: phase 5.1 adler32.ml baseline (Adler-32 of 'Wikipedia' = 300286872 = 0x11E60398)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
Two running sums modulo 65521:
a = (1 + sum of bytes) mod 65521
b = sum of running 'a' values mod 65521
checksum = b * 65536 + a
let adler32 s =
let a = ref 1 in
let b = ref 0 in
let m = 65521 in
for i = 0 to String.length s - 1 do
a := (!a + Char.code s.[i]) mod m;
b := (!b + !a) mod m
done;
!b * 65536 + !a
For 'Wikipedia': 0x11E60398 = 300286872 (the canonical test value).
Tests for-loop accumulating two refs together, modular arithmetic,
and Char.code on s.[i].
96 baseline programs total.
This commit is contained in:
13
lib/ocaml/baseline/adler32.ml
Normal file
13
lib/ocaml/baseline/adler32.ml
Normal file
@@ -0,0 +1,13 @@
|
||||
let adler32 s =
|
||||
let a = ref 1 in
|
||||
let b = ref 0 in
|
||||
let m = 65521 in
|
||||
for i = 0 to String.length s - 1 do
|
||||
a := (!a + Char.code s.[i]) mod m;
|
||||
b := (!b + !a) mod m
|
||||
done;
|
||||
!b * 65536 + !a
|
||||
|
||||
;;
|
||||
|
||||
adler32 "Wikipedia"
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"ackermann.ml": 125,
|
||||
"adler32.ml": 300286872,
|
||||
"anagram_check.ml": 2,
|
||||
"anagrams.ml": 3,
|
||||
"atm.ml": 120,
|
||||
|
||||
Reference in New Issue
Block a user