From nobody Wed Feb 11 05:51:17 2026 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AF51374D2; Tue, 14 May 2024 08:48:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715676534; cv=none; b=JYrzGl2WhrKzzBAc7ewc+2eoH0Ol6pskPbc7PCBC7G4iQePxgNP6dfvKMvIzGZNt0/ZEPLqxP2ePqBXyHMnoKKk7AZ+KBjy7hQoZFAxwlD/yVWvZCXLT7rrTsrmQTZG5Z0tZMk4U1E3EYbfQA4uRoitx9NrPL2ec60LjMR3yVoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715676534; c=relaxed/simple; bh=CYJPttL+JF8N5/NTkoHY1q+LgvV7Sz6Pl1uxkoyDlPQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sWcYhgNXN5F1J5CbJDvC8EE6CzGVumVrFYDAl8Sa5amk4Yz1qLQU4NhoduKA/X7SSRzx/J8RrGL6Y01CcTmvMGpNUPDkX2hjCt6v8ZGK5z1fZW/Us7nP52cmmys3SUMoA16wWcNDCZe7S0ZEe++NqXWkcTROc4O/ChWHi9eEXiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HrgcKoME; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HrgcKoME" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2b360096cc4so1334834a91.1; Tue, 14 May 2024 01:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715676532; x=1716281332; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YsW/NrQIz4qgIL+42NXiwZPni65tkbkU75mwRevJWaw=; b=HrgcKoMEkVAYy+t0NQIYrScIyJQILx4leLSzQa+R+0OMxL3GojKF4R3KtWrW2MgvAo yjH2MT/jtbsKeOYXIjMD7ZojJOSwAVBuE2/Km1eHfuenMjtp1Tlfa9Kj+cJQijV+BAsi dMOCtG6t+C8ZFMnkWdWTBJm68fV6tmOnRSq2hjheuAN/0xPfBnltvgH315fv3XJHx+Yc VtvnThXqrolXKV7zhXtLCutcYE7eEqRWnkmmdgSF8dxqIA7tNFeIw6EkkenLhOL8Eoqc aXb5Q4KpO4gQDNhwjVWLdFgkixOgYm3eg4Dql/KJSze1MxTf/xIlJ/fFIpZEcr0/ICMy HxQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715676532; x=1716281332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YsW/NrQIz4qgIL+42NXiwZPni65tkbkU75mwRevJWaw=; b=QgB5b/8ZWcUwGtAuBWITGFkSsCTiG+7+z0r9Gaexq+dtHV6l/qipTdAC/LsNE/lgiH 3AJbnVhG6V2oMLw7+fjW+cIpUFd2+roZ2Dt0A2H2vXdAWC4EXtbZ9p0X5ZsypBxAJ57E NvLCiNqnoXc+O2QDB06VTKNexYeWW0XgP+B9FAHOYRI/CTnZxgcoy9s4jPQFJ/LBwXHA NUgeFeBfLTMhJd7ihL5lV6+tb2zoeHcivRfNtoQD5mWoH08GN9PFjFxefPg+NoJWgmO7 3xXItDo3QCBT1MIu/X/0tvgq038OtkK678KHur/veEPriUZDBtpVGZzc3EYgV9JsfgUc wydA== X-Forwarded-Encrypted: i=1; AJvYcCVPBPZRrjt7xgmap9iiK0xm6nGgUcD9uMK+sx+dSCtbYHrsFjT3gZPV/Hv/uXLL2ivvdHoD2lzlbzr2s50iVfrYyG4mtn5g1PsaK9zQZ/Tq5i77Y7PSfg4bLfgeb63ic6+qr14Fwky73SJjdySdbV9jWmYWB0QPgplc5qzLaM9KRKpYjTD6EOYmFhEwjqwA3pOvq8czMchZMD9Aq7vn1qBQj7d+ZAdYBExBkutW X-Gm-Message-State: AOJu0Yz8B6N73AjdYQ00pgnfhIk6x6mVxLLKN//39Z6oTZoaEOkKlnzB 8lRHododSG+eFGBIPrn66f/wYdm1Qyzg/hE07DSeJ2EM//LQ9LR/ X-Google-Smtp-Source: AGHT+IEZJBE4DY5W8seUtK7dDgv4H+R9ogDWxkvK6WzOdLPljg9hUEy4MyjVirQowRDmzupDGecTdQ== X-Received: by 2002:a05:6a21:329d:b0:1af:a5e8:d184 with SMTP id adf61e73a8af0-1afde224bd1mr14426210637.5.1715676532311; Tue, 14 May 2024 01:48:52 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2b6711660fdsm9195597a91.16.2024.05.14.01.48.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 01:48:51 -0700 (PDT) From: Kuan-Wei Chiu To: colyli@suse.de, kent.overstreet@linux.dev, msakai@redhat.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, akpm@linux-foundation.org Cc: bfoster@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, bagasdotme@gmail.com, jserv@ccns.ncku.edu.tw, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@lists.linux.dev, linux-bcachefs@vger.kernel.org, linux-perf-users@vger.kernel.org, Kuan-Wei Chiu Subject: [RESEND PATCH v5 16/16] bcachefs: Remove heap-related macros and switch to generic min_heap Date: Tue, 14 May 2024 16:47:24 +0800 Message-Id: <20240514084724.557100-17-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240514084724.557100-1-visitorckw@gmail.com> References: <20240514084724.557100-1-visitorckw@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop the heap-related macros from bcachefs and replacing them with the generic min_heap implementation from include/linux. By doing so, code readability is improved by using functions instead of macros. Moreover, the min_heap implementation in include/linux adopts a bottom-up variation compared to the textbook version currently used in bcachefs. This bottom-up variation allows for approximately 50% reduction in the number of comparison operations during heap siftdown, without changing the number of swaps, thus making it more efficient. Link: https://lkml.kernel.org/ioyfizrzq7w7mjrqcadtzsfgpuntowtjdw5pgn4qhvsdp= 4mqqg@nrlek5vmisbu Signed-off-by: Kuan-Wei Chiu Reviewed-by: Ian Rogers Acked-by: Kent Overstreet --- fs/bcachefs/clock.c | 43 ++++++++++---- fs/bcachefs/clock_types.h | 2 +- fs/bcachefs/ec.c | 76 ++++++++++++++++-------- fs/bcachefs/ec_types.h | 2 +- fs/bcachefs/util.h | 118 +------------------------------------- 5 files changed, 87 insertions(+), 154 deletions(-) diff --git a/fs/bcachefs/clock.c b/fs/bcachefs/clock.c index 363644451106..3ec64fe6a064 100644 --- a/fs/bcachefs/clock.c +++ b/fs/bcachefs/clock.c @@ -6,16 +6,29 @@ #include #include =20 -static inline long io_timer_cmp(io_timer_heap *h, - struct io_timer *l, - struct io_timer *r) +static inline bool io_timer_cmp(const void *l, const void *r, void __alway= s_unused *args) { - return l->expire - r->expire; + struct io_timer **_l =3D (struct io_timer **)l; + struct io_timer **_r =3D (struct io_timer **)r; + + return (*_l)->expire < (*_r)->expire; +} + +static inline void io_timer_swp(void *l, void *r, void __always_unused *ar= gs) +{ + struct io_timer **_l =3D (struct io_timer **)l; + struct io_timer **_r =3D (struct io_timer **)r; + + swap(*_l, *_r); } =20 void bch2_io_timer_add(struct io_clock *clock, struct io_timer *timer) { size_t i; + const struct min_heap_callbacks callbacks =3D { + .less =3D io_timer_cmp, + .swp =3D io_timer_swp, + }; =20 spin_lock(&clock->timer_lock); =20 @@ -26,11 +39,11 @@ void bch2_io_timer_add(struct io_clock *clock, struct i= o_timer *timer) return; } =20 - for (i =3D 0; i < clock->timers.used; i++) + for (i =3D 0; i < clock->timers.nr; i++) if (clock->timers.data[i] =3D=3D timer) goto out; =20 - BUG_ON(!heap_add(&clock->timers, timer, io_timer_cmp, NULL)); + BUG_ON(!min_heap_push(&clock->timers, &timer, &callbacks, NULL)); out: spin_unlock(&clock->timer_lock); } @@ -38,12 +51,16 @@ void bch2_io_timer_add(struct io_clock *clock, struct i= o_timer *timer) void bch2_io_timer_del(struct io_clock *clock, struct io_timer *timer) { size_t i; + const struct min_heap_callbacks callbacks =3D { + .less =3D io_timer_cmp, + .swp =3D io_timer_swp, + }; =20 spin_lock(&clock->timer_lock); =20 - for (i =3D 0; i < clock->timers.used; i++) + for (i =3D 0; i < clock->timers.nr; i++) if (clock->timers.data[i] =3D=3D timer) { - heap_del(&clock->timers, i, io_timer_cmp, NULL); + min_heap_del(&clock->timers, i, &callbacks, NULL); break; } =20 @@ -131,12 +148,16 @@ static struct io_timer *get_expired_timer(struct io_c= lock *clock, unsigned long now) { struct io_timer *ret =3D NULL; + const struct min_heap_callbacks callbacks =3D { + .less =3D io_timer_cmp, + .swp =3D io_timer_swp, + }; =20 spin_lock(&clock->timer_lock); =20 - if (clock->timers.used && + if (clock->timers.nr && time_after_eq(now, clock->timers.data[0]->expire)) - heap_pop(&clock->timers, ret, io_timer_cmp, NULL); + min_heap_pop(&clock->timers, &callbacks, NULL); =20 spin_unlock(&clock->timer_lock); =20 @@ -161,7 +182,7 @@ void bch2_io_timers_to_text(struct printbuf *out, struc= t io_clock *clock) spin_lock(&clock->timer_lock); now =3D atomic64_read(&clock->now); =20 - for (i =3D 0; i < clock->timers.used; i++) + for (i =3D 0; i < clock->timers.nr; i++) prt_printf(out, "%ps:\t%li\n", clock->timers.data[i]->fn, clock->timers.data[i]->expire - now); diff --git a/fs/bcachefs/clock_types.h b/fs/bcachefs/clock_types.h index 5fae0012d808..59716e148645 100644 --- a/fs/bcachefs/clock_types.h +++ b/fs/bcachefs/clock_types.h @@ -23,7 +23,7 @@ struct io_timer { /* Amount to buffer up on a percpu counter */ #define IO_CLOCK_PCPU_SECTORS 128 =20 -typedef HEAP(struct io_timer *) io_timer_heap; +typedef MIN_HEAP(struct io_timer *, io_timer_heap) io_timer_heap; =20 struct io_clock { atomic64_t now; diff --git a/fs/bcachefs/ec.c b/fs/bcachefs/ec.c index 082075244e16..ade65173898a 100644 --- a/fs/bcachefs/ec.c +++ b/fs/bcachefs/ec.c @@ -866,8 +866,8 @@ static int __ec_stripe_mem_alloc(struct bch_fs *c, size= _t idx, gfp_t gfp) =20 mutex_lock(&c->ec_stripes_heap_lock); if (n.size > h->size) { - memcpy(n.data, h->data, h->used * sizeof(h->data[0])); - n.used =3D h->used; + memcpy(n.data, h->data, h->nr * sizeof(h->data[0])); + n.nr =3D h->nr; swap(*h, n); } mutex_unlock(&c->ec_stripes_heap_lock); @@ -958,7 +958,7 @@ static u64 stripe_idx_to_delete(struct bch_fs *c) =20 lockdep_assert_held(&c->ec_stripes_heap_lock); =20 - if (h->used && + if (h->nr && h->data[0].blocks_nonempty =3D=3D 0 && !bch2_stripe_is_open(c, h->data[0].idx)) return h->data[0].idx; @@ -966,14 +966,6 @@ static u64 stripe_idx_to_delete(struct bch_fs *c) return 0; } =20 -static inline int ec_stripes_heap_cmp(ec_stripes_heap *h, - struct ec_stripe_heap_entry l, - struct ec_stripe_heap_entry r) -{ - return ((l.blocks_nonempty > r.blocks_nonempty) - - (l.blocks_nonempty < r.blocks_nonempty)); -} - static inline void ec_stripes_heap_set_backpointer(ec_stripes_heap *h, size_t i) { @@ -982,39 +974,71 @@ static inline void ec_stripes_heap_set_backpointer(ec= _stripes_heap *h, genradix_ptr(&c->stripes, h->data[i].idx)->heap_idx =3D i; } =20 +static inline bool ec_stripes_heap_cmp(const void *l, const void *r, void = __always_unused *args) +{ + struct ec_stripe_heap_entry *_l =3D (struct ec_stripe_heap_entry *)l; + struct ec_stripe_heap_entry *_r =3D (struct ec_stripe_heap_entry *)r; + + return ((_l->blocks_nonempty > _r->blocks_nonempty) < + (_l->blocks_nonempty < _r->blocks_nonempty)); +} + +static inline void ec_stripes_heap_swap(void *l, void *r, void *h) +{ + struct ec_stripe_heap_entry *_l =3D (struct ec_stripe_heap_entry *)l; + struct ec_stripe_heap_entry *_r =3D (struct ec_stripe_heap_entry *)r; + ec_stripes_heap *_h =3D (ec_stripes_heap *)h; + size_t i =3D _l - _h->data; + size_t j =3D _r - _h->data; + + swap(*_l, *_r); + + ec_stripes_heap_set_backpointer(_h, i); + ec_stripes_heap_set_backpointer(_h, j); +} + static void heap_verify_backpointer(struct bch_fs *c, size_t idx) { ec_stripes_heap *h =3D &c->ec_stripes_heap; struct stripe *m =3D genradix_ptr(&c->stripes, idx); =20 - BUG_ON(m->heap_idx >=3D h->used); + BUG_ON(m->heap_idx >=3D h->nr); BUG_ON(h->data[m->heap_idx].idx !=3D idx); } =20 void bch2_stripes_heap_del(struct bch_fs *c, struct stripe *m, size_t idx) { + const struct min_heap_callbacks callbacks =3D { + .less =3D ec_stripes_heap_cmp, + .swp =3D ec_stripes_heap_swap, + }; + mutex_lock(&c->ec_stripes_heap_lock); heap_verify_backpointer(c, idx); =20 - heap_del(&c->ec_stripes_heap, m->heap_idx, - ec_stripes_heap_cmp, - ec_stripes_heap_set_backpointer); + min_heap_del(&c->ec_stripes_heap, m->heap_idx, &callbacks, &c->ec_stripes= _heap); mutex_unlock(&c->ec_stripes_heap_lock); } =20 void bch2_stripes_heap_insert(struct bch_fs *c, struct stripe *m, size_t idx) { + const struct min_heap_callbacks callbacks =3D { + .less =3D ec_stripes_heap_cmp, + .swp =3D ec_stripes_heap_swap, + }; + mutex_lock(&c->ec_stripes_heap_lock); - BUG_ON(heap_full(&c->ec_stripes_heap)); + BUG_ON(min_heap_full(&c->ec_stripes_heap)); =20 - heap_add(&c->ec_stripes_heap, ((struct ec_stripe_heap_entry) { + genradix_ptr(&c->stripes, idx)->heap_idx =3D c->ec_stripes_heap.nr; + min_heap_push(&c->ec_stripes_heap, &((struct ec_stripe_heap_entry) { .idx =3D idx, .blocks_nonempty =3D m->blocks_nonempty, }), - ec_stripes_heap_cmp, - ec_stripes_heap_set_backpointer); + &callbacks, + &c->ec_stripes_heap); =20 heap_verify_backpointer(c, idx); mutex_unlock(&c->ec_stripes_heap_lock); @@ -1023,6 +1047,10 @@ void bch2_stripes_heap_insert(struct bch_fs *c, void bch2_stripes_heap_update(struct bch_fs *c, struct stripe *m, size_t idx) { + const struct min_heap_callbacks callbacks =3D { + .less =3D ec_stripes_heap_cmp, + .swp =3D ec_stripes_heap_swap, + }; ec_stripes_heap *h =3D &c->ec_stripes_heap; bool do_deletes; size_t i; @@ -1033,10 +1061,8 @@ void bch2_stripes_heap_update(struct bch_fs *c, h->data[m->heap_idx].blocks_nonempty =3D m->blocks_nonempty; =20 i =3D m->heap_idx; - heap_sift_up(h, i, ec_stripes_heap_cmp, - ec_stripes_heap_set_backpointer); - heap_sift_down(h, i, ec_stripes_heap_cmp, - ec_stripes_heap_set_backpointer); + min_heap_sift_up(h, i, &callbacks, &c->ec_stripes_heap); + min_heap_sift_down(h, i, &callbacks, &c->ec_stripes_heap); =20 heap_verify_backpointer(c, idx); =20 @@ -1828,7 +1854,7 @@ static s64 get_existing_stripe(struct bch_fs *c, return -1; =20 mutex_lock(&c->ec_stripes_heap_lock); - for (heap_idx =3D 0; heap_idx < h->used; heap_idx++) { + for (heap_idx =3D 0; heap_idx < h->nr; heap_idx++) { /* No blocks worth reusing, stripe will just be deleted: */ if (!h->data[heap_idx].blocks_nonempty) continue; @@ -2159,7 +2185,7 @@ void bch2_stripes_heap_to_text(struct printbuf *out, = struct bch_fs *c) size_t i; =20 mutex_lock(&c->ec_stripes_heap_lock); - for (i =3D 0; i < min_t(size_t, h->used, 50); i++) { + for (i =3D 0; i < min_t(size_t, h->nr, 50); i++) { m =3D genradix_ptr(&c->stripes, h->data[i].idx); =20 prt_printf(out, "%zu %u/%u+%u", h->data[i].idx, diff --git a/fs/bcachefs/ec_types.h b/fs/bcachefs/ec_types.h index 976426da3a12..2ed67431a81c 100644 --- a/fs/bcachefs/ec_types.h +++ b/fs/bcachefs/ec_types.h @@ -36,6 +36,6 @@ struct ec_stripe_heap_entry { unsigned blocks_nonempty; }; =20 -typedef HEAP(struct ec_stripe_heap_entry) ec_stripes_heap; +typedef MIN_HEAP(struct ec_stripe_heap_entry, ec_stripes_heap) ec_stripes_= heap; =20 #endif /* _BCACHEFS_EC_TYPES_H */ diff --git a/fs/bcachefs/util.h b/fs/bcachefs/util.h index 5cf885b09986..d5a1f1e29013 100644 --- a/fs/bcachefs/util.h +++ b/fs/bcachefs/util.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -54,17 +55,9 @@ static inline size_t buf_pages(void *p, size_t len) PAGE_SIZE); } =20 -#define HEAP(type) \ -struct { \ - size_t size, used; \ - type *data; \ -} - -#define DECLARE_HEAP(type, name) HEAP(type) name - #define init_heap(heap, _size, gfp) \ ({ \ - (heap)->used =3D 0; \ + (heap)->nr =3D 0; \ (heap)->size =3D (_size); \ (heap)->data =3D kvmalloc((heap)->size * sizeof((heap)->data[0]),\ (gfp)); \ @@ -76,113 +69,6 @@ do { \ (heap)->data =3D NULL; \ } while (0) =20 -#define heap_set_backpointer(h, i, _fn) \ -do { \ - void (*fn)(typeof(h), size_t) =3D _fn; \ - if (fn) \ - fn(h, i); \ -} while (0) - -#define heap_swap(h, i, j, set_backpointer) \ -do { \ - swap((h)->data[i], (h)->data[j]); \ - heap_set_backpointer(h, i, set_backpointer); \ - heap_set_backpointer(h, j, set_backpointer); \ -} while (0) - -#define heap_peek(h) \ -({ \ - EBUG_ON(!(h)->used); \ - (h)->data[0]; \ -}) - -#define heap_full(h) ((h)->used =3D=3D (h)->size) - -#define heap_sift_down(h, i, cmp, set_backpointer) \ -do { \ - size_t _c, _j =3D i; \ - \ - for (; _j * 2 + 1 < (h)->used; _j =3D _c) { \ - _c =3D _j * 2 + 1; \ - if (_c + 1 < (h)->used && \ - cmp(h, (h)->data[_c], (h)->data[_c + 1]) >=3D 0) \ - _c++; \ - \ - if (cmp(h, (h)->data[_c], (h)->data[_j]) >=3D 0) \ - break; \ - heap_swap(h, _c, _j, set_backpointer); \ - } \ -} while (0) - -#define heap_sift_up(h, i, cmp, set_backpointer) \ -do { \ - while (i) { \ - size_t p =3D (i - 1) / 2; \ - if (cmp(h, (h)->data[i], (h)->data[p]) >=3D 0) \ - break; \ - heap_swap(h, i, p, set_backpointer); \ - i =3D p; \ - } \ -} while (0) - -#define __heap_add(h, d, cmp, set_backpointer) \ -({ \ - size_t _i =3D (h)->used++; \ - (h)->data[_i] =3D d; \ - heap_set_backpointer(h, _i, set_backpointer); \ - \ - heap_sift_up(h, _i, cmp, set_backpointer); \ - _i; \ -}) - -#define heap_add(h, d, cmp, set_backpointer) \ -({ \ - bool _r =3D !heap_full(h); \ - if (_r) \ - __heap_add(h, d, cmp, set_backpointer); \ - _r; \ -}) - -#define heap_add_or_replace(h, new, cmp, set_backpointer) \ -do { \ - if (!heap_add(h, new, cmp, set_backpointer) && \ - cmp(h, new, heap_peek(h)) >=3D 0) { \ - (h)->data[0] =3D new; \ - heap_set_backpointer(h, 0, set_backpointer); \ - heap_sift_down(h, 0, cmp, set_backpointer); \ - } \ -} while (0) - -#define heap_del(h, i, cmp, set_backpointer) \ -do { \ - size_t _i =3D (i); \ - \ - BUG_ON(_i >=3D (h)->used); \ - (h)->used--; \ - if ((_i) < (h)->used) { \ - heap_swap(h, _i, (h)->used, set_backpointer); \ - heap_sift_up(h, _i, cmp, set_backpointer); \ - heap_sift_down(h, _i, cmp, set_backpointer); \ - } \ -} while (0) - -#define heap_pop(h, d, cmp, set_backpointer) \ -({ \ - bool _r =3D (h)->used; \ - if (_r) { \ - (d) =3D (h)->data[0]; \ - heap_del(h, 0, cmp, set_backpointer); \ - } \ - _r; \ -}) - -#define heap_resort(heap, cmp, set_backpointer) \ -do { \ - ssize_t _i; \ - for (_i =3D (ssize_t) (heap)->used / 2 - 1; _i >=3D 0; --_i) \ - heap_sift_down(heap, _i, cmp, set_backpointer); \ -} while (0) - #define ANYSINT_MAX(t) \ ((((t) 1 << (sizeof(t) * 8 - 2)) - (t) 1) * (t) 2 + (t) 1) =20 --=20 2.34.1