Package com.nr.lna

Examples of com.nr.lna.Huffcode


    // Do an actual count of each char in the message
    for (i=0;i<N+1;i++) nfreq[c[i]]++;

    // Test codeone
    Huffcode huff=new Huffcode(NCHAR,nfreq);
    nb.val=0;
    byte[] code = new byte[N];
    for (i=0;i<N+1;i++) huff.codeone(c[i],code,nb);
    System.out.printf("Number of bits used: %d\n", nb.val);
    System.out.printf("Compression ratio: %f\n", (double)(N*3)/nb.val); // Normally 3 bits each for 5 characters

    // Recover the text
    nb.val=0;
    byte[]d=new byte[N+1];
    for (i=0;i<N+1;i++) {
      d[i]=(byte)huff.decodeone(code,nb);
      localflag = localflag || (c[i] != d[i]);
    }
    globalflag = globalflag || localflag;
    if (localflag) {
      fail("*** Huffcode: Recovered message not the same as the original");
View Full Code Here

TOP

Related Classes of com.nr.lna.Huffcode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.