Slim numerical data compression 1.0
bitstream.h File Reference

Include file for the bitstream and derived classes. More...

#include <stdint.h>
#include <cstdio>
#include "bit_constants.h"

Go to the source code of this file.

Classes

class  bitstream
 Bit stream base class. More...
 
class  obitstream
 Output bit stream. More...
 
class  ibitstream
 Input bit stream. More...
 

Functions

static unsigned int bit_size (int32_t i)
 Find size (on [0,32]) of the smallest # that can hold the integer i.
 
static unsigned int bit_size (unsigned int u)
 Find size (on [1,32]) of the smallest # that can hold the unsigned int u.
 

Detailed Description

Include file for the bitstream and derived classes.

Function Documentation

◆ bit_size() [1/2]

static unsigned int bit_size ( int32_t i)
inlinestatic

Find size (on [0,32]) of the smallest # that can hold the integer i.

By our convention, [-1,0] require 1 bit, [-2,1] require 2 bits, [-4,-3, 2,3] require 3 bits, etc. This was implemented as loops, but we find we save a lot of compute cycles by laying it out as an explicit tree of tests.

Parameters
iThe number whose size is being checked.

Referenced by mexp_golomb_write().

◆ bit_size() [2/2]

static unsigned int bit_size ( unsigned int u)
inlinestatic

Find size (on [1,32]) of the smallest # that can hold the unsigned int u.

By our convention, [0,1] require 1 bit, [2,3] require 2 bits, [4,5, 6,7] require 3 bits, etc.

Parameters
uThe number whose size is being checked.