[libc-commits] [libc] [libc][tsearch] add tsearch functions (PR #172625)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri Jan 30 11:01:19 PST 2026
================
@@ -0,0 +1,137 @@
+//===-- Unittests for tsearch ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "hdr/types/posix_tnode.h"
+#include "src/search/tdelete.h"
+#include "src/search/tdestroy.h"
+#include "src/search/tfind.h"
+#include "src/search/tsearch.h"
+#include "src/search/twalk.h"
+#include "src/search/twalk_r.h"
+#include "test/UnitTest/Test.h"
+#include <search.h>
+
+static void *encode(int val) {
+ return reinterpret_cast<void *>(static_cast<intptr_t>(val));
+}
+
+static int decode(const void *val) {
+ return static_cast<int>(reinterpret_cast<intptr_t>(val));
+}
+
+static int read_and_decode(const __llvm_libc_tnode *val) {
+ return static_cast<int>(*static_cast<const intptr_t *>(val));
+}
+
+static int compare(const void *a, const void *b) {
+ int x = decode(a);
+ int y = decode(b);
+ return (x > y) - (x < y);
+}
----------------
michaelrj-google wrote:
ideally the tests should be similar to how the functions should actually be used. Is storing integers in the pointers a normal use case?
https://github.com/llvm/llvm-project/pull/172625
More information about the libc-commits
mailing list