![]() |
![]() |
![]() |
telepathy-glib Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <telepathy-glib/intset.h> TpIntSet; #define TP_TYPE_INTSET void (*TpIntFunc) (guint i
,gpointer userdata
); TpIntSet * tp_intset_sized_new (guint size
); TpIntSet * tp_intset_new (void
); TpIntSet * tp_intset_new_containing (guint element
); void tp_intset_destroy (TpIntSet *set
); void tp_intset_clear (TpIntSet *set
); void tp_intset_add (TpIntSet *set
,guint element
); gboolean tp_intset_remove (TpIntSet *set
,guint element
); gboolean tp_intset_is_member (const TpIntSet *set
,guint element
); void tp_intset_foreach (const TpIntSet *set
,TpIntFunc func
,gpointer userdata
); GArray * tp_intset_to_array (const TpIntSet *set
); TpIntSet * tp_intset_from_array (const GArray *array
); gboolean tp_intset_is_empty (const TpIntSet *set
); guint tp_intset_size (const TpIntSet *set
); gboolean tp_intset_is_equal (const TpIntSet *left
,const TpIntSet *right
); TpIntSet * tp_intset_copy (const TpIntSet *orig
); TpIntSet * tp_intset_intersection (const TpIntSet *left
,const TpIntSet *right
); TpIntSet * tp_intset_union (const TpIntSet *left
,const TpIntSet *right
); TpIntSet * tp_intset_difference (const TpIntSet *left
,const TpIntSet *right
); TpIntSet * tp_intset_symmetric_difference (const TpIntSet *left
,const TpIntSet *right
); gchar * tp_intset_dump (const TpIntSet *set
); TpIntSetFastIter; void tp_intset_fast_iter_init (TpIntSetFastIter *iter
,const TpIntSet *set
); gboolean tp_intset_fast_iter_next (TpIntSetFastIter *iter
,guint *output
); #define TP_INTSET_ITER_INIT (set) TpIntSetIter; #define tp_intset_iter_init (iter, set) gboolean tp_intset_iter_next (TpIntSetIter *iter
); #define tp_intset_iter_reset (iter)
A TpIntSet is a set of unsigned integers, implemented as a dynamically-allocated sparse bitfield.
#define TP_TYPE_INTSET (tp_intset_get_type ())
The boxed type of a TpIntSet.
Since 0.11.3
void (*TpIntFunc) (guint i
,gpointer userdata
);
A callback function acting on unsigned integers.
|
The relevant integer |
|
Opaque user data |
TpIntSet * tp_intset_sized_new (guint size
);
Allocate a new integer set.
|
ignored (it was previously 1 more than the largest integer you expect to store) |
Returns : |
a new, empty integer set to be destroyed with tp_intset_destroy()
|
TpIntSet * tp_intset_new (void
);
Allocate a new integer set.
Returns : |
a new, empty integer set to be destroyed with tp_intset_destroy()
|
TpIntSet * tp_intset_new_containing (guint element
);
Allocate a new integer set containing the given integer.
|
integer to add to a new set |
Returns : |
a new integer set containing element , to be destroyed with
tp_intset_destroy()
since 0.7.26
|
void tp_intset_destroy (TpIntSet *set
);
Free all memory used by the set.
|
set |
void tp_intset_add (TpIntSet *set
,guint element
);
Add an integer into a TpIntSet.
|
set |
|
integer to add |
gboolean tp_intset_remove (TpIntSet *set
,guint element
);
Remove an integer from a TpIntSet
|
set |
|
integer to add |
Returns : |
TRUE if element was previously in set
|
gboolean tp_intset_is_member (const TpIntSet *set
,guint element
);
Tests if element
is a member of set
|
set |
|
integer to test |
Returns : |
TRUE if element is in set
|
void tp_intset_foreach (const TpIntSet *set
,TpIntFunc func
,gpointer userdata
);
Call func
(element, userdata
) for each element of set
, in order.
|
set |
|
TpIntFunc to use to iterate the set
|
|
user data to pass to each call of func
|
GArray * tp_intset_to_array (const TpIntSet *set
);
|
set to convert |
Returns : |
a GArray of guint (which must be freed by the caller) containing
the same integers as set . [element-type uint]
|
TpIntSet * tp_intset_from_array (const GArray *array
);
|
An array of guint. [element-type uint] |
Returns : |
A set containing the same integers as array .
|
gboolean tp_intset_is_empty (const TpIntSet *set
);
Return the same thing as (tp_intset_size (set) == 0)
,
but calculated more efficiently.
|
a set of integers |
Returns : |
TRUE if set is empty
|
Since 0.11.6
guint tp_intset_size (const TpIntSet *set
);
|
A set of integers |
Returns : |
The number of integers in set
|
gboolean tp_intset_is_equal (const TpIntSet *left
,const TpIntSet *right
);
|
A set of integers |
|
A set of integers |
Returns : |
TRUE if left and right contain the same bits
|
TpIntSet * tp_intset_copy (const TpIntSet *orig
);
|
A set of integers |
Returns : |
A set containing the same integers as orig , to be freed with
tp_intset_destroy() by the caller
|
TpIntSet * tp_intset_intersection (const TpIntSet *left
,const TpIntSet *right
);
|
The left operand |
|
The right operand |
Returns : |
The set of those integers which are in both left and right
(analogous to the bitwise operation left & right), to be freed with
tp_intset_destroy() by the caller
|
TpIntSet * tp_intset_union (const TpIntSet *left
,const TpIntSet *right
);
|
The left operand |
|
The right operand |
Returns : |
The set of those integers which are in either left or right
(analogous to the bitwise operation left | right), to be freed with
tp_intset_destroy() by the caller
|
TpIntSet * tp_intset_difference (const TpIntSet *left
,const TpIntSet *right
);
|
The left operand |
|
The right operand |
Returns : |
The set of those integers which are in left and not in right
(analogous to the bitwise operation left & (~right)), to be freed with
tp_intset_destroy() by the caller
|
TpIntSet * tp_intset_symmetric_difference (const TpIntSet *left
,const TpIntSet *right
);
|
The left operand |
|
The right operand |
Returns : |
The set of those integers which are in either left or right
but not both (analogous to the bitwise operation left ^ right), to be freed
with tp_intset_destroy() by the caller
|
gchar * tp_intset_dump (const TpIntSet *set
);
|
An integer set |
Returns : |
a string which the caller must free with g_free, listing the
numbers in set in a human-readable format
|
typedef struct { } TpIntSetFastIter;
An opaque structure representing iteration in undefined order over a set of
integers. Must be initialized with tp_intset_fast_iter_init()
.
Usage is similar to GHashTableIter:
1 2 3 4 5 6 7 8 9 |
TpIntSetFastIter iter; guint element; tp_intset_fast_iter_init (&iter, intset); while (tp_intset_fast_iter_next (&iter, &element)) { printf ("%u is in the intset\n", element); } |
Since 0.11.6
void tp_intset_fast_iter_init (TpIntSetFastIter *iter
,const TpIntSet *set
);
Initialize iter
to iterate over set
in arbitrary order. iter
will become
invalid if set
is modified.
|
an iterator |
|
a set |
Since 0.11.6
gboolean tp_intset_fast_iter_next (TpIntSetFastIter *iter
,guint *output
);
Advances iter
and retrieves the integer it now points to. Iteration
is not necessarily in numerical order.
|
an iterator |
|
a location to store a new integer, in arbitrary order |
Returns : |
FALSE if the end of the set has been reached
|
Since 0.11.6
#define TP_INTSET_ITER_INIT(set) { (set), (guint)(-1) }
A suitable static initializer for a TpIntSetIter, to be used as follows:
1 2 3 4 5 6 |
void do_something (const TpIntSet *intset) { TpIntSetIter iter = TP_INTSET_ITER_INIT (intset); /* ... do something with iter ... */ } |
Since 0.11.6, consider using TpIntSetFastIter if iteration in numerical order is not required.
|
A set of integers |
typedef struct { const TpIntSet *set; guint element; } TpIntSetIter;
A structure representing iteration over a set of integers. Must be
initialized with either TP_INTSET_ITER_INIT()
or tp_intset_iter_init()
.
Since 0.11.6, consider using TpIntSetFastIter if iteration in numerical order is not required.
const TpIntSet * |
The set iterated over. |
Must be (guint)(-1) before iteration starts. Set to the next
element in the set by tp_intset_iter_next() ; undefined after
tp_intset_iter_next() returns FALSE .
|
#define tp_intset_iter_init(iter, set) tp_intset_iter_init_inline (iter, set)
Reset the iterator iter
to the beginning and make it iterate over set
.
|
An integer set iterator to be initialized. |
|
An integer set to be used by that iterator |
gboolean tp_intset_iter_next (TpIntSetIter *iter
);
If there are integers in (iter->set
) higher than (iter->element
), set
(iter->element) to the next one and return TRUE
. Otherwise return FALSE
.
Usage:
1 2 3 4 5 |
TpIntSetIter iter = TP_INTSET_INIT (intset); while (tp_intset_iter_next (&iter)) { printf ("%u is in the intset\n", iter.element); } |
Since 0.11.6, consider using TpIntSetFastIter if iteration in numerical order is not required.
|
An iterator originally initialized with TP_INTSET_INIT(set) |
Returns : |
TRUE if (iter->element ) has been advanced
|