+static notmuch_bool_t
+_notmuch_doc_id_set_init (void *ctx,
+ notmuch_doc_id_set_t *doc_ids,
+ GArray *arr)
+{
+ unsigned int max = 0;
+ unsigned int *bitmap;
+
+ for (unsigned int i = 0; i < arr->len; i++)
+ max = MAX(max, g_array_index (arr, unsigned int, i));
+ bitmap = talloc_zero_array (ctx, unsigned int, 1 + max / sizeof (*bitmap));
+
+ if (bitmap == NULL)
+ return FALSE;
+
+ doc_ids->bitmap = bitmap;
+ doc_ids->bound = max + 1;
+
+ for (unsigned int i = 0; i < arr->len; i++) {
+ unsigned int doc_id = g_array_index (arr, unsigned int, i);
+ bitmap[DOCIDSET_WORD(doc_id)] |= 1 << DOCIDSET_BIT(doc_id);
+ }
+
+ return TRUE;
+}
+
+notmuch_bool_t
+_notmuch_doc_id_set_contains (notmuch_doc_id_set_t *doc_ids,
+ unsigned int doc_id)
+{
+ if (doc_id >= doc_ids->bound)
+ return FALSE;
+ return doc_ids->bitmap[DOCIDSET_WORD(doc_id)] & (1 << DOCIDSET_BIT(doc_id));
+}
+
+void
+_notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,
+ unsigned int doc_id)
+{
+ if (doc_id < doc_ids->bound)
+ doc_ids->bitmap[DOCIDSET_WORD(doc_id)] &= ~(1 << DOCIDSET_BIT(doc_id));
+}
+