Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

codeword.cc File Reference

#include "config.h"
#include "codeword.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>

Include dependency graph for codeword.cc:

Include dependency graph

Go to the source code of this file.

Functions

void init_bitcount_array (unsigned char *arr, unsigned int nb_bits)
void init_minbit_array (unsigned char *arr, unsigned int minbits)
unsigned int minbit (unsigned long val)
unsigned int bitcount (unsigned long val)
int initialize_codeword ()
unsigned int minbit (const ExtraLongUInt &val)
unsigned int bitcount (const ExtraLongUInt &val)

Variables

unsigned char minbit_array [256]
unsigned char bitcount_array [256]
int dummy = initialize_codeword()


Function Documentation

unsigned int bitcount const ExtraLongUInt val  ) 
 

Definition at line 555 of file codeword.cc.

References ExtraLongUInt::bitcount().

Referenced by MFTPSndAgent::fill_read_ahead_buf().

00556 {
00557     return val.bitcount();
00558 }

Here is the call graph for this function:

unsigned int bitcount unsigned long  val  ) 
 

Definition at line 235 of file codeword.cc.

00236 {
00237     unsigned int res = 0;
00238 
00239     while(val) {
00240         res += bitcount_array[(unsigned int) (val & 255)];
00241         val >>= 8;
00242     }
00243     return res;
00244 }

void init_bitcount_array unsigned char *  arr,
unsigned int  nb_bits
 

Definition at line 172 of file codeword.cc.

Referenced by initialize_codeword().

00173 {
00174     unsigned long bitcount_array_size = ((unsigned long) 1) << nb_bits;
00175     unsigned long i;
00176     unsigned int bit;
00177     int count;
00178 
00179     assert(sizeof(unsigned long) == 4);   // we need this for the following
00180     assert(0 < nb_bits && nb_bits <= 32); // or else this function must be revised
00181     assert(arr != NULL);
00182 
00183     for(i = 0; i < bitcount_array_size; ++i) {
00184         count = 0;
00185         // to avoid warning: unsigned value >= 0 is always 1
00186         // for(bit = 0; 0 <= bit && bit < nb_bits; bit++) {
00187         for(bit = 0; bit < nb_bits; bit++) {
00188             if(i & ((unsigned long) 1 << bit)) {
00189                 count++;
00190             }
00191         }
00192         arr[i] = count;
00193     }
00194 }

void init_minbit_array unsigned char *  arr,
unsigned int  minbits
 

Definition at line 196 of file codeword.cc.

Referenced by initialize_codeword().

00197 {
00198     unsigned int minbit_array_size = (unsigned int) 1 << minbits;
00199     unsigned int i;
00200     unsigned int bit;
00201 
00202     assert(minbits == 8); // or else minbit(...) needs a revision!
00203     assert(arr != NULL);
00204 
00205     for(i = 0; i < minbit_array_size; ++i) {
00206       // to avoid warning: unsigned value >= 0 is always 1
00207       //for(bit = 0; 0 <= bit && bit < minbits; bit++) {
00208         for(bit = 0; bit < minbits; bit++) {
00209             if(i & ((unsigned int) 1 << bit)) {
00210                 arr[i] = (unsigned char) bit;
00211                 break;
00212             }
00213         }
00214     }
00215 }

int initialize_codeword  ) 
 

Definition at line 247 of file codeword.cc.

References bitcount_array, init_bitcount_array(), init_minbit_array(), and minbit_array.

00248 {
00249     assert(sizeof(minbit_array) / sizeof(unsigned char) == 256);
00250     init_minbit_array(minbit_array, 8);
00251     init_bitcount_array(bitcount_array, 8);
00252     return 0;
00253 }

Here is the call graph for this function:

unsigned int minbit const ExtraLongUInt val  ) 
 

Definition at line 549 of file codeword.cc.

References ExtraLongUInt::minbit().

Referenced by MFTPSndAgent::fill_read_ahead_buf(), and MFTPRcvAgent::process_packet().

00550 {
00551     return val.minbit();
00552 }

Here is the call graph for this function:

unsigned int minbit unsigned long  val  ) 
 

Definition at line 218 of file codeword.cc.

00219 {
00220     unsigned int i;
00221 
00222     assert(val);
00223     for(i = 0; val; ++i) {
00224         assert(i < sizeof(CW_PATTERN_t));
00225         if(val & 255) {
00226             return minbit_array[(unsigned int) (val & 255)] + 8*i;
00227         }
00228         val >>= 8;
00229     }
00230     assert(false); // value is 0
00231     return 0;      // compiler, be quiet.
00232 }


Variable Documentation

unsigned char bitcount_array[256] [static]
 

Definition at line 30 of file codeword.cc.

Referenced by bitcount(), and initialize_codeword().

int dummy = initialize_codeword() [static]
 

Definition at line 34 of file codeword.cc.

unsigned char minbit_array[256] [static]
 

Definition at line 29 of file codeword.cc.

Referenced by initialize_codeword(), and minbit().


Generated on Tue Apr 20 12:16:59 2004 for NS2.26SourcesOriginal by doxygen 1.3.3