From: Kuan-Wei Chiu <visitorckw@gmail.com>
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 <visitorckw@gmail.com>
Subject: [PATCH v6 06/16] lib min_heap: Add min_heap_peek()
Date: Fri, 24 May 2024 23:29:48 +0800 [thread overview]
Message-ID: <20240524152958.919343-7-visitorckw@gmail.com> (raw)
In-Reply-To: <20240524152958.919343-1-visitorckw@gmail.com>
Add min_heap_peek() function to retrieve a pointer to the smallest
element. The pointer is cast to the appropriate type of heap elements.
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Ian Rogers <irogers@google.com>
---
include/linux/min_heap.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/min_heap.h b/include/linux/min_heap.h
index b384a4ea2afa..d9c4ae7ad0cc 100644
--- a/include/linux/min_heap.h
+++ b/include/linux/min_heap.h
@@ -53,6 +53,16 @@ void __min_heap_init(min_heap_char *heap, void *data, int size)
#define min_heap_init(_heap, _data, _size) \
__min_heap_init((min_heap_char *)_heap, _data, _size)
+/* Get the minimum element from the heap. */
+static __always_inline
+void *__min_heap_peek(struct min_heap_char *heap)
+{
+ return heap->nr ? heap->data : NULL;
+}
+
+#define min_heap_peek(_heap) \
+ (__minheap_cast(_heap) __min_heap_peek((min_heap_char *)_heap))
+
/* Sift the element at pos down the heap. */
static __always_inline
void __min_heapify(min_heap_char *heap, int pos, size_t elem_size,
--
2.34.1
next prev parent reply other threads:[~2024-05-24 15:30 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-24 15:29 [PATCH v6 00/16] treewide: Refactor heap related implementation Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 01/16] perf/core: Fix several typos Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 02/16] bcache: Fix typo Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 03/16] bcachefs: " Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 04/16] lib min_heap: Add type safe interface Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 05/16] lib min_heap: Add min_heap_init() Kuan-Wei Chiu
2024-05-24 15:29 ` Kuan-Wei Chiu [this message]
2024-05-24 15:29 ` [PATCH v6 07/16] lib min_heap: Add min_heap_full() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 08/16] lib min_heap: Add args for min_heap_callbacks Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 09/16] lib min_heap: Add min_heap_sift_up() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 10/16] lib min_heap: Add min_heap_del() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 11/16] lib min_heap: Update min_heap_push() and min_heap_pop() to return bool values Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 12/16] lib min_heap: Rename min_heapify() to min_heap_sift_down() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 13/16] lib min_heap: Update min_heap_push() to use min_heap_sift_up() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 14/16] lib/test_min_heap: Add test for heap_del() Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 15/16] bcache: Remove heap-related macros and switch to generic min_heap Kuan-Wei Chiu
2024-05-24 15:29 ` [PATCH v6 16/16] bcachefs: " Kuan-Wei Chiu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240524152958.919343-7-visitorckw@gmail.com \
--to=visitorckw@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=akpm@linux-foundation.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=bagasdotme@gmail.com \
--cc=bfoster@redhat.com \
--cc=colyli@suse.de \
--cc=dm-devel@lists.linux.dev \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=jserv@ccns.ncku.edu.tw \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-bcachefs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=msakai@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).