audk/MdePkg/Library
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
..
BaseCacheMaintenanceLib Add type cast for better coding style. 2014-08-07 08:32:54 +00:00
BaseCpuLib MdePkg/BaseCpuLib: Added ARM Aarch64 architecture support 2013-07-29 09:56:36 +00:00
BaseDebugLibNull Update DebugLib to provide support for "err" command in the EFI Shell to adjust the filter mask for DEBUG() messages. The "err" command provide the ability to adjust this filter mask at a global level through an EFI Variable and at the module level through a the Debug Mask Protocol. In order to support the degree of flexibility, the DebugLib needs to use library to abstract the get/set operations to the filter mask. 2011-03-10 22:12:34 +00:00
BaseDebugLibSerialPort Update DebugLib to provide support for "err" command in the EFI Shell to adjust the filter mask for DEBUG() messages. The "err" command provide the ability to adjust this filter mask at a global level through an EFI Variable and at the module level through a the Debug Mask Protocol. In order to support the degree of flexibility, the DebugLib needs to use library to abstract the get/set operations to the filter mask. 2011-03-10 22:12:34 +00:00
BaseDebugPrintErrorLevelLib Refine code to follow coding style. 2011-03-15 00:53:52 +00:00
BaseExtractGuidedSectionLib Build the registered guid HOB and SystemTable to record the GUID itself in PeiExtractGuidedSectionLib and DxeExtractGuidedSectionLib, and also state the restriction in BaseExtractGuidedSectionLib. 2012-11-08 01:12:56 +00:00
BaseIoLibIntrinsic MdePkg: Added ARM Aarch64 architecture support 2013-07-29 09:52:18 +00:00
BaseLib MdePkg: Fix Clang build failure 2014-08-11 07:05:49 +00:00
BaseMemoryLib Fix InternalMemScanMem* functions so that they return the pointer to the matched object, as specified, instead of the following object. 2011-01-07 23:00:16 +00:00
BaseMemoryLibMmx MdePkg: Fix Clang build failure 2014-08-11 07:05:49 +00:00
BaseMemoryLibOptDxe Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BaseMemoryLibOptPei MdePkg: Fix Clang build failure 2014-08-11 07:05:49 +00:00
BaseMemoryLibRepStr MdePkg: Fix Clang build failure 2014-08-11 07:05:49 +00:00
BaseMemoryLibSse2 MdePkg: Fix Clang build failure 2014-08-11 07:05:49 +00:00
BaseOrderedCollectionRedBlackTreeLib MdePkg: introduce BaseOrderedCollectionRedBlackTreeLib library instance 2014-08-12 07:29:04 +00:00
BasePalLibNull Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BasePcdLibNull MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported, align the behavior of LibPcdSetPtr with LibPcdSetN to handle error status returned. 2014-01-07 09:28:33 +00:00
BasePciCf8Lib Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BasePciExpressLib Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BasePciLibCf8 Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BasePciLibPciExpress Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BasePeCoffExtraActionLibNull Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BasePeCoffGetEntryPointLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BasePeCoffLib Support load 64 bit image from 32 bit core. 2014-03-25 05:04:21 +00:00
BasePerformanceLibNull Add new extension PerformanceLib APIs to store ID info. 2012-04-24 08:42:24 +00:00
BasePostCodeLibDebug Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BasePostCodeLibPort80 Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BasePrintLib Add type cast for better coding style. 2014-08-07 08:32:54 +00:00
BaseReportStatusCodeLibNull Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
BaseS3BootScriptLibNull Add comment for S3BootScriptSaveMemPoll API, since it does not match PI specification. 2014-03-01 12:25:31 +00:00
BaseS3IoLib Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BaseS3PciLib Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
BaseS3SmbusLib MdePkg: Add S3 library interfaces and base implementations 2011-08-29 22:16:28 +00:00
BaseS3StallLib MdePkg: Add S3 library interfaces and base implementations 2011-08-29 22:16:28 +00:00
BaseSerialPortLibNull Fix issue when BaseDebugLibSerialPort is combined with BaseSerialPortLibNull. It will ASSERT() due to the recent addition of a CONSTRUCTOR to BaseDebugLibSerialPort that calls SerialPortInitialize(). 2010-12-30 01:07:39 +00:00
BaseSmbusLibNull Add BaseSmbusLibNull instance for SmbusLib. Add check in BootScriptExecutorDxe driver for the return status of S3BootScriptExecute(). 2013-11-08 02:59:05 +00:00
BaseSynchronizationLib MdePkg/BaseSynchronizationLib: Added ARM Aarch64 architecture support 2013-07-29 09:57:43 +00:00
BaseTimerLibNullTemplate Add new API GetTimeInNanoSecond() to TimerLib to convert elapsed ticks to time in unit of nanoseconds. 2011-08-25 05:59:17 +00:00
BaseUefiDecompressLib Refine code to make it more safely. 2014-06-26 03:17:59 +00:00
DxeCoreEntryPoint Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
DxeCoreHobLib Update HobLib and Hob Service to avoid data over flow. 2012-07-17 01:50:52 +00:00
DxeExtendedSalLib Add Missing invocations to VA_END() for VA_START(). 2012-02-01 06:06:08 +00:00
DxeExtractGuidedSectionLib Build the registered guid HOB and SystemTable to record the GUID itself in PeiExtractGuidedSectionLib and DxeExtractGuidedSectionLib, and also state the restriction in BaseExtractGuidedSectionLib. 2012-11-08 01:12:56 +00:00
DxeHobLib Update HobLib and Hob Service to avoid data over flow. 2012-07-17 01:50:52 +00:00
DxeIoLibCpuIo2 Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
DxeIoLibEsal Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
DxePalLibEsal For libraries that have multiple module types support, just define a [Depex] section for specified module types that are permitted to have a [Depex] section. 2011-07-27 08:54:57 +00:00
DxePcdLib MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported, align the behavior of LibPcdSetPtr with LibPcdSetN to handle error status returned. 2014-01-07 09:28:33 +00:00
DxePciLibEsal Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
DxePciSegmentLibEsal Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
DxeRuntimeExtendedSalLib Add Missing invocations to VA_END() for VA_START(). 2012-02-01 06:06:08 +00:00
DxeRuntimePciExpressLib Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
DxeSalLibEsal Initialize data before using it 2011-06-21 02:24:46 +00:00
DxeServicesLib Correct function comments on DxeServicesLib GetFileBufferByFilePath API. 2012-04-17 09:42:44 +00:00
DxeServicesTableLib Add the missing supported module type in MdePkg DxeServicesTableLib instance. 2011-11-23 02:00:05 +00:00
DxeSmbusLib For libraries that have multiple module types support, just define a [Depex] section for specified module types that are permitted to have a [Depex] section. 2011-07-27 08:54:57 +00:00
DxeTimerLibEsal MdePkg: Add missing implementation of GetTimeInNanoSecond() to TimerLib library instance DxeTimerLibEsal. 2011-09-08 01:34:24 +00:00
PeiCoreEntryPoint Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
PeiDxePostCodeLibReportStatusCode Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
PeiExtractGuidedSectionLib Build the registered guid HOB and SystemTable to record the GUID itself in PeiExtractGuidedSectionLib and DxeExtractGuidedSectionLib, and also state the restriction in BaseExtractGuidedSectionLib. 2012-11-08 01:12:56 +00:00
PeiHobLib MdePkg PeiHobLib: Initialize Owner field of Resource HOB to 0 rather than random value. 2014-07-14 01:38:19 +00:00
PeiIoLibCpuIo Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
PeiMemoryAllocationLib Update MemoryAllocationLib.AllocateAlignedPages API comments for memory overflow ASSERT case. 2013-12-31 07:19:09 +00:00
PeiMemoryLib Sync bug fix in Edk r10821 to PeiMemoryLib and UefiMemoryLib instances. 2010-08-26 00:50:37 +00:00
PeiPalLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
PeiPcdLib MdePkg PcdLib: Except for SizeOfBuffer is greater than the maximum size supported, align the behavior of LibPcdSetPtr with LibPcdSetN to handle error status returned. 2014-01-07 09:28:33 +00:00
PeiPciLibPciCfg2 Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
PeiPciSegmentLibPciCfg2 Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
PeiResourcePublicationLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
PeiServicesLib MdePkg PeiServicesLib: Refine the code to avoid error report. 2013-10-14 09:39:25 +00:00
PeiServicesTablePointerLib Add VOID MigratePeiServicesTablePointer() to fix'Deprecated declaration'. 2014-01-17 06:06:30 +00:00
PeiServicesTablePointerLibIdt Add VOID MigratePeiServicesTablePointer() to fix'Deprecated declaration'. 2014-01-17 06:06:30 +00:00
PeiServicesTablePointerLibKr7 Add VOID MigratePeiServicesTablePointer() to fix'Deprecated declaration'. 2014-01-17 06:06:30 +00:00
PeiSmbusLibSmbus2Ppi For libraries that have multiple module types support, just define a [Depex] section for specified module types that are permitted to have a [Depex] section. 2011-07-27 08:54:57 +00:00
PeimEntryPoint Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
SecPeiDxeTimerLibCpu Removed the assumption on APIC timer initial Count is all 1s and updated it to handle the long delay that timer initial count. 2013-08-27 07:29:14 +00:00
SmmIoLibSmmCpuIo2 Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
SmmLibNull Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
SmmMemoryAllocationLib Update MemoryAllocationLib.AllocateAlignedPages API comments for memory overflow ASSERT case. 2013-12-31 07:19:09 +00:00
SmmPciLibPciRootBridgeIo Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
SmmPeriodicSmiLib Simplify the SmmPeriodicSmiLib to call AllocatePool() for every entry in the SMI periodic handler list. 2011-08-19 01:37:47 +00:00
SmmServicesTableLib A minor change for the format of usage align with spec. 2011-02-21 08:07:22 +00:00
UefiApplicationEntryPoint Update UefiDriverEntryPoint library by adding BaseLib library class required by AutoGen code. 2010-10-18 09:59:55 +00:00
UefiBootServicesTableLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
UefiDebugLibConOut Should pass in bytes of string buffer to UnicodeSPrint() rather than Unicode string length. 2012-08-29 09:23:34 +00:00
UefiDebugLibStdErr Should pass in bytes of string buffer to UnicodeSPrint() rather than Unicode string length. 2012-08-29 09:23:34 +00:00
UefiDevicePathLib Remove the assertion which may cause IsDevicePathValid() hang in DEBUG build. 2014-05-22 07:34:35 +00:00
UefiDevicePathLibDevicePathProtocol Add 4 APIs to DevicePathLib: ConvertDeviceNodeToText, ConvertDevicePathToText, ConvertTextToDeviceNode and ConvertTextToDevicePath. 2013-07-26 03:00:21 +00:00
UefiDriverEntryPoint Update the description of Loaded Image Protocol Unload function to follow the UEFI2.3.1 Spec. 2011-04-19 06:33:25 +00:00
UefiLib This patch uses dummy routine as NotifyFunction to make sure those 2 APIs provided from library can create event as expected when the caller does not feed in a NotifyFunction. Also, typo is corrected. 2013-09-05 06:12:04 +00:00
UefiMemoryAllocationLib Update MemoryAllocationLib.AllocateAlignedPages API comments for memory overflow ASSERT case. 2013-12-31 07:19:09 +00:00
UefiMemoryLib Sync bug fix in Edk r10821 to PeiMemoryLib and UefiMemoryLib instances. 2010-08-26 00:50:37 +00:00
UefiPalLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
UefiPciLibPciRootBridgeIo Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
UefiPciSegmentLibPciRootBridgeIo Add ASSERT() for BitField operations to make sure the input value is valid. 2012-12-25 02:25:50 +00:00
UefiRuntimeLib Update MODULE_TYPE to be DXE_RUNTIME_DRIVER 2010-09-14 17:02:46 +00:00
UefiRuntimeServicesTableLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-25 21:56:02 +00:00
UefiSalLib Minor grammatical work--mostly adding periods. Items with ONLY period added did not have the heading date changed, but Items with content changes had heading copyright dates updated. Sending separately a list of files missing Doxygen @param and @return information. (PENDING) 2010-06-30 00:13:25 +00:00
UefiScsiLib MdePkg/UefiScsiLib: Wrong function parameter comments in UefiScsiLib. It should be the number of transferred blocks rather than block size. 2014-04-30 03:38:05 +00:00
UefiUsbLib Minor refinement on source code. 2010-08-14 07:25:20 +00:00