Research Article

An Adaptive Lossless Data Compression Scheme for Wireless Sensor Networks

Algorithm 1

Pseudo-code of 2-Huffman Table ALEC.
2TableALECencoder( 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 2-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 2-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)
// compare size_A and size_B and select the encoded bitstream with the least compressed size
IF size_A <= size_B THEN
 // generate the table identifier of Table A
 SET ID TO “0”
 // append encoded bitstream A to ID
 SET code TO ID *   A
ELSE
 // generate the table identifier of Table B
 SET ID TO “1”
 // append encoded bitstream B to ID
 SET code TO ID *   B
ENDIF
RETURN code