util: rb-tree: A simple, invasive, red-black tree
authorJason Ekstrand <jason@jlekstrand.net>
Thu, 5 Apr 2018 15:21:49 +0000 (08:21 -0700)
committerLionel Landwerlin <lionel.g.landwerlin@intel.com>
Thu, 5 Jul 2018 10:57:45 +0000 (11:57 +0100)
commit2602ea89d55cd1004bbec46c8ff1ac1ad1510940
treef97c0dace92b5693ffc2cc4814fb26941d0b6fa8
parent144b40db541183ba2ee18efa4e1531aabcf9c6e8
util: rb-tree: A simple, invasive, red-black tree

This is a simple, invasive, liberally licensed red-black tree
implementation. It's an invasive data structure similar to the
Linux kernel linked-list where the intention is that you embed a
rb_node struct the data structure you intend to put into the
tree.

The implementation is mostly based on the one in "Introduction to
Algorithms", third edition, by Cormen, Leiserson, Rivest, and
Stein. There were a few other key design points:

 * It's an invasive data structure similar to the [Linux kernel
   linked list].

 * It uses NULL for leaves instead of a sentinel. This means a few
   algorithms differ a small bit from the ones in "Introduction to
   Algorithms".

 * All search operations are inlined so that the compiler can
   optimize away the function pointer call.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/util/Makefile.sources
src/util/meson.build
src/util/rb_tree.c [new file with mode: 0644]
src/util/rb_tree.h [new file with mode: 0644]