GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> LDT / dev > encdec / rhel5-64


Interface   Data Structures   File List   Data Fields   Globals  

BTE.h File Reference

Binary Tree Encoding interface file. More...


Classes

struct  _BTE_compressed
 Combines the compressed word, its encoding scheme and its size in bits in one structure. More...

Typedefs

typedef struct _BTE_compressed BTE_compressed
 Typedef for struct _BTE_compressed.

Functions

BTE_compressed BTE_wordCompress (unsigned int w)
 Computes and returns the compressed word plus its size, in bits, plus the encoding scheme used.
unsigned int BTE_wordEncode (unsigned int w, unsigned int pattern, unsigned int scheme_size)
 Encodes the original word and its higher level binary tree pattern returning a 32 bit output word. The algorithm is such that at most 32 bits are used, not counting the bits needed to encode the scheme.
unsigned int BTE_wordPattern (unsigned int w)
 Prepares a pattern word which includes all but the lowest level of the binary tree.
unsigned int BTE_wordSize (unsigned int w, unsigned int pattern, unsigned int scheme)
 Computes the size using of the specified encoding schemes.
unsigned int BTE_wordSchemeSize (unsigned int w, unsigned int pattern)
 Computes the optimal encoding scheme and size using of the 4 possible encoding schemes.
unsigned int BTE_wordSizes (unsigned int w, unsigned int pattern)
 Computes the bit size of the encoded word using each of the 4 possible encoding schemes.
BTE_compressed BTE_shortCompress (unsigned short int w)
 Computes and returns the compressed short word plus its size, in bits,plus the encoding scheme used.
unsigned int BTE_shortEncode (unsigned short int w, unsigned int pattern, unsigned int scheme_size)
 Encodes the original word and its higher level binary tree pattern returning a 16 (only 14 used) bit output word. The algorithm is such that at most 16 bits are used, not counting the bits needed to encode the scheme.
unsigned int BTE_shortPattern (unsigned short int w)
 Prepares a pattern word which includes all but the lowest level of the binary tree.
unsigned int BTE_shortSize (unsigned short int w, unsigned int pattern, unsigned int scheme)
 Computes the size using of the specified encoding schemes.
unsigned int BTE_shortSchemeSize (unsigned short w, unsigned int pattern)
unsigned int BTE_shortSizes (unsigned short int w, unsigned int pattern)
 Computes the bit size of the encoded word using each of the 4 possible encoding schemes.
static __inline int BTE_size (unsigned int scheme_size)
 Extracts the size, in bits, from the scheme/size word.
static __inline int BTE_scheme (unsigned int scheme_size)
 Extracts the encoding scheme, from the scheme/size word.


Detailed Description

Binary Tree Encoding interface file.

Author:
JJRussell - russell@slac.stanford.edu
   CVS $Id: BTE.h,v 1.3 2009/04/29 23:06:40 russell Exp $

Interface specification for routines to encode bit strings using a binary tree.


Typedef Documentation

Typedef for struct _BTE_compressed.

This is the return value of the convenience function BTE_wordCompress.


Function Documentation

static __inline int BTE_scheme ( unsigned int  schemeSize  )  [static]

Extracts the encoding scheme, from the scheme/size word.

Returns:
The encoding scheme to be used
Parameters:
schemeSize The word containing the packed scheme and size fields. This is returned by BTE_wordSchemeSize

BTE_compressed BTE_shortCompress ( unsigned short int  w  ) 

Computes and returns the compressed short word plus its size, in bits,plus the encoding scheme used.

Returns:
A BTE_compressed structure containing the compressed word plus its size, in bits, plus the encoding scheme used
Parameters:
w The short word to compress
This is a convenience routine combining the
  • BTE_shortPattern
  • BTE_shortSchemeSize
  • BTE_shortEncode
While this routine is convenient, it does so at some cost. Each word is encoded according to the optimal scheme. This means the caller must make sure the encoding scheme is encoded along with each compressed word. The encoding of the encoding scheme itself costs some number of bits.
For a collection of words to encode, it may be more optimal to pick a fixed scheme. The fixed scheme may be based on some apriori knowledge (one just picks a scheme) or one computes the size of the collection for each of the 4 schemes, then uses the scheme giving the smallest total size of the whole collection, to encode the whole collection.

References BTE_shortEncode(), BTE_shortPattern(), BTE_shortSchemeSize(), _BTE_compressed::scheme_size, and _BTE_compressed::word.

unsigned int BTE_shortEncode ( unsigned short int  w,
unsigned int  pattern,
unsigned int  scheme_size 
)

Encodes the original word and its higher level binary tree pattern returning a 16 (only 14 used) bit output word. The algorithm is such that at most 16 bits are used, not counting the bits needed to encode the scheme.

Parameters:
w The original 16-bit word that is to be encoded
pattern The higher level binary tree pattern word. This is generally computed by calling BTE_shortPrepare().
scheme_size The encoding scheme to be used. This is generally computed by BTE_shortSchemeSize (), but can be determined by other means. The scheme is one of
  • 0, no encoding, just return w,
  • 1, encode using 01 = 0, 10 = 10, 11 = 11
  • 2, encode using 01 = 10, 10 = 0, 11 = 11
  • 3, encode using 01 = 10, 10 = 11, 11 = 0

Why is there an encoding scheme
The node of the binary encoding is a 2 bit number, indicating whether the left/right neighors are non-empty. However, to get to a node on of the left or right neighbors must be non-empty. Therefore there are really only 3 states, i.e. only the states 01, 10 and 11 must be represented, 00, being impossible. These three states can be represented by the following bit strings
  • 0
  • 10
  • 11

Without resorting to statistical encoding methods one can pick the the state occuring most of the time to be represented by the symbol with only 1 bit, i.e. 0.

Of course, to properly decode the encoded word, one needs the symbol. The user is free to carry the which encoding is to be used by any means he wishes. An extreme example would be to use a fixed scheme for all the symbols. One might compute the size of a collection of symbols using all each scheme, then pick the one that gives the smallest size.

References encode().

Referenced by BTE_shortCompress().

unsigned int BTE_shortPattern ( unsigned short int  w  ) 

Prepares a pattern word which includes all but the lowest level of the binary tree.

Parameters:
w The short word to encode
Returns:
The pattern word
A 16 bit word expressed as a binary tree takes a maximum of 31 bits to encode. This tree looks like



              +---------- x ----------+               half       =  1 bit
              |                       |
        +---- x ----+           +---- x ----+         byte       =  2 bits
        |           |           |           |
     +- x -+     +- x -+     +- x -+     +- x -+      nibble     =  4 bits
     |     |     |     |     |     |     |     |
     x     x     x     x     x     x     x     x      2 bit      =  8 bits
    / \   / \   / \   / \   / \   / \   / \   / \
   x   x x   x x   x x   x x   x x   x x   x x   x    1 bit      = 16 bits
                                                                   --
                                                                   31 bits
  

This pattern word is arranged by levels from the highest levels in the most significant bits to the lowest levels. Note that the lowest level of the tree is original 16 bit word.

Here is an example of tree for w = 0x8001


                                1                                   L0
                                |
                 1--------------+----------------1                  L1
                 |                               |
         1-------+-------0               0-------+-------1          L2
         |               |               |               |
     1---+---0       0---+---0       0---+---0       0---+---1      L3
     |       |       |       |       |       |       |       |
   1-+-0   0-+-0   0-+-0   0-+-0   0-+-0   0-+-0   0-+-0   0-+-1    L4


  
The levels are


       l0                     1
       L1                    1 1
       L2                   10 01
       L3                1000   0001 
       L4           10000000     00000001

  

Which, ignoring the lowest level, l5, is the pattern.

           1 11 1001 10000001 1000000000000001
           0111 1001 1000 0001 1000 0000 0000 0001
       = 0x79818001

  

Note, by convention, the highest level of the tree is ignored, so that only the upper 14 bits are used. This is beccause the upper bit only indicates whether the word is 0 or non-zero, something the user can easily determine.

Referenced by BTE_shortCompress().

unsigned int BTE_shortSize ( unsigned short int  w,
unsigned int  pattern,
unsigned int  scheme 
)

Computes the size using of the specified encoding schemes.

Returns:
A packed word containing the encoding scheme and its size in bits. The upper 16 bits are the scheme number and the lower 16 bits is the size in bits.
Parameters:
w The original short word (the lowest level of the tree
pattern The pattern word (the higher levels of the tree
scheme The encoding scheme to use
The schemes are 0: Just use the original 32 bit number 1: Use the scheme that assigns the 01 pattern the value 0 2: Use the scheme that assigns the 10 pattern the value 0 3: Use the scheme that assigns the 11 pattern the value 0

References BTE_shortCnts().

unsigned int BTE_shortSizes ( unsigned short int  w,
unsigned int  pattern 
)

Computes the bit size of the encoded word using each of the 4 possible encoding schemes.

Returns:
The 4 sizes packed a byte each into a 32-bit word with scheme 0 packed into the least signficant byte, scheme 1 into the next least signficant byte, etc.
Parameters:
w The original short word (the lowest level of the tree
pattern The pattern word (the higher levels of the tree
The encoding size of using each of the 4 possible encoding schemes is found. The sizes are packed into the 32-bit return value, a byte/size with scheme 0 in the least significant byte. The scheme identifiers are

0: Use the original 16-bit number (implies low byte = 16) 1: Use the scheme that assigns the 01 pattern the value 0 2: Use the scheme that assigns the 10 pattern the value 0 3: Use the scheme that assigns the 11 pattern the value 0

References BTE_shortCnts().

Referenced by BTE_shortSchemeSize().

static __inline int BTE_size ( unsigned int  schemeSize  )  [static]

Extracts the size, in bits, from the scheme/size word.

Returns:
The size field
Parameters:
schemeSize The word containing the packed scheme and size fields. This is returned by BTE_wordSchemeSize

BTE_compressed BTE_wordCompress ( unsigned int  w  ) 

Computes and returns the compressed word plus its size, in bits, plus the encoding scheme used.

Returns:
A BTE_compressed structure containing the compressed word plus its size, in bits, plus the encoding scheme used
Parameters:
w The word to compress
This is a convenience routine combining the
  • BTE_wordPattern
  • BTE_wordSchemeSize
  • BTE_wordEncode
While this routine is convenient, it does so at some cost. Each word is encoded according to the optimal scheme. This means the caller must make sure the encoding scheme is encoded along with each compressed word. The encoding of the encoding scheme itself costs some number of bits.
For a collection of words to encode, it may be more optimal to pick a fixed scheme. The fixed scheme may be based on some apriori knowledge (one just picks a scheme) or one computes the size of the collection for each of the 4 schemes, then uses the scheme giving the smallest total size of the whole collection, to encode the whole collection.

References BTE_wordEncode(), BTE_wordPattern(), BTE_wordSchemeSize(), _BTE_compressed::scheme_size, and _BTE_compressed::word.

unsigned int BTE_wordEncode ( unsigned int  w,
unsigned int  pattern,
unsigned int  scheme_size 
)

Encodes the original word and its higher level binary tree pattern returning a 32 bit output word. The algorithm is such that at most 32 bits are used, not counting the bits needed to encode the scheme.

Parameters:
w The original 32-bit word that is to be encoded
pattern The higher level binary tree pattern word. This is generally computed by calling BTE_wordPrepare().
scheme_size The encoding scheme to be used. This is generally computed by BTE_wordSchemeSize (), but can be determined by other means. The scheme is one of
  • 0, no encoding, just return w,
  • 1, encode using 01 = 0, 10 = 10, 11 = 11
  • 2, encode using 01 = 10, 10 = 0, 11 = 11
  • 3, encode using 01 = 10, 10 = 11, 11 = 0

Why is there an encoding scheme
The node of the binary encoding is a 2 bit number, indicating whether the left/right neighors are non-mpty. However, to get to a node on of the left or right neighbors must be non-empty. Therefore there are really only 3 states, i.e. only the states 01, 10 and 11 must be represented, 00, being impossible. These three states can be represented by the following bit strings
  • 0
  • 10
  • 11

Without resorting to statistical encoding methods one can pick the the state occuring most of the time to be represented by the symbol with only 1 bit, i.e. 0.

Of course, to properly decode the encoded word, one needs the symbol. The user is free to carry the which encoding is to be used by any means he wishes. An extreme example would be to use a fixed scheme for all the symbols. One might compute the size of a collection of symbols using all each scheme, then pick the one that gives the smallest size.

References encode().

Referenced by BTE_wordCompress().

unsigned int BTE_wordPattern ( unsigned int  w  ) 

Prepares a pattern word which includes all but the lowest level of the binary tree.

Parameters:
w The word to encode
Returns:
The pattern word
A 32 bit word express as a binary tree takes a maximum of 63 bits to encode. This tree looks like



              +---------- x ----------+               word       =  1 bit
              |                       |
        +---- x ----+           +---- x ----+         half       =  2 bits
        |           |           |           |
     +- x -+     +- x -+     +- x -+     +- x -+      byte       =  4 bits
     |     |     |     |     |     |     |     |
     x     x     x     x     x     x     x     x      nibble     =  8 bits
    / \   / \   / \   / \   / \   / \   / \   / \
   x   x x   x x   x x   x x   x x   x x   x x   x    2 bit      = 16 bits
   ab cd ef gh ij kl mn op qr st uv wx yz AB CD EF    1 bit      = 32 bits
                                                                   --
                                                                   63 bits
  

This pattern word is arranged by levels from the highest levels in the most significant bits to the lowest levels. Note that the lowest level of the tree is original 32 bit word.

Here is an example of tree for w = 0x00011000


                                1                                   L0
                                |
                 1--------------+----------------1                  L1
                 |                               |
         0-------+-------1               1-------+-------0          L2
         |               |               |               |
     0---+---0       0---+---1       1---+---0       0---+---0      L3
     |       |       |       |       |       |       |       |
   0-+-0   0-+-0   0-+-0   0-+-1   0-+-1   0-+-0   0-+-0   0-+-0    L4
   00 00   00 00   00 00   00 01   00 01   00 00   00 00   00 00    L5

  
The levels are


       l0                     1
       L1                    1 1
       L2                   01 10
       L3                0001   0100
       L4           00000001     01000000
       L5  0000000000000001       0001000000000000

  

Which, ignoring the lowest level, l5, is the pattern.

         0 1 11 0110 00010100 0000000101000000
       = 0x76180140

  

Note, by convention, the highest level of the tree is ignored, so that only the upper 30 bits are used. This is beccause the upper bit only indicates whether the word is 0 or non-zero, something the user can easily determine.

Referenced by BTE_wordCompress().

unsigned int BTE_wordSchemeSize ( unsigned int  w,
unsigned int  pattern 
)

Computes the optimal encoding scheme and size using of the 4 possible encoding schemes.

Returns:
A packed word containing the optimal encoding scheme and its size in bits. The upper 16 bits are the scheme number and the lower 16 bits is the size in bits.
Parameters:
w The original word (the lowest level of the tree
pattern The pattern word (the higher levels of the tree
The encoding size of using each of the 4 possible encoding schemes is found. The smallest size and its corresponding scheme identifier are returned. The scheme identifiers are

0: Just use the original 32 bit number 1: Use the scheme that assignes the 01 pattern the value 0 2: Use the scheme that assignes the 10 pattern the value 0 3: Use the scheme that assignes the 11 pattern the value 0

References BTE_wordSizes().

Referenced by BTE_wordCompress().

unsigned int BTE_wordSize ( unsigned int  w,
unsigned int  pattern,
unsigned int  scheme 
)

Computes the size using of the specified encoding schemes.

Returns:
A packed word containing the encoding scheme and its size in bits. The upper 16 bits are the scheme number and the lower 16 bits is the size in bits.
Parameters:
w The original word (the lowest level of the tree
pattern The pattern word (the higher levels of the tree
scheme The encoding scheme to use
The schems are 0: Just use the original 32 bit number 1: Use the scheme that assignes the 01 pattern the value 0 2: Use the scheme that assignes the 10 pattern the value 0 3: Use the scheme that assignes the 11 pattern the value 0

References BTE_wordCnts().

unsigned int BTE_wordSizes ( unsigned int  w,
unsigned int  pattern 
)

Computes the bit size of the encoded word using each of the 4 possible encoding schemes.

Returns:
The 4 sizes packed a byte each into a 32-bit word with scheme 0 packed into the least signficant byte, scheme 1 into the next least signficant byte, etc.
Parameters:
w The original word (the lowest level of the tree
pattern The pattern word (the higher levels of the tree
The encoding size of using each of the 4 possible encoding schemes is found. The sizes are packed into the 32-bit return value, a byte/size with scheme 0 in the least significant byte. The scheme identifiers are

0: Use the original 32-bit number (implies low byte = 32) 1: Use the scheme that assigns the 01 pattern the value 0 2: Use the scheme that assigns the 10 pattern the value 0 3: Use the scheme that assigns the 11 pattern the value 0

References BTE_wordCnts().

Referenced by BTE_wordSchemeSize().


Generated on Thu Feb 9 12:21:46 2012 by  doxygen 1.5.8