[libc-commits] [libc] [libc] Use best-fit binary trie to make malloc logarithmic (PR #106259)

via libc-commits libc-commits at lists.llvm.org
Thu Oct 10 10:41:14 PDT 2024


================
@@ -0,0 +1,252 @@
+//===-- Interface for freetrie --------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+#define LLVM_LIBC_SRC___SUPPORT_FREETRIE_H
+
+#include "freelist.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+/// A trie of free lists.
+
+class FreeTrie {
+public:
+  /// A trie node that is also a free list. The subtrie contains a continous
+  /// SizeRange of free lists. The lower and upper subtrie's contain the lower
+  /// and upper half of the subtries range. There is no direct relationship
+  /// between the size of this node's free list and the contents of the lower
+  /// and upper subtries.
+  class Node : public FreeList::Node {
+    /// Return an abitrary leaf in the subtrie.
+    Node &leaf();
----------------
nopsledder wrote:

debatable: Since this is only needed by `FreeTrie::remove`, and `FreeTrie` is already a friend, I might suggesting getting rid of this method and moving that code directly into `remove`. It's just feels like an odd bit of interface.

https://github.com/llvm/llvm-project/pull/106259


More information about the libc-commits mailing list