Commit c0bb09f6 authored by Benoit Barbot's avatar Benoit Barbot
Browse files

improve gen serizlizer

parent b8bdd28e
...@@ -28,22 +28,36 @@ let buff_int b i = ...@@ -28,22 +28,36 @@ let buff_int b i =
add_char b (b64_of_ui i1); add_char b (b64_of_ui i1);
add_char b (b64_of_ui i2); add_char b (b64_of_ui i2);
) else ) else
let r = int_of_float ((log @@ float @@ abs @@ i) /. log 2.0) / 5 in let r = max 2 (int_of_float ((log @@ float @@ abs @@ i) /. log 2.0) / 5) in
add_char b (b64_of_ui (32 + (if i<0 then 16 else 0) + ((abs i) lsr (r*5)))); add_char b (b64_of_ui (32 + (if i<0 then 16 else 0) + ((abs i) lsr (r*5))));
let j = ref ((abs i) mod (1 lsl (5*r))) in let j = ref ((abs i) mod (1 lsl (5*r))) in
let r2 = ref (r*5) in let r2 = ref (r*5) in
while !r2 > 0 do while !r2 > 0 do
print_endline (string_of_int !r2); print_string ((string_of_int !r2)^":");
add_char b (b64_of_ui ((if r>5 then 32 else 0) + (!j mod (1 lsl (!r2*5))))); print_endline (string_of_int !j);
j:= !j / 32;
r2:= !r2-5; r2:= !r2-5;
add_char b (b64_of_ui ((if !r2>0 then 32 else 0) + (!j lsr !r2)));
j:= !j mod (1 lsl !r2);
done done
let int_buff s pos = let int_buff s pos =
let r = ref 0 in
while ui_of_b64 s.[pos+ !r] >= 32 do incr r done;
let i1 = ui_of_b64 s.[pos] in let i1 = ui_of_b64 s.[pos] in
if i1 < (1 lsl 5) then pos+1,i1 if !r =0 then pos+1,i1
else let i2 = ui_of_b64 s.[pos+1] in else if !r =1 then
pos+2, (i1 mod (1 lsl 5))*(1 lsl 5) + i2 let i2 = ui_of_b64 s.[pos+1] in
pos+2, (i1 mod (1 lsl 5))*(1 lsl 5) + i2
else
let j = ref (i1 mod 16) in
let r2 = ref 1 in
while !r2 <= !r do
let i2 = ui_of_b64 s.[pos+ !r2] in
j := (!j lsl 5) + ( i2 mod 32);
incr r2;
done;
if (i1 mod 32) >=16 then pos+ !r2, (- !j)
else pos+ !r2, !j
(*let buff_int b i = (*let buff_int b i =
let ui = (i + (1 lsl 17)) mod (1 lsl 18) in let ui = (i + (1 lsl 17)) mod (1 lsl 18) in
...@@ -61,15 +75,15 @@ let int_buff s pos = ...@@ -61,15 +75,15 @@ let int_buff s pos =
ui - (1 lsl 17)*) ui - (1 lsl 17)*)
let buff_float b f = let buff_float b f =
let i = int_of_float (f *. 10.0) in let i = int_of_float (f *. 100.0) in
buff_int b i buff_int b i
let float_buff b pos = let float_buff b pos =
let f = int_buff b pos in let p,f = int_buff b pos in
(float_of_int f) /. 10. p, ((float_of_int f) /. 100.)
let _ = (*let _ =
let t = Buffer.create 100 in let t = Buffer.create 100 in
for i = -1025 to -1020 do for i = -1025 to 1020 do
buff_int t i; buff_int t i;
done; done;
let str = (Bytes.to_string @@ Buffer.to_bytes t) in let str = (Bytes.to_string @@ Buffer.to_bytes t) in
...@@ -80,7 +94,7 @@ let _ = ...@@ -80,7 +94,7 @@ let _ =
let p1,i1= int_buff str !pos in let p1,i1= int_buff str !pos in
pos := p1; pos := p1;
print_endline (string_of_int i1); print_endline (string_of_int i1);
done done*)
let buff_string b str = let buff_string b str =
let n = String.length str in let n = String.length str in
...@@ -113,8 +127,8 @@ let buff_string b str = ...@@ -113,8 +127,8 @@ let buff_string b str =
let string_buff b pin = let string_buff b pin =
let n = int_buff b pin in let p,n = int_buff b pin in
let pos = ref (pin+3) in let pos = ref p in
let pos2 = ref 0 in let pos2 = ref 0 in
let str = Bytes.create ((n/4)*3) in let str = Bytes.create ((n/4)*3) in
while !pos < n+(pin+3) do while !pos < n+(pin+3) do
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment