[fpc-devel] Library announcement: Generics.Collections

Maciej Izak hnb.code at gmail.com
Wed May 22 21:44:56 CEST 2013


Hi Free Pascal community!

I'm pleased to announce the generic library, compatible with Delphi
Generics.Collections (almost ;) ).

Homepage

https://code.google.com/p/fpc-generics-collections/

SVN

http://fpc-generics-collections.googlecode.com/svn/trunk/


=== modules ===

  Generics.Defaults
  Generics.Collections
  Generics.Helpers
  Generics.Hashes

=== compatible classes ===

  TEnumerator<T>
  TEnumerable<T>
  TList<T>
  TQueue<T>
  TStack<T>
  TDictionary<TKey, TValue>
  TObjectList<T: TObject>
  TObjectStack<T: TObject>
  TObjectDictionary<TKey, TValue>

=== renamed (because compiler limations/bug) ===

  TArrayHelper<T> instead of TArray<T>

=== additional classes ===
  ************
  TDictionary<TKey, TValue, TProbeSequence, THash, THashFactory>
  TObjectDictionary<TKey, TValue, TProbeSequence, THash, THashFactory>

    TKey - key, TValue - value, THashFactory - hash factory :)
    TProbeSequence - TProbeSequence is special record for open addresing.
To choose from a predefined:
      TLinearProbing, TQuadraticProbing, TDoubleHashing,
      TFastLinearProbing, TFastQuadraticProbing, TFastDoubleHashing (fast
version is without "mod")
      more info at http://en.wikipedia.org/wiki/Open_addressing
    THash - type for hash (to reduce size of dictionary - can be UInt8,
UInt16, UInt32 etc.)

    For example, Delphi TDictionary version in this library is defined as:
    TDictionary<TKey, TValue> = class(TDictionary<TKey, TValue,
TFastLinearProbing, UInt32, TDelphiHashFactory>);
  ************
  TDictionaryList<TKey, TValue, TIndex, THash, THashFactory>
    class, that combines a TList and TDictionary

    TKey - key, TValue - value, THashFactory - hash factory :)
    TIndex - type for index (to reduce size of dictionary - can be UInt8,
UInt16, UInt32 etc.)
    THash - type for hash (to reduce size of dictionary - can be UInt8,
UInt16, UInt32 etc.)
  ************
  Similar to TList, TDictionary and TDictionaryList, but uses normal
operators instead of IEqualityComparer.

  TFastList
  TFastDictionary
  TFastDictionaryList
  ************
  TFastArrayHelper<T> - similar rules as above

=== not implemented ===

  TThreadedQueue<T>

=== FAQ ===

1. How to use record as Key or Value in dictionary?

  You need to wait for some compiler magic ( system functions
GetReferenceToValue and GetValueSize described bolow)
  or add two methods to record:

    TRecord = record
      (* ... *)
      function GetValueSize: Integer; inline;
      function GetReferenceToValue: Pointer; inline;
    end;

2. How to use Pointer or some custom type as Key or Value in dictionary?

  You need to wait for some compiler magic ( system functions
GetReferenceToValue and GetValueSize described bolow)
  or use TValueHelper:

    uses
      Generics.Collections, Generics.Helpers;
    (* ... *)
      type
        TValueHelperPointer = TValueHelper<Pointer>;
      var
        d: TDictionary<TValueHelperPointer, string>;
      begin
        (* ... *)
        d.Add(nil, 'foo');

=== TODO ===

Comparer from Generics.Defaults can be optimized.

I have no knowledge of FPC compiler design, so i need a little help...

First thing : To finish my work I need critical compiler magic
functions/feature. At first look mayby there is no sense for this functions
but during work on Generic library it's necessary:

  function GetReferenceToValue(Value: T): Pointer; // for string types
return @s[1] or nil for empty string for Int32 return @i etc. returns a
reference to the value, as

measured by human/programmer
  function GetValueSize(Value: T): Integer; // for string types return
Length(s), for Int32 returs 4 etc.

This functions should be implemented as operators (like Inc, Dec operators).

There is half-workaround/cripled solution as record/type helpers (module
Generics.Helpers). Don't work for custom strings, and for custom "basic"
types like:

  type MyStr = type string;
  type MyInt = type Int32;

Second thing: Bugs. Look at Critical - fix is needed to perform
compatibility with Delphi and proper work.

      http://bugs.freepascal.org/view.php?id=24283 (CRITICAL! Very
Important!)
      http://bugs.freepascal.org/view.php?id=24282 (CRITICAL! Very
Important!)
      http://bugs.freepascal.org/view.php?id=24254 (CRITICAL! for
TArray.Sort<T>)
      http://bugs.freepascal.org/view.php?id=24287 (Very Important!)
      http://bugs.freepascal.org/view.php?id=24072 (Very Important!)
      http://bugs.freepascal.org/view.php?id=24097 (Important!)
      http://bugs.freepascal.org/view.php?id=24064 (Important!)
      http://bugs.freepascal.org/view.php?id=24071 (Important!)
      http://bugs.freepascal.org/view.php?id=24285 (Important!)
      http://bugs.freepascal.org/view.php?id=24286 similar to 24285
      http://bugs.freepascal.org/view.php?id=24458
      http://bugs.freepascal.org/view.php?id=24098 (Frustrating)
      http://bugs.freepascal.org/view.php?id=24073
      http://bugs.freepascal.org/view.php?id=24463


-- 
Regards,
HNB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20130522/e8aa49f3/attachment.html>


More information about the fpc-devel mailing list