SphinxBase  5prealpha
bitarr.h File Reference

An implementation bit array - memory efficient storage for digit int and float data. More...

#include <assert.h>
#include <string.h>
#include <stdint.h>
#include <sphinxbase/prim_type.h>
#include <sphinxbase/sphinxbase_export.h>

Go to the source code of this file.

Data Structures

struct  bitarr_mask_s
 Structure that specifies bits required to efficiently store certain data. More...
 
struct  bitarr_address_s
 Structure that stores address of certain value in bit array. More...
 

Typedefs

typedef struct bitarr_mask_s bitarr_mask_t
 Structure that specifies bits required to efficiently store certain data.
 
typedef struct bitarr_address_s bitarr_address_t
 Structure that stores address of certain value in bit array.
 

Functions

SPHINXBASE_EXPORT uint64 bitarr_read_int57 (bitarr_address_t address, uint8 length, uint64 mask)
 Read uint64 value from bit array. More...
 
SPHINXBASE_EXPORT void bitarr_write_int57 (bitarr_address_t address, uint8 length, uint64 value)
 Write specified value into bit array. More...
 
SPHINXBASE_EXPORT uint32 bitarr_read_int25 (bitarr_address_t address, uint8 length, uint32 mask)
 Read uint32 value from bit array. More...
 
SPHINXBASE_EXPORT void bitarr_write_int25 (bitarr_address_t address, uint8 length, uint32 value)
 Write specified value into bit array. More...
 
SPHINXBASE_EXPORT float bitarr_read_negfloat (bitarr_address_t address)
 Read non positive float32 from bit array. More...
 
SPHINXBASE_EXPORT void bitarr_write_negfloat (bitarr_address_t address, float value)
 Writes non positive float32 to bit array. More...
 
SPHINXBASE_EXPORT float bitarr_read_float (bitarr_address_t address)
 Reads float32 from bit array. More...
 
SPHINXBASE_EXPORT void bitarr_write_float (bitarr_address_t address, float value)
 Writes float32 to bit array. More...
 
SPHINXBASE_EXPORT void bitarr_mask_from_max (bitarr_mask_t *bit_mask, uint32 max_value)
 Fills mask for certain int range according to provided max value. More...
 
SPHINXBASE_EXPORT uint8 bitarr_required_bits (uint32 max_value)
 Computes amount of bits required ti store integers upto value provided. More...
 

Detailed Description

An implementation bit array - memory efficient storage for digit int and float data.

Implementation of basic operations of read/write digits consuming as little space as possible.

Definition in file bitarr.h.

Function Documentation

SPHINXBASE_EXPORT void bitarr_mask_from_max ( bitarr_mask_t bit_mask,
uint32  max_value 
)

Fills mask for certain int range according to provided max value.

Parameters
bit_maskmask that is filled
max_valuebigest integer that is going to be stored using this mask

Definition at line 172 of file bitarr.c.

References bitarr_required_bits().

SPHINXBASE_EXPORT float bitarr_read_float ( bitarr_address_t  address)

Reads float32 from bit array.

Parameters
addressin bit array from where to read
Returns
value float32 that was read

Definition at line 158 of file bitarr.c.

SPHINXBASE_EXPORT uint32 bitarr_read_int25 ( bitarr_address_t  address,
uint8  length,
uint32  mask 
)

Read uint32 value from bit array.

Assumes mask == (1 << length) - 1 where length <= 25

Parameters
addressto read from
lengthnumber of bits for value
maskof read value
Returns
uint32 value that was read

Definition at line 116 of file bitarr.c.

SPHINXBASE_EXPORT uint64 bitarr_read_int57 ( bitarr_address_t  address,
uint8  length,
uint64  mask 
)

Read uint64 value from bit array.

Assumes mask == (1 << length) - 1 where length <= 57

Parameters
addressto read from
lengthnumber of bits for value
maskof read value
Returns
uint64 value that was read

Definition at line 98 of file bitarr.c.

SPHINXBASE_EXPORT float bitarr_read_negfloat ( bitarr_address_t  address)

Read non positive float32 from bit array.

Probability [0, 1) in log domain can be stored like this.

Parameters
addressof value in bit array
Returns
float value taht was read

Definition at line 141 of file bitarr.c.

SPHINXBASE_EXPORT uint8 bitarr_required_bits ( uint32  max_value)

Computes amount of bits required ti store integers upto value provided.

Parameters
max_valuebigest integer that going to be stored using this amount of bits
Returns
amount of bits required to store integers from range with maximum provided

Definition at line 178 of file bitarr.c.

Referenced by bitarr_mask_from_max().

SPHINXBASE_EXPORT void bitarr_write_float ( bitarr_address_t  address,
float  value 
)

Writes float32 to bit array.

Parameters
addressin bit array where to write
valuefloat32 to write

Definition at line 165 of file bitarr.c.

References bitarr_write_int57().

SPHINXBASE_EXPORT void bitarr_write_int25 ( bitarr_address_t  address,
uint8  length,
uint32  value 
)

Write specified value into bit array.

Assumes value < (1 << length) and length <= 25. Assumes the memory is zero initially.

Parameters
addressin bit array ti write to
lengthamount of active bytes in value to write
valueinteger to write

Definition at line 128 of file bitarr.c.

SPHINXBASE_EXPORT void bitarr_write_int57 ( bitarr_address_t  address,
uint8  length,
uint64  value 
)

Write specified value into bit array.

Assumes value < (1 << length) and length <= 57. Assumes the memory is zero initially.

Parameters
addressto write to
lengthamount of active bytes in value to write
valueinteger to write

Definition at line 103 of file bitarr.c.

Referenced by bitarr_write_float(), and bitarr_write_negfloat().

SPHINXBASE_EXPORT void bitarr_write_negfloat ( bitarr_address_t  address,
float  value 
)

Writes non positive float32 to bit array.

Probability [0, 1) in log domain can be stored like this

Parameters
addresswhere to write
valuewhat to write

Definition at line 150 of file bitarr.c.

References bitarr_write_int57().