summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2010-12-07 16:31:40 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2010-12-17 10:55:03 +0000
commit173c5201aad8ca3fe733a992d74fdcff6101f09a (patch)
tree0d009abf8462e4c843688a339782d6aaf399f250
parentbf9e9716394c406f754c8a952682ce6eb278ee71 (diff)
TpIntset: factor out tp_intset_union_update, tp_intset_difference_update
-rw-r--r--docs/reference/telepathy-glib-sections.txt2
-rw-r--r--telepathy-glib/intset.c69
-rw-r--r--telepathy-glib/intset.h3
3 files changed, 55 insertions, 19 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 721f8b970..b2bea10d2 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -1929,7 +1929,9 @@ tp_intset_is_equal
tp_intset_copy
tp_intset_intersection
tp_intset_union
+tp_intset_union_update
tp_intset_difference
+tp_intset_difference_update
tp_intset_symmetric_difference
tp_intset_dump
TpIntsetFastIter
diff --git a/telepathy-glib/intset.c b/telepathy-glib/intset.c
index 96dc76b34..86369f6c9 100644
--- a/telepathy-glib/intset.c
+++ b/telepathy-glib/intset.c
@@ -624,7 +624,6 @@ tp_intset_intersection (const TpIntset *left, const TpIntset *right)
return ret;
}
-
/**
* tp_intset_union:
* @left: The left operand
@@ -640,27 +639,43 @@ tp_intset_intersection (const TpIntset *left, const TpIntset *right)
TpIntset *
tp_intset_union (const TpIntset *left, const TpIntset *right)
{
- gpointer key, value;
- GHashTableIter iter;
TpIntset *ret;
ret = tp_intset_copy (left);
+ tp_intset_union_update (ret, right);
- g_hash_table_iter_init (&iter, (GHashTable *) right->table);
+ return ret;
+}
+
+/**
+ * tp_intset_union_update:
+ * @self: the set to change
+ * @other: members to add
+ *
+ * Add each integer in @other to @self, analogous to the bitwise operation
+ * self |= other.
+ *
+ * Since: 0.13.UNRELEASED
+ */
+void
+tp_intset_union_update (TpIntset *self,
+ const TpIntset *other)
+{
+ gpointer key, value;
+ GHashTableIter iter;
+
+ g_hash_table_iter_init (&iter, (GHashTable *) other->table);
while (g_hash_table_iter_next (&iter, &key, &value))
{
gsize v = GPOINTER_TO_SIZE (value);
- intset_update_largest_ever (ret, key);
- v |= GPOINTER_TO_SIZE (g_hash_table_lookup (ret->table, key));
- g_hash_table_insert (ret->table, key, GSIZE_TO_POINTER (v));
+ intset_update_largest_ever (self, key);
+ v |= GPOINTER_TO_SIZE (g_hash_table_lookup (self->table, key));
+ g_hash_table_insert (self->table, key, GSIZE_TO_POINTER (v));
}
-
- return ret;
}
-
/**
* tp_intset_difference:
* @left: The left operand
@@ -677,33 +692,49 @@ TpIntset *
tp_intset_difference (const TpIntset *left, const TpIntset *right)
{
TpIntset *ret;
- gpointer key, value;
- GHashTableIter iter;
g_return_val_if_fail (left != NULL, NULL);
g_return_val_if_fail (right != NULL, NULL);
ret = tp_intset_copy (left);
+ tp_intset_difference_update (ret, right);
- g_hash_table_iter_init (&iter, (GHashTable *) right->table);
+ return ret;
+}
+
+/**
+ * tp_intset_difference_update:
+ * @self: the set to change
+ * @other: members to remove
+ *
+ * Remove each integer in @other from @self, analogous to the bitwise
+ * operation self &= (~other).
+ *
+ * Since: 0.13.UNRELEASED
+ */
+void
+tp_intset_difference_update (TpIntset *self,
+ const TpIntset *other)
+{
+ gpointer key, value;
+ GHashTableIter iter;
+
+ g_hash_table_iter_init (&iter, (GHashTable *) other->table);
while (g_hash_table_iter_next (&iter, &key, &value))
{
gsize v = GPOINTER_TO_SIZE (value);
- v = (GPOINTER_TO_SIZE (g_hash_table_lookup (ret->table, key))) & ~v;
+ v = (GPOINTER_TO_SIZE (g_hash_table_lookup (self->table, key))) & ~v;
/* No need to update largest_ever here - we're only deleting members. */
if (v == 0)
- g_hash_table_remove (ret->table, key);
+ g_hash_table_remove (self->table, key);
else
- g_hash_table_insert (ret->table, key, GSIZE_TO_POINTER (v));
+ g_hash_table_insert (self->table, key, GSIZE_TO_POINTER (v));
}
-
- return ret;
}
-
/**
* tp_intset_symmetric_difference:
* @left: The left operand
diff --git a/telepathy-glib/intset.h b/telepathy-glib/intset.h
index b3eb2043b..5b9d907a5 100644
--- a/telepathy-glib/intset.h
+++ b/telepathy-glib/intset.h
@@ -132,6 +132,9 @@ void tp_intset_fast_iter_init (TpIntsetFastIter *iter,
gboolean tp_intset_fast_iter_next (TpIntsetFastIter *iter,
guint *output);
+void tp_intset_union_update (TpIntset *self, const TpIntset *other);
+void tp_intset_difference_update (TpIntset *self, const TpIntset *other);
+
G_END_DECLS
#endif /*__TP_INTSET_H__*/