Acidanthera UEFI Development Kit based on EDK II edk2-stable202311
Go to file
Laszlo Ersek cf556c6a58 MdePkg: introduce BaseOrderedCollectionRedBlackTreeLib library instance
edk2 should have a fast and easy-to-use associative array (a dictionary)
type.

Red-black trees have O(log(n)) worst case time complexity for lookup,
insertion, and deletion (where n is the number of nodes in the tree). They
support minimum and maximum lookup with the same time complexity, hence
red-black trees double as priority queues as well.

Given an iterator to a red-black tree node, getting the next or previous
node (which corresponds to the ordered successor or the predecessor,
respectively, according to the user-defined ordering) is O(log(n)) as
well.

The code reflects the Binary Search Trees and Red-Black Trees chapters of
Introduction to Algorithms, by Cormen, Leiserson, Rivest. One point where
the implementation diverges is the first phase of the Delete() operation.
During that phase, the book's algorithm copies the key and other business
*contents* of the successor node (in case the successor node is affected),
and releases the successor node (instead of the node that the user
requested to delete).

While semantically correct, this would break the above iterator validity
guarantee. This implementation replaces the copying of business contents
between nodes with suitable relinking of nodes, so that all iterators
(except the one whose deletion is being requested) remain valid.

I had written this code originally in approx. 2002. I personally own the
copyright of that version and am hereby relicensing it to Red Hat, under
the BSDL. I had used the original code in a few personal projects since,
for example in the lbzip2-0.x parallel (de)compressor, and now I've ported
the library to edk2. Both during the original implementation and now
during the porting I verified all the cases and their proofs as rigorously
as I could, on paper. (NB, I couldn't find any errors in the 2002 code
now.)

During the porting to edk2, I documented all those cases in code comments
as well (at least half of the source is documentation). These comments are
not blind copies of diagrams from the Algorithms book, nor are they copies
from my original code -- I've done them all fresh now, and I've only
matched the results against the book. Reviewers are invited to sit down
with a pen, some paper, the book, and the code.

The Validate() function verifies the internal red-black properties of the
tree. This function helps with unit testing, and is only invoked when
requested with the PcdValidateOrderedCollection feature flag.

A note about diagrams: edges represented by backslash (\) characters are
often written as "\_", ie. with a following underscore. This is because
line-trailing backslashes are processed very early in compilation (in
translation phase 2), "splicing physical source lines to form logical
source lines". Since the edk2 coding style requires "//" comments for such
documentation, a trailing backslash would splice the next physical line
into the "scope" of the comment. To prevent this, trailing backslashes are
defanged by appending underscores, which should be visually bearable.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Michael Kinney <michael.d.kinney@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15791 6f19259b-4bc3-4df7-8a09-765794883524
2014-08-12 07:29:04 +00:00
AppPkg Enable the build command override the .DSC file contents to enable debug output and specify which debug messages are displayed. An example: 2013-11-19 02:37:37 +00:00
ArmPkg ArmPkg/ArmSmcLib: Fixed SMC helper functions 2014-08-04 14:18:13 +00:00
ArmPlatformPkg ArmPlatformPkg/Bds: Signal EndOfDxe PI Event 2014-08-01 18:35:29 +00:00
BaseTools BaseTools: Add AArch64 ADR_PREL_LO21 and R_AARCH64_CONDBR19 2014-08-04 08:44:11 +00:00
BeagleBoardPkg ArmPlatformPkg: Removed the global ImageHandle when UefiBootServicesTableLib is included 2014-08-01 18:33:17 +00:00
Conf Adding top-level Conf directory for next generation of EDK II build infrastructure tools. 2007-06-20 19:33:23 +00:00
CryptoPkg Clean up code. 2014-08-07 07:56:31 +00:00
DuetPkg Fixed one code error, should use & instead of |. 2014-07-10 01:25:41 +00:00
EdkCompatibilityPkg Refine code to make it more safely. 2014-06-26 03:16:27 +00:00
EdkShellBinPkg New EdkShell binaries. 2014-01-10 04:57:57 +00:00
EdkShellPkg EdkShellPkg/ShellR64.patch: Adding missing files from the patch 2014-01-14 15:31:01 +00:00
EmbeddedPkg EmbeddedPkg: FDT Configuration Table GUID 2014-08-01 18:34:20 +00:00
EmulatorPkg EmulatorPkg/Mpservice: Add StateLock where missing 2014-07-31 15:45:27 +00:00
FatBinPkg New FatDxe binary. 2014-01-10 02:44:43 +00:00
IntelFrameworkModulePkg Fixed a bug in LegacyBiosDxe to allocate correct ranges of memory. 2014-08-12 05:19:34 +00:00
IntelFrameworkPkg Update IntelFrameworkPkg version: 0.92->0.93 2014-01-10 01:18:20 +00:00
IntelFspPkg Rollback file GUID change, because it is VTF file and GUID is predefined. 2014-08-08 02:15:41 +00:00
IntelFspWrapperPkg Rollback file GUID change, because it is VTF file and GUID is predefined. 2014-08-08 02:15:41 +00:00
MdeModulePkg MdeModulePkg PeiCore: The DEBUG message (for HeapOffset and StackOffset) should be placed after HeapOffset is got. 2014-08-12 01:41:25 +00:00
MdePkg MdePkg: introduce BaseOrderedCollectionRedBlackTreeLib library instance 2014-08-12 07:29:04 +00:00
NetworkPkg Update network stack code to use StrnCpy instead of StrCpy. 2014-08-08 00:41:14 +00:00
Nt32Pkg Fix build error with VS2013 toolchain for NT32 Package caused by function redefinition, use #if fix the error. 2014-07-28 07:36:46 +00:00
Omap35xxPkg ARM Packages: Fixed missing braces (the warning was disabled by GCC) 2014-06-20 18:24:51 +00:00
OptionRomPkg Fix wrong usage sizeof(SIZE). 2014-07-23 02:13:14 +00:00
OvmfPkg OvmfPkg/Csm/CsmSupportLib: fix "missing braces around initializer" 2014-07-31 15:44:52 +00:00
PcAtChipsetPkg PcAtChipsetPkg: Enable timer interrupt through I/O APIC 2014-06-20 07:18:08 +00:00
PerformancePkg Refine code to make it more safely. 2014-06-26 03:18:44 +00:00
SecurityPkg Correct StrnCat length calculation. 2014-08-12 03:31:47 +00:00
ShellBinPkg ShellBinPkg: Updated ARM and AArch64 EFI Shell binaries 2014-05-07 12:58:55 +00:00
ShellPkg ShellPkg: Refactor string manipulation in cp command 2014-08-07 20:02:40 +00:00
SourceLevelDebugPkg SourceLevelDebugPkg/DebugAgent: fix trivial typo. 2014-08-08 07:50:21 +00:00
StdLib StdLib/LibC/Stdio: fix "missing braces around initializer" 2014-08-11 22:00:01 +00:00
StdLibPrivateInternalFiles EADK (StdLib, AppPkg, StdLibPrivateInternalFiles): Update ReadMe.txt in all packages. 2013-10-24 23:14:10 +00:00
UefiCpuPkg 1. Save/restore ICR high 32bit value and check Delivery Status before sending IPI. It could be fix the interrupted issue between ICR high/low writes by SMI handler. 2014-07-11 02:36:56 +00:00
UnixPkg UnixPkg: Remove UnixPkg files (It is replaced by EmulatorPkg) 2013-07-29 21:09:55 +00:00
BuildNotes2.txt Update to new SVN URL in readme.txt 2013-06-08 05:26:39 +00:00
edksetup.bat Contributed-under: TianoCore Contribution Agreement 1.0 2014-06-18 09:01:33 +00:00
edksetup.sh edksetup.sh: Ensure that WORKSPACE points to the top of an edk2 checkout 2014-07-28 17:37:40 +00:00