bitset Struct Reference


Public Methods

struct bitset* bitset_ctor (struct bitset *ptr_bitset, short size)
void bitset_clear (struct bitset *ptr_bitset)
void bitset_excl (struct bitset *ptr_bitset, short fbit)
bool bitset_in (struct bitset *ptr_bitset, short fbit)
void bitset_incl (struct bitset *ptr_bitset, short fbit)
void bitset_add (struct bitset *ptr_bitset_1, struct bitset *ptr_bitset_2)
void bitset_mul (struct bitset *ptr_bitset_1, struct bitset *ptr_bitset_2)
void bitset_sub (struct bitset *ptr_bitset_1, struct bitset *ptr_bitset_2)
void bitset_dtor (struct bitset *ptr_bitset, int memory_flag)


Detailed Description

Works with a set of bits using simple bit operations.

You must call the bitset_ctor() function before use, and the bitset_dtor() function after use.

See also:
Integer Math


Member Function Documentation

void bitset_add ( struct bitset * ptr_bitset_1,
struct bitset * ptr_bitset_2 )
 

Adds two bitsets, the same as logical OR.
The result will be stored in the first bitset.

Parameters:
ptr_bitset_1   A pointer to the first bitset
ptr_bitset_2   A pointer to the second bitset
Returns:
None
       #include <cybiko.h>
       ...
       struct bitset btset1;
       struct bitset btset2;
       bitset_ctor( &btset1, 8 );
       bitset_ctor( &btset2, 8 );
       ...
       bitset_clear( &btset1 );
       bitset_clear( &btset2 );
       
       bitset_incl( &btset1 , 0 );
       bitset_incl( &btset1 , 1 );
       bitset_incl( &btset2 , 0 );
       bitset_incl( &btset2 , 2 );
       ...
       //  Performs the logical OR operation.
       //  Before call:
       //      btset1   00000011  
       //      btset2   00000101
       //  After call:
       //      btset1   00000111  
       //      btset2   00000101
       bitset_add( &btset1, &btset2 );
       ...
       bitset_dtor( &btset1, LEAVE_MEMORY );
       bitset_dtor( &btset2, LEAVE_MEMORY );

void bitset_clear ( struct bitset * ptr_bitset )
 

Sets all bits to zero.

Parameters:
ptr_bitset   A pointer to the initialized bitset object
Returns:
None
       #include <cybiko.h>
       ...
       struct bitset float_value;
       bitset_ctor( &float_value, 32 );
       ...
       //  Sets a value to zero.
       bitset_clear( &float_value );
       ...
       bitset_dtor( &float_value, LEAVE_MEMORY );

struct bitset * bitset_ctor ( struct bitset * ptr_bitset,
short size )
 

Creates a set of bits.

Parameters:
ptr_bitset   A pointer to a bitset object
size   The number of bits in a bitset object
Returns:
A pointer to the initialized bitset object
       #include <cybiko.h>
       #define SIGN_BIT    31
       ...
       struct bitset float_value;
       bitset_ctor( &float_value, 32 );
       ...
       //  Takes abs of a value.
       bitset_excl( &float_value, SIGN_BIT );
       ...
       bitset_dtor( &float_value, LEAVE_MEMORY );
See also:
bitset_dtor.

void bitset_dtor ( struct bitset * ptr_bitset,
int memory_flag )
 

The bitset destructor.
Deletes a bitset object.

Parameters:
ptr_bitset   A pointer to the initialized bitset object.
memory_flag   Can be FREE_MEMORY or LEAVE_MEMORY. If the memory was allocated for the object by malloc(), use FREE_MEMORY to free it. Use LEAVE_MEMORY If the object was static or allocated in stack
Returns:
None
       #include <cybiko.h>
       #define SIGN_BIT    31
       ...
       struct bitset float_value;
       bitset_ctor( &float_value, 32 );
       ...
       //  Takes abs of a value.
       bitset_excl( &float_value, SIGN_BIT );
       ...
       bitset_dtor( &float_value, LEAVE_MEMORY );
See also:
bitset_ctor, FREE_MEMORY, LEAVE_MEMORY.

void bitset_excl ( struct bitset * ptr_bitset,
short fbit )
 

Excludes a bit from the set at a specified position.

Parameters:
ptr_bitset   A pointer to the initialized bitset object
fbit   The position of the bit to exclude
Returns:
None
       #include <cybiko.h>
       #define SIGN_BIT    31
       ...
       struct bitset float_value;
       bitset_ctor( &float_value, 32 );
       ...
       //  Takes abs of a value.
       bitset_excl( &float_value, SIGN_BIT );
       ...
       bitset_dtor( &float_value, LEAVE_MEMORY );
See also:
bitset_in, bitset_incl.

bool bitset_in ( struct bitset * ptr_bitset,
short fbit )
 

Determines whether the bit at a specified position was excluded.

Parameters:
ptr_bitset   A pointer to the initialized bitset object.
fbit   The position of the bit to test
Returns:
TRUE if the bit at the specified position was not excluded
       #include <cybiko.h>
       #define SIGN_BIT    31
       ...
       {
         struct bitset float_value;
         bitset_ctor( &float_value, 32 );
         ...
         //  Inverses a value.
         if( bitset_in( &float_value, SIGN_BIT ) ) 
         {
           bitset_excl( &float_value, SIGN_BIT );
         } 
         else 
         {
           bitset_incl( &float_value, SIGN_BIT );
         }
         ...
         bitset_dtor( &float_value, LEAVE_MEMORY );
       }
See also:
bitset_excl, bitset_incl.

void bitset_incl ( struct bitset * ptr_bitset,
short fbit )
 

Adds the bit at a specified position to the set.

Parameters:
ptr_bitset   A pointer to the initialized bitset object
fbit   The position of the bit to test
Returns:
None
       #include <cybiko.h>
       #define SIGN_BIT    31
       ...
       {
         struct bitset float_value;
         bitset_ctor( &float_value, 32 );
         ...
         //  Inverses a value.
         if( bitset_in( &float_value, SIGN_BIT ) )
         {
           bitset_excl( &float_value, SIGN_BIT );
         }
         else
         {
           bitset_incl( &float_value, SIGN_BIT );
         }
         ...
         bitset_dtor( &float_value, LEAVE_MEMORY );
       }
See also:
bitset_excl, bitset_in.

void bitset_mul ( struct bitset * ptr_bitset_1,
struct bitset * ptr_bitset_2 )
 

Multiplies two bitsets, the same as logical AND.
The result will be stored in the first bitset.

Parameters:
ptr_bitset_1   A pointer to the first bitset
ptr_bitset_2   A pointer to the second bitset
Returns:
None
       #include <cybiko.h>
       ...
       struct bitset btset1;
       struct bitset btset2;
       bitset_ctor( &btset1, 8 );
       bitset_ctor( &btset2, 8 );
       ...
       bitset_clear( &btset1 );
       bitset_clear( &btset2 );
       
       bitset_incl( &btset1 , 0 );
       bitset_incl( &btset1 , 1 );
       bitset_incl( &btset2 , 0 );
       bitset_incl( &btset2 , 2 );
       ...
       //  Performs the logical AND operation.
       //  Before call:
       //      btset1   00000011  
       //      btset2   00000101
       //  After call:
       //      btset1   00000001  
       //      btset2   00000101
       bitset_mul( &btset1, &btset2 );
       ...
       bitset_dtor( &btset1, LEAVE_MEMORY );
       bitset_dtor( &btset2, LEAVE_MEMORY );

void bitset_sub ( struct bitset * ptr_bitset_1,
struct bitset * ptr_bitset_2 )
 

Subtracts two bitsets, the same as logical XOR.
The result will be stored in the first bitset.

Parameters:
ptr_bitset_1   A pointer to the first bitset.
ptr_bitset_2   A pointer to the second bitset.
Returns:
None
       #include <cybiko.h>
       ...
       struct bitset btset1;
       struct bitset btset2;
       bitset_ctor( &btset1, 8 );
       bitset_ctor( &btset2, 8 );
       ...
       bitset_clear( &btset1 );
       bitset_clear( &btset2 );
       
       bitset_incl( &btset1 , 0 );
       bitset_incl( &btset1 , 1 );
       bitset_incl( &btset2 , 0 );
       bitset_incl( &btset2 , 2 );
       ...
       //  Performs the logical XOR operation.
       //  Before call:
       //      btset1   00000011  
       //      btset2   00000101
       //  After call:
       //      btset1   00000110  
       //      btset2   00000101
       bitset_sub( &btset1, &btset2 );
       ...
       bitset_dtor( &btset1, LEAVE_MEMORY );
       bitset_dtor( &btset2, LEAVE_MEMORY );