com.sleepycat.je.utilint
Class Adler32

java.lang.Object
  extended by com.sleepycat.je.utilint.Adler32
All Implemented Interfaces:
Checksum

public class Adler32
extends Object
implements Checksum

Adler32 checksum implementation. This class is used rather than the native java.util.zip.Adler32 class because we have seen a JIT problem when calling the Adler32 class using the Server JVM on Linux and Solaris. Specifically, we suspect this may be Bug Parade number 4965907. See SR [#9376]. The Adler32 checksum is discussed in RFC1950. The sample implementation from this RFC is shown below:

    #define BASE 65521  largest prime smaller than 65536
    unsigned long update_adler32(unsigned long adler,
       unsigned char *buf, int len)
    {
      unsigned long s1 = adler & 0xffff;
      unsigned long s2 = (adler >> 16) & 0xffff;
      int n;

      for (n = 0; n < len; n++) {
        s1 = (s1 + buf[n]) % BASE;
        s2 = (s2 + s1)     % BASE;
      }
      return (s2 << 16) + s1;
    }

    unsigned long adler32(unsigned char *buf, int len)
    {
      return update_adler32(1L, buf, len);
    }
 
The NMAX optimization is so that we don't have to do modulo calculations on every iteration. NMAX is the max number of additions to make before you have to perform the modulo calculation.


Constructor Summary
Adler32()
           
 
Method Summary
 long getValue()
          Returns current checksum value.
 void reset()
          Reset Adler-32 checksum to initial value.
 void update(byte[] b, int off, int len)
          Update current Adler-32 checksum given the specified byte array.
 void update(int b)
          Update current Adler-32 checksum given the specified byte.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Adler32

public Adler32()
Method Detail

update

public void update(int b)
Update current Adler-32 checksum given the specified byte.

Specified by:
update in interface Checksum

update

public void update(byte[] b,
                   int off,
                   int len)
Update current Adler-32 checksum given the specified byte array.

Specified by:
update in interface Checksum

reset

public void reset()
Reset Adler-32 checksum to initial value.

Specified by:
reset in interface Checksum

getValue

public long getValue()
Returns current checksum value.

Specified by:
getValue in interface Checksum


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.