Collections 1.0

Last week I have finally got some free time on my hands to do something I was planning for a long time now: create a new package that will only provide a number of collections. What this means is that I took DeHL and stripped out everything that was not collection related; remodeled the classes to rely on Generics.Collections and Generics.Defaults standard units; and finished all the documentation.

What remained is a pure collection orientated package called (very unimaginatively)  Collections.  If you ever used DeHL’s collections you will most certainly recognize the code. But, while stripping out the bloat I was forced to re move some things that relied on that bloat:

  • No more reliance on IType/TType. Collections now use IComparer and IEqualityComparer provided by Generics.Defaults.
  • All associative collections use TPair now.
  • Because IType was designed to provide cleanup for the enclosed values in the collections some reworking was necessary to make collections more Delphi-like. You still get the OwnsObjects, OwnsKeys and OwnsValues properties on the object variants.
  • No more Op.Cast<> support. This Enex operation relied on TConverter which relied on IType and so on and so forth. Instead use a Op.Select with a casting predicate.
  • Using NativeInt instead of NativeUInt in some places. This was a menace for a lot of people.

Note that Collections is not base-class or interface compatible with Generics.Collections. I could not make the proper compatibility because of interface support.
So what would you expect in the package:

  • Full inline documentation. All APIs are properly documented. If you find any typos or errors please fill a bug!
  • Test cases for mostly everything provided.
  • A wide range of collections (much more than just stack, queue, list and dictionary).
  • Enumerable extensions.
  • Easy extensibility.
  • Based on NativeInt instead of Integer. Ready at interface level for 64bit support.

Warning: This is a 1.0 release. There may still be some problems. If you find any please fill in a bug report. If you feel that you can help and implement something that is not included in the package feel free to contact me!

8 Responses to 'Collections 1.0'

  1. Linas says:

    Looks very promising!

  2. Very nice. Do you have any plans to implement an Enex-style thread-communication queue like the new TThreadedQueue from XE?

    Also, wouldn’t it be possible to implement an Op.Cast that calls Op.Select internally, to make porting easier?

  3. alex says:

    @Mason Wheeler
    If anyone’s going to help me I want to add parallel extensions. I don’t have time to do it myself though….

    Implementing cast is a really big task. You need a lot of conversion code. BTW, internally Cast was a Select with a conversion anon procedure. But the big bulk of work is not left in DeHL.

    You can always define a function like:

    ConvertIntToStr(const AInt: Integer): string;
    begin
    Exit(IntToStr(AInt));
    end;

    and then call select like

    StrList := IntList.Op.Select(ConvertIntToStr);

  4. Stefan says:

    Very nice. I always wanted to use the DeHL for the collections and enex but it was to much bloat for me.
    Now if the package only would be compilable.
    I tried in Delphi XE ([DCC Fatal Error] Collections.Base.pas(5827): F2084 Internal Error: AV22223FF9-R00000000-0) and in Delphi 2010 ([DCC Error] Collections.Base.pas(6611): E2003 Undeclared Identifier: ‘EArgumentNilException’).

  5. Alex, if you’re looking to implement parallel work, try talking with Primoz Gabrijelcic. A library that unifies Enex and OTL would be *very* nice!

  6. alex says:

    @Stefan
    Investigating … though it’s a real pain since the compiler often fails at different points…

    @Mason Wheeler
    I though of using OTL’s functionality to power my parallel work. Will try it out when I have time.

  7. Tommi Prami says:

    btw… What is this Enex-thingy people talked earlier???

Leave a Reply to Linas Cancel reply

Your email address will not be published.