[fpc-pascal] ANN: Generics.Collections 2.0

Maciej Izak hnb.code at gmail.com
Fri Mar 9 01:01:56 CET 2018


 I'm pleased to finally announce next release of rtl-generics aka
Generics.Collections 2.0

version for trunk available in trunk ;)
version for 3.0.4 available at :
https://github.com/maciej-izak/generics.collections

What is new:
* New collections:
    - TSortedList<T>
    - THashSet<T>
    - TAVLTreeMap<TKey, TValue>
    - TIndexedAVLTreeMap<TKey, TValue>
    - TAVLTree<T>
    - TIndexedAVLTree<T>
    - TSortedSet<T>
    - TSortedHashSet<T> (this one collection is especially interesting -
optimized mix of dictionary and AVL tree)
* New hash functions (the optimal hash function for collections is selected
depending on environment)
* Bug fixes
* Tests
* My favorite and related to my compiler stuff like management operators
(also related to all managed types) : new Ptr property for all collections.
How it works and what is the gain? Simple example:

====== code begin ======
type
  TIntfObject = class(TInterfacedObject, IUnknown)
  protected
    function _AddRef : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
    function _Release : longint;{$IFNDEF
WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
  end;

function TIntfObject._AddRef: longint; stdcall;
begin
  Writeln('_AddRef');
  Result := inherited;
end;

function TIntfObject._Release: longint; stdcall;
begin
  Result := inherited;
  Writeln('_Release');
end;

procedure Test;
var
  List: TList<IInterface>;
  item: IInterface;
  itemPtr: ^IInterface;
begin
  WriteLn('--- initialization ---');
  List := TList<IInterface>.Create;
  List.Add(TIntfObject.Create);
  List.Add(TIntfObject.Create);
  List.Add(TIntfObject.Create);
  WriteLn('--- ptr loop ---');
  for itemPtr in List.Ptr^ do
    { something };
  WriteLn('--- loop ---');
  for item in List do
    { something };
  WriteLn('--- finalization ---');
  List.Free;
end;

begin
  Test;
  WriteLn('--- end ---');
end.
====== code end ======

Output:

--- initialization ---
_AddRef
_AddRef
_AddRef
--- ptr loop ---
--- loop ---
_AddRef
_AddRef
_Release
_AddRef
_Release
--- finalization ---
_Release
_Release
_Release
_Release
--- end ---

by usage pointer as enumerator was possible to omit all _AddRef & _Release
calls. The optimization is highly visible for extensive usage of managed
types.

Acknowledgment / credits:

Thanks to Sphere 10 Software (http://sphere10.com) for sponsoring many new
types and major refactoring of entire library

Thanks to mORMot (http://synopse.info) project for the best implementations
of hashing functions like crc32c and xxHash32 :)

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180309/96264980/attachment-0001.html>


More information about the fpc-pascal mailing list