From patchwork Thu Feb 13 02:21:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11379659 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6F38109A for ; Thu, 13 Feb 2020 02:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E75A20848 for ; Thu, 13 Feb 2020 02:21:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729432AbgBMCVv (ORCPT ); Wed, 12 Feb 2020 21:21:51 -0500 Received: from cloud.peff.net ([104.130.231.41]:42118 "HELO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1729348AbgBMCVv (ORCPT ); Wed, 12 Feb 2020 21:21:51 -0500 Received: (qmail 9875 invoked by uid 109); 13 Feb 2020 02:20:39 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with SMTP; Thu, 13 Feb 2020 02:20:39 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 8754 invoked by uid 111); 13 Feb 2020 02:30:47 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Wed, 12 Feb 2020 21:30:46 -0500 Authentication-Results: peff.net; auth=none Date: Wed, 12 Feb 2020 21:21:50 -0500 From: Jeff King To: git@vger.kernel.org Subject: [PATCH 10/13] bitmap: add bitmap_unset() function Message-ID: <20200213022150.GJ1126038@coredump.intra.peff.net> References: <20200213021506.GA1124607@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200213021506.GA1124607@coredump.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We've never needed to unset an individual bit in a bitmap until now. Typically they start with all bits unset and we bitmap_set() them, or we are applying another bitmap as a mask. But the easiest way to apply an object filter to a bitmap result will be to unset the individual bits. Signed-off-by: Jeff King --- ewah/bitmap.c | 8 ++++++++ ewah/ewok.h | 1 + 2 files changed, 9 insertions(+) diff --git a/ewah/bitmap.c b/ewah/bitmap.c index 52f1178db4..1c31b3e249 100644 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@ -45,6 +45,14 @@ void bitmap_set(struct bitmap *self, size_t pos) self->words[block] |= EWAH_MASK(pos); } +void bitmap_unset(struct bitmap *self, size_t pos) +{ + size_t block = EWAH_BLOCK(pos); + + if (block < self->word_alloc) + self->words[block] &= ~EWAH_MASK(pos); +} + int bitmap_get(struct bitmap *self, size_t pos) { size_t block = EWAH_BLOCK(pos); diff --git a/ewah/ewok.h b/ewah/ewok.h index 84b2a29faa..59f4ef7c4f 100644 --- a/ewah/ewok.h +++ b/ewah/ewok.h @@ -173,6 +173,7 @@ struct bitmap { struct bitmap *bitmap_new(void); void bitmap_set(struct bitmap *self, size_t pos); +void bitmap_unset(struct bitmap *self, size_t pos); int bitmap_get(struct bitmap *self, size_t pos); void bitmap_reset(struct bitmap *self); void bitmap_free(struct bitmap *self);