Thread: code of adler 32

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    10

    code of adler 32

    Code:
    uLong ZEXPORT adler32(adler, buf, len)
        uLong adler;
        const Bytef *buf;
        uInt len;
    {
        unsigned long sum2;
        unsigned n;
    
        /* split Adler-32 into component sums */
        sum2 = (adler >> 16) & 0xffff;
        adler &= 0xffff;
    
        /* in case user likes doing a byte at a time, keep it fast */
        if (len == 1) {
            adler += buf[0];
            if (adler >= BASE)
                adler -= BASE;
            sum2 += adler;
            if (sum2 >= BASE)
                sum2 -= BASE;
            return adler | (sum2 << 16);
        }
    
        /* initial Adler-32 value (deferred check for len == 1 speed) */
        if (buf == Z_NULL)
            return 1L;
    
        /* in case short lengths are provided, keep it somewhat fast */
        if (len < 16) {
            while (len--) {
                adler += *buf++;
                sum2 += adler;
            }
            if (adler >= BASE)
                adler -= BASE;
            MOD4(sum2);             /* only added so many BASE's */
            return adler | (sum2 << 16);
        }
    
        /* do length NMAX blocks -- requires just one modulo operation */
        while (len >= NMAX) {
            len -= NMAX;
            n = NMAX / 16;          /* NMAX is divisible by 16 */
            do {
                DO16(buf);          /* 16 sums unrolled */
                buf += 16;
            } while (--n);
            MOD(adler);
            MOD(sum2);
        }
    
        /* do remaining bytes (less than NMAX, still just one modulo) */
        if (len) {                  /* avoid modulos if none remaining */
            while (len >= 16) {
                len -= 16;
                DO16(buf);
                buf += 16;
            }
            while (len--) {
                adler += *buf++;
                sum2 += adler;
            }
            MOD(adler);
            MOD(sum2);
        }
    
        /* return recombined sums */
        return adler | (sum2 << 16);
    }
    Write the meaning of each line of the code

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Please refer to the homework policy.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    OK, now you're just getting annoying.

    http://cboard.cprogramming.com/showthread.php?t=109441
    http://cboard.cprogramming.com/showthread.php?t=109402

    You're just not going to get someone here to give you a long wax crayon description of what every line of code in zlib does when you basically don't have a clue about either compression or C programming.

    And since it's only been a couple of days since you last tried this trick, it means that you've not been paying any attention, nor had chance to get down to some solid research of your own.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2008
    Posts
    1
    prefer kanthane book

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In thread 109441 I posted a link to the Wiki page of Adler32. This code is not a sample implementation of Adler32, but rather an optimized version that contains different fast variants for different use-cases of the code.

    If there is a particular section of the code you want an explanation of, please feel free to ask SPECIFIC questions, but do not expect someone to explain 50 lines of rather complicated and not exactly written for readability.

    As Salem explained, if you are trying to learn about compression and have little understanding of C as a language, you need to start by learning the language, and then study the art of compression - neither is something you'd expect to learn in a few days.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  3. Explain this C code in english
    By soadlink in forum C Programming
    Replies: 16
    Last Post: 08-31-2006, 12:48 AM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM