Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / JU / Adler32.js
1 Clazz.declarePackage ("JU");
2 Clazz.load (["JU.Checksum"], "JU.Adler32", null, function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.s1 = 1;
5 this.s2 = 0;
6 this.b1 = null;
7 Clazz.instantialize (this, arguments);
8 }, JU, "Adler32", null, JU.Checksum);
9 Clazz.prepareFields (c$, function () {
10 this.b1 =  Clazz.newByteArray (1, 0);
11 });
12 Clazz.overrideMethod (c$, "resetLong", 
13 function (init) {
14 this.s1 = init & 0xffff;
15 this.s2 = (init >> 16) & 0xffff;
16 }, "~N");
17 Clazz.overrideMethod (c$, "reset", 
18 function () {
19 this.s1 = 1;
20 this.s2 = 0;
21 });
22 Clazz.overrideMethod (c$, "getValue", 
23 function () {
24 return ((this.s2 << 16) | this.s1);
25 });
26 Clazz.overrideMethod (c$, "update", 
27 function (buf, index, len) {
28 if (len == 1) {
29 this.s1 += buf[index++] & 0xff;
30 this.s2 += this.s1;
31 this.s1 %= 65521;
32 this.s2 %= 65521;
33 return;
34 }var len1 = Clazz.doubleToInt (len / 5552);
35 var len2 = len % 5552;
36 while (len1-- > 0) {
37 var k = 5552;
38 len -= k;
39 while (k-- > 0) {
40 this.s1 += buf[index++] & 0xff;
41 this.s2 += this.s1;
42 }
43 this.s1 %= 65521;
44 this.s2 %= 65521;
45 }
46 var k = len2;
47 len -= k;
48 while (k-- > 0) {
49 this.s1 += buf[index++] & 0xff;
50 this.s2 += this.s1;
51 }
52 this.s1 %= 65521;
53 this.s2 %= 65521;
54 }, "~A,~N,~N");
55 Clazz.overrideMethod (c$, "updateByteAsInt", 
56 function (b) {
57 this.b1[0] = b;
58 this.update (this.b1, 0, 1);
59 }, "~N");
60 Clazz.defineStatics (c$,
61 "BASE", 65521,
62 "NMAX", 5552);
63 });