GBitArray

GBitArray — An array of bit flags

Synopsis

struct              GBitArray;
GBitArray *         g_bit_array_new                     (guint bit_length);
GBitArray *         g_bit_array_resize                  (GBitArray *array,
                                                         guint bit_length);
GBitArray *         g_bit_array_extend                  (GBitArray *array,
                                                         guint num);
void                g_bit_array_copy                    (GBitArray *lhs,
                                                         const GBitArray *rhs);
guint               g_bit_array_get_len                 (const GBitArray *array);
guint               g_bit_array_get_num_set             (const GBitArray *array);
gboolean            g_bit_array_get_bit                 (const GBitArray *array,
                                                         guint pos);
GBitArray *         g_bit_array_set_bit                 (GBitArray *array,
                                                         guint pos);
GBitArray *         g_bit_array_clear_bit               (GBitArray *array,
                                                         guint pos);
gboolean            g_bit_array_flip_bit                (GBitArray *array,
                                                         guint pos);
GBitArray *         g_bit_array_set_bit_val             (GBitArray *array,
                                                         guint pos,
                                                         gboolean val);
GBitArray *         g_bit_array_set_range               (GBitArray *array,
                                                         guint start,
                                                         guint stop,
                                                         gboolean val);
GBitArray *         g_bit_array_reset                   (GBitArray *array,
                                                         gboolean val);
gboolean            g_bit_array_equal                   (GBitArray *lhs,
                                                         GBitArray *rhs);
gint                g_bit_array_serial_compare          (const GBitArray *a,
                                                         const GBitArray *b);
void                g_bit_array_iter_reset              (GBitArray *array);
gint                g_bit_array_iter_next               (GBitArray *array);

Object Hierarchy

  GObject
   +----GBitArray

Description

Details

struct GBitArray

struct GBitArray;


g_bit_array_new ()

GBitArray *         g_bit_array_new                     (guint bit_length);

Returns a new GBitArray with the given length. Note that the bit states are undefined.

bit_length :

the number of bits

Returns :

the new GBitArray

g_bit_array_resize ()

GBitArray *         g_bit_array_resize                  (GBitArray *array,
                                                         guint bit_length);

Resizes the GBitArray to the specified length. All bits are cleared after this operation.

array :

a GBitArray

bit_length :

The non-negative number of bits

Returns :

the resized GBitArray

g_bit_array_extend ()

GBitArray *         g_bit_array_extend                  (GBitArray *array,
                                                         guint num);

Extends array by num bits. Unlike g_bit_array_resize(), maintains the existing bits. New bits are cleared.

array :

a GBitArray

num :

number of bits to add

Returns :

the extended GBitArray

g_bit_array_copy ()

void                g_bit_array_copy                    (GBitArray *lhs,
                                                         const GBitArray *rhs);

Resizes lhs as necessary.

lhs :

GBitArray to be overwritten

rhs :

GBitArray to be copied

g_bit_array_get_len ()

guint               g_bit_array_get_len                 (const GBitArray *array);

Returns the bit length of the array.

array :

a GBitArray

Returns :

the length of the array in bits

g_bit_array_get_num_set ()

guint               g_bit_array_get_num_set             (const GBitArray *array);

array :

a GBitArray

Returns :

the number of bits that are set

g_bit_array_get_bit ()

gboolean            g_bit_array_get_bit                 (const GBitArray *array,
                                                         guint pos);

Returns whether or not the bit indexed by pos is set. The index must satisfy 0 <= pos < length.

array :

a GBitArray

pos :

the index of the bit to query

Returns :

gboolean status

g_bit_array_set_bit ()

GBitArray *         g_bit_array_set_bit                 (GBitArray *array,
                                                         guint pos);

Sets the bit indexed by pos to TRUE. The index must satisfy 0 <= pos < length.

array :

a GBitArray

pos :

the index of the bit to set

Returns :

the GBitArray

g_bit_array_clear_bit ()

GBitArray *         g_bit_array_clear_bit               (GBitArray *array,
                                                         guint pos);

Sets the bit indexed by pos to FALSE. The index must satisfy 0 <= pos < length.

array :

a GBitArray

pos :

the index of the bit to clear

Returns :

the GBitArray

g_bit_array_flip_bit ()

gboolean            g_bit_array_flip_bit                (GBitArray *array,
                                                         guint pos);

Negates the bit indexed by pos. The index must satisfy 0 <= pos < length.

array :

a GBitArray

pos :

the index of the bit to flip

Returns :

the new value of the bit

g_bit_array_set_bit_val ()

GBitArray *         g_bit_array_set_bit_val             (GBitArray *array,
                                                         guint pos,
                                                         gboolean val);

Sets the bit indexed by pos to val. The index must satisfy 0 <= pos < length.

array :

a GBitArray

pos :

the index of the bit to clear

val :

a boolean value

Returns :

the GBitArray

g_bit_array_set_range ()

GBitArray *         g_bit_array_set_range               (GBitArray *array,
                                                         guint start,
                                                         guint stop,
                                                         gboolean val);

Sets all of the bits between start and stop (inclusive) to val. The indeces must satisfy 0 <= start <= stop < length.

array :

a GBitArray

start :

the index of the first bit to set

stop :

the index of the last bit to set

val :

a boolean value

Returns :

the GBitArray

g_bit_array_reset ()

GBitArray *         g_bit_array_reset                   (GBitArray *array,
                                                         gboolean val);

Sets all of the bits in the array to val.

array :

a GBitArray

val :

a boolean value

Returns :

the GBitArray

g_bit_array_equal ()

gboolean            g_bit_array_equal                   (GBitArray *lhs,
                                                         GBitArray *rhs);

If lhs and rhs are not the same length, returns FALSE.

lhs :

a GBitArray

rhs :

another GBitArray

Returns :

TRUE if lhs and rhs have the same value

g_bit_array_serial_compare ()

gint                g_bit_array_serial_compare          (const GBitArray *a,
                                                         const GBitArray *b);

Compares a serialization of a and b. The serialization interprets the bit array as a base-2 integer.

a :

a GBitArray object

b :

a GBitArray object

Returns :

0 if a == b, -1 if a < b, and 1 if a > b.

g_bit_array_iter_reset ()

void                g_bit_array_iter_reset              (GBitArray *array);

Restarts the iterator at the beginning. The next call to g_bit_array_iter_next() will return the index of the first true bit.

array :

a GBitArray

g_bit_array_iter_next ()

gint                g_bit_array_iter_next               (GBitArray *array);

Returns the index of the next TRUE bit. Returns -1 when the end of the array has been reached.

array :

a GBitArray

Returns :

the bit index, or -1