MLib Alpha 1 API Reference

MLib Alpha 1 API Reference

Bit Sets

an MLib M_Bitset is a dynamically growable set of bits


M_Bitset


  typedef struct M_BitsetRec_*          M_Bitset;

handle to a ?M_BitsetRec object, used to model a given bitset



m_bitset_new


  MLIB_API(M_Bitset)   m_bitset_new( M_Memory  memory,
                                     M_Bool    push );

create a new (empty) bitset


input
memory

current memory handler

push

boolean. when set, the new bitset is pushed on the cleanup stack

return

handle to new bitset, cannot be NULL

throws

out-of-memory

throws

out-of-memory


m_bitset_copy


  MLIB_API(M_Bitset)   m_bitset_copy( M_Bitset  source,
                                      M_Bool    push );

returns the copy of a given bitset


input
source

source bitset handle

push

boolean. when set, the copy is pushed on the cleanup stack

return

handle to bitset copy

throws

out-of-memory


m_bitset_destroy


  MLIB_API(void)       m_bitset_destroy( M_Bitset  bitset );

destroy a given bitset (you must ensure that the bitset is not on the cleanup stack)


input
bitset

target bitset handle


m_bitset_is_empty


  MLIB_API(M_Bool)     m_bitset_is_empty( M_Bitset  bitset );

a function that returns true iff a bitset is empty (i.e. all bits to 0)


input
bitset

source bitset handle

return

boolean


m_bitset_ensure


  MLIB_API(void)       m_bitset_ensure( M_Bitset  source,
                                        M_UInt    count );

reallocates a bitset block pointers table in order to ensure that it can hold at least "count" bits.

this function is used internally, and shouldn't be called directly by client applications, except in certain rare cases..


input
source

source bitset handle

count

minimum bit count to ensure.

throws

out-of-memory


m_bitset_get


  MLIB_API(M_UInt)     m_bitset_get ( M_Bitset  bitset,
                                      M_UInt    index );

return the value of a given bit in a bitset


input
bitset

source bitset handle

index

bit position, starting from 0. there is no upper limit but bits are set to 0 by default.

return

bit value (0 or 1)


m_bitset_get2


  MLIB_API(M_UInt)     m_bitset_get2( M_Bitset  bitset,
                                      M_UInt    index );

return the value of a given 2-bit cell in a bitset


input
bitset

source bitset handle

index

cell position, starting from 0. there is no upper limit but cells are set to 0 by default.

return

cell value (0 to 3)

note

this functions reads the bits at [2*index..2*index+1]


m_bitset_get4


  MLIB_API(M_UInt)     m_bitset_get4( M_Bitset  bitset,
                                      M_UInt    index );

return the value of a given 4-bit cell in a bitset


input
bitset

source bitset handle

index

cell position, starting from 0. there is no upper limit but cells are set to 0 by default.

return

cell value (0 to 15)

note

this functions reads the bits at [4*index..4*index+3]


m_bitset_get8


  MLIB_API(M_UInt)     m_bitset_get8( M_Bitset  bitset,
                                      M_UInt    index );

return the value of a given 8-bit cell in a bitset


input
bitset

source bitset handle

index

cell position, starting from 0. there is no upper limit but cells are set to 0 by default.

return

cell value (0 to 255)

note

this functions reads the bits at [8*index..8*index+7]


m_bitset_set


  MLIB_API(void)       m_bitset_set ( M_Bitset   bitset,
                                      M_UInt     index,
                                      M_UInt     value );

set the value of a given bit in a bitset


input
bitset

target bitset handle

index

bit position, starting from 0. there is no upper limit as the bitset is extended accordingly

value

bit value (note that is is anded with 1)

throws

out-of-memory


m_bitset_set2


  MLIB_API(void)       m_bitset_set2( M_Bitset   bitset,
                                      M_UInt     index,
                                      M_UInt     value );

set the value of a given 2-bit cell in a bitset


input
bitset

target bitset handle

index

bit position, starting from 0. there is no upper limit as the bitset is extended accordingly

value

new cell value

note

the value is anded with 3 before being applied this function sets the bits at [2*index..2*index+1]

throws

out-of-memory


m_bitset_set4


  MLIB_API(void)       m_bitset_set4( M_Bitset   bitset,
                                      M_UInt     index,
                                      M_UInt     value );

set the value of a given 4-bit cell in a bitset


input
bitset

target bitset handle

index

bit position, starting from 0. there is no upper limit as the bitset is extended accordingly

value

new cell value

note

the value is anded with 15 before being applied this function sets the bits at [4*index..4*index+3]

throws

out-of-memory


m_bitset_set8


  MLIB_API(void)       m_bitset_set8( M_Bitset   bitset,
                                      M_UInt     index,
                                      M_UInt     value );

set the value of a given 8-bit cell in a bitset


input
bitset

target bitset handle

index

bit position, starting from 0. there is no upper limit as the bitset is extended accordingly

value

new cell value

note

the value is anded with 255 before being applied this function sets the bits at [8*index..8*index+7]

throws

out-of-memory


m_bitset_set_range


  MLIB_API(void)       m_bitset_set_range( M_Bitset  bitset,
                                           M_UInt    start,
                                           M_UInt    count,
                                           M_UInt    size,
                                           M_UInt    value );

this function is used to set a range of bit cells to a single value.


input
bitset

target bitset handle

start

start bit/cell position

count

number of bits/cells to set

size

size of bit cell (1,2,4 or 8)

value

new bit/cell value

note

this function will panic if "size" is not 1, 2, 4 or 8

the value is anded with (1 << size)-1 before being applied this function sets the bits at [size*index..size*index+size-1]

throws

out-of-memory


m_bitset_test_intersect


  MLIB_API(M_Bool)     m_bitset_test_intersect( M_Bitset  bitset1,
                                                M_Bitset  bitset2 );

returns true iff two bitsets intersect


input
bitset1

first bitset

bitset2

second bitset

note

this function is a quick way to test if two bitsets intersect. however, if you need the intersection itself, consider using m_bitset_intersect directly..


m_bitset_clear


  MLIB_API(void)       m_bitset_clear( M_Bitset  bitset );

clear a bitset, i.e. set all bits/cells to 0


input
bitset

target bitset handle


m_bitset_union


  MLIB_API(M_Bitset)   m_bitset_union( M_Bitset  bitset1,
                                       M_Bitset  bitset2,
                                       M_Bool    push );

computes the union of two bitsets


input
bitset1

first bitset

bitset2

second bitset

push

boolean. if set, the result is pushed on the cleanup stack

return

union of the two bitsets

throws

out-of-memory


m_bitset_intersect


  MLIB_API(M_Bitset)   m_bitset_intersect( M_Bitset  bitset1,
                                           M_Bitset  bitset2,
                                           M_Bool    push );

computes the intersection of two bitsets


input
bitset1

first bitset

bitset2

second bitset

push

boolean. if set, the result is pushed on the cleanup stack

return

intersection of the two bitsets

throws

out-of-memory


m_bitset_substract


  MLIB_API(M_Bitset)   m_bitset_substract( M_Bitset  bitset1,
                                           M_Bitset  bitset2,
                                           M_Bool    push );

computes the substraction of two bitsets


input
bitset1

first bitset

bitset2

second bitset

push

boolean. if set, the result is pushed on the cleanup stack

return

bitset1 - bitset2

throws

out-of-memory


m_bitset_compress


  MLIB_API(void)       m_bitset_compress( M_Bitset  bitset );

compress a given bitset in memory.


input
bitset

handle to target bitset


m_bitset_push


  MLIB_API(void)       m_bitset_push( M_Bitset  set );

push a given bitset on the cleanup stack


input
bitset

target bitset handle


m_bitset_pop


  MLIB_API(void)       m_bitset_pop( M_Bitset  bitset,
                                     M_Bool    keep_it );

pops a given bitset from the cleanup stack


input
bitset

target bitset handle

keep_it

boolean. if true, the bitset isn't destroyed


generated on Tue Oct 09 23:59:46 2001