+static notmuch_bool_t
+_notmuch_doc_id_set_init (void *ctx,
+ notmuch_doc_id_set_t *doc_ids,
+ GArray *arr, unsigned int bound)
+{
+ size_t count = (bound + sizeof (doc_ids->bitmap[0]) - 1) /
+ sizeof (doc_ids->bitmap[0]);
+ unsigned int *bitmap = talloc_zero_array (ctx, unsigned int, count);
+
+ if (bitmap == NULL)
+ return FALSE;
+
+ doc_ids->bitmap = bitmap;
+ doc_ids->bound = bound;
+
+ for (unsigned int i = 0; i < arr->len; i++) {
+ unsigned int doc_id = g_array_index(arr, unsigned int, i);
+ bitmap[doc_id / sizeof (bitmap[0])] |=
+ 1 << (doc_id % sizeof (bitmap[0]));
+ }
+
+ 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[doc_id / sizeof (doc_ids->bitmap[0])] &
+ (1 << (doc_id % sizeof (doc_ids->bitmap[0])))) != 0;
+}
+
+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[doc_id / sizeof (doc_ids->bitmap[0])] &=
+ ~(1 << (doc_id % sizeof (doc_ids->bitmap[0])));
+}
+