Research Article

An Adaptive Lossless Data Compression Scheme for Wireless Sensor Networks

Algorithm 2

Pseudo-code of 3-Huffman Table ALEC.
3TableALECencoder( di , n , code)
// encode() is the encode function
// is the current residue value
// n is the block size (the number of residue values to be encoded at a time)
// code is the encoded bitstream of n
// *denotes concatenation
// encode block of n using the first Huffman Table of the 3-Huffman Table ALEC Coder
CALL encode() with block of n and Table A RETURNING
SET A To
// compute the size of the encoded bitstream A
SET size_A TO length( A)
// encode the same block of n using the second Huffman Table of the 3-Huffman Table ALEC Coder
CALL encode() with block of n and Table B RETURNING
SET B To
// compute the size of the encoded bitstream B
SET size_B TO length( B)
// encode the same block of n using the third Huffman Table of the 3-Huffman Table ALEC Coder
CALL encode() with block of n and Table C RETURNING
SET C To
// compute the size of the encoded bitstream C
SET size_C TO length( C)
// compare size_A, size_B and size_C and select the encoded bitstream with the least compressed size
IF size_A <= min(size_B, size_C) THEN
 // generate the table identifier of Table A
 SET ID TO “10”
 // append encoded bitstream A to ID
 SET code TO ID *   A
ELSEIF size_B <= min(size_A, size_C) THEN
 // generate the table identifier of Table B
 SET ID TO “11”
 // append encoded bitstream B to ID
 SET code TO ID *   B
ELSEIF size_C <= min(size_A, size_B) THEN
 // generate the table identifier of Table C
 SET ID TO “0”
 // append encoded bitstream C to ID
 SET code TO ID *   C
ENDIF
RETURN code