Catalog · How the catalog works
Rapid.Generics.v2
- ★ 27 on GitHub
Anyone may press Interesting, signed in or not. It helps others find this project.
README
Rapid.Generics.v2
What is this?
This is a modified fork of Rapid.Generics with improvements and fixes.
Github repository: https://github.com/Alexandre-Atozed/Rapid.Generics.v2
Why v2?
The original library could not be used in a real application due to several issues:
- It contained a few bugs
- No unit tests
- The author doesn't seem to maintain it
What is different in v2?
✅ Unit Tests
- 700+ new unit tests added for
TArray<>,TDictionary<>,TObjectDictionary<>,TList<>,TObjectList<>,TQueue<>,TObjectQueue<>,TStack<>,TObjectStack<>andTHashSet<>classes - All tests run memory leak free. Tested with FastMM4 in FullDebugMode
- Most tests can also use standard System.Generics.Collections data structures, just disabling a directive (undefine TEST_RAPIDGENERICS), making it easy to compare unexpected behavior (except SortDescending methods which have no counterpart in System.Generics.Collections)
- New tests added to the performance test (benchmark) application
🔧 General Changes
{$DEFINE HAS_INLINE}allows enabling/disablinginlinefor easier debugging- Exception handling refactored using functions similar to Delphi 12 RTL with better error messages
- Local variables renamed for clarity (e.g., distinguishing them from properties like
Count) - Unused code removed
- Warnings silenced (most via
{$WARNINGS OFF}when the compiler cannot detect variable initialization inside acasestatement) - Fixed AV during interface clean up (Creating dictionaries/lists with interfaces would cause AV when destroying)
- Fixed destruction of objects owned by TObjectDictionary<>, TObjectList<>, TObjectStack<>, TObjectQueue<> when a descendant class overrides Notify() method
- Fixed TObjectStack Pop method
- Fixed many bugs when using records as keys in dictionaries
- THashSet implementation for all supported compilers
📌 TArray Improvements
- Implemented missing methods:
IndexOf<T>andContains<T> - Fixed
TArray.Copy<T>for certain sizes of T - Fixed
TArray.InternalSearchwhen the array is empty - New comprehensive unit test suite for TArray<>
- Sorting:
- Ascending (most common) sorting uses QuickSort and InsertionSort for small partitions (configured by INSERTION_SORT_THRESHOLD, default 16) for most data types
- Use of InsertionSort for small partitions increase the performance around 30-40% for large data sets, and up to 500% for small data sets, compared to pure QuickSort
- Descending sorting uses a pure QuickSort algorithm. Plans to also extend to use InsertionSort
- New: Sorting uses Median of three pivot selection
- QuickSort corner cases fixed, preventing infinite loops due to improper index bounds during pivot selection
- Removed original
RadixSortandInsertionroutines (both failed basic unit tests). - Fixed
SortDescending()methods - Fixed SetCapacity() (zero-initializing allocated memory)
📌 TDictionary<> Improvements
- Implemented missing method:
TryAdd
📌 TObjectDictionary<> Improvements
- Fixed memory leaks when overriding KeyNotify()/ValueNotify() in descendant classes (doOwnsKeys or doOwnsValues)
📌 TList<> Improvements
- Implemented missing methods:
ExtractAt()andIsEmpty() - Fixed
TList<>.InternalDeletemethod for managed types, which fixed memory leaks when adding records with managed types to lists - Sorting: See TArray sorting
📌 Compatibility
This has been tested with:
- Delphi 10, 10.1, 10.2, 10.3, 10.4, 11, 12 and 13 (x86 and x64)
- Not tested with any version of Lazarus/FPC yet
- Other compiler versions will be tested in the near future
📌 Dependencies
- No external dependencies
- Unit test project requires DUnitX framework. (Included in 3rdParty folder)
- Unit test memory leak check requires FastMM4 (also included in 3rdParty folder)
📌 How to Use
- Include
Rapid.Generics.pasin your project. - Replace
System.Generics.CollectionsandSystem.Generics.DefaultswithRapid.Genericsin yourusessections.
📌 TRapidDictionary/TRapidObjectDictionary
Rapid "inline" TDictionary / TObjectDictionary equivalents with default hash codes and comparers.
Code formatting
The Code is GExperts Code Formatter by GExperts.

