<div dir="ltr"><div>Hi Free Pascal community!</div><div><br></div><div>I'm pleased to announce the generic library, compatible with Delphi Generics.Collections (almost ;) ).</div><div><br></div><div>Homepage</div><div>
<br></div><div><a href="https://code.google.com/p/fpc-generics-collections/">https://code.google.com/p/fpc-generics-collections/</a></div><div><br></div><div>SVN</div><div><br></div><div><a href="http://fpc-generics-collections.googlecode.com/svn/trunk/">http://fpc-generics-collections.googlecode.com/svn/trunk/</a></div>
<div><br></div><div><br></div><div>=== modules ===</div><div><br></div><div> Generics.Defaults</div><div> Generics.Collections</div><div> Generics.Helpers</div><div> Generics.Hashes</div><div><br></div><div>=== compatible classes ===</div>
<div><br></div><div> TEnumerator<T></div><div> TEnumerable<T></div><div> TList<T></div><div> TQueue<T></div><div> TStack<T></div><div> TDictionary<TKey, TValue></div><div> TObjectList<T: TObject></div>
<div> TObjectStack<T: TObject></div><div> TObjectDictionary<TKey, TValue></div><div><br></div><div>=== renamed (because compiler limations/bug) ===</div><div><br></div><div> TArrayHelper<T> instead of TArray<T></div>
<div><br></div><div>=== additional classes ===</div><div> ************</div><div> TDictionary<TKey, TValue, TProbeSequence, THash, THashFactory></div><div> TObjectDictionary<TKey, TValue, TProbeSequence, THash, THashFactory></div>
<div><br></div><div> TKey - key, TValue - value, THashFactory - hash factory :)</div><div> TProbeSequence - TProbeSequence is special record for open addresing. To choose from a predefined:</div><div> TLinearProbing, TQuadraticProbing, TDoubleHashing,</div>
<div> TFastLinearProbing, TFastQuadraticProbing, TFastDoubleHashing (fast version is without "mod")</div><div> more info at <a href="http://en.wikipedia.org/wiki/Open_addressing">http://en.wikipedia.org/wiki/Open_addressing</a></div>
<div> THash - type for hash (to reduce size of dictionary - can be UInt8, UInt16, UInt32 etc.)</div><div><br></div><div> For example, Delphi TDictionary version in this library is defined as:</div><div> TDictionary<TKey, TValue> = class(TDictionary<TKey, TValue, TFastLinearProbing, UInt32, TDelphiHashFactory>);</div>
<div> ************</div><div> TDictionaryList<TKey, TValue, TIndex, THash, THashFactory></div><div> class, that combines a TList and TDictionary</div><div><br></div><div> TKey - key, TValue - value, THashFactory - hash factory :)</div>
<div> TIndex - type for index (to reduce size of dictionary - can be UInt8, UInt16, UInt32 etc.)</div><div> THash - type for hash (to reduce size of dictionary - can be UInt8, UInt16, UInt32 etc.)</div><div> ************</div>
<div> Similar to TList, TDictionary and TDictionaryList, but uses normal operators instead of IEqualityComparer.</div><div><br></div><div> TFastList</div><div> TFastDictionary</div><div> TFastDictionaryList</div><div>
************</div><div> TFastArrayHelper<T> - similar rules as above</div><div><br></div><div>=== not implemented ===</div><div><br></div><div> TThreadedQueue<T></div><div><br></div><div>=== FAQ ===</div><div>
<br></div><div>1. How to use record as Key or Value in dictionary?</div><div><br></div><div> You need to wait for some compiler magic ( system functions GetReferenceToValue and GetValueSize described bolow)</div><div> or add two methods to record:</div>
<div><br></div><div> TRecord = record</div><div> (* ... *)</div><div> function GetValueSize: Integer; inline;</div><div> function GetReferenceToValue: Pointer; inline;</div><div> end;</div><div><br></div>
<div>2. How to use Pointer or some custom type as Key or Value in dictionary?</div><div><br></div><div> You need to wait for some compiler magic ( system functions GetReferenceToValue and GetValueSize described bolow)</div>
<div> or use TValueHelper:</div><div><br></div><div> uses</div><div> Generics.Collections, Generics.Helpers;</div><div> (* ... *)</div><div> type</div><div> TValueHelperPointer = TValueHelper<Pointer>;</div>
<div> var</div><div> d: TDictionary<TValueHelperPointer, string>;</div><div> begin</div><div> (* ... *)</div><div> d.Add(nil, 'foo');</div><div><br></div><div>=== TODO ===</div>
<div><br></div><div>Comparer from Generics.Defaults can be optimized.</div><div><br></div><div>I have no knowledge of FPC compiler design, so i need a little help...</div><div><br></div><div>First thing : To finish my work I need critical compiler magic functions/feature. At first look mayby there is no sense for this functions</div>
<div>but during work on Generic library it's necessary:</div><div><br></div><div> 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 </div>
<div><br></div><div>measured by human/programmer</div><div> function GetValueSize(Value: T): Integer; // for string types return Length(s), for Int32 returs 4 etc.</div><div><br></div><div>This functions should be implemented as operators (like Inc, Dec operators).</div>
<div><br></div><div>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:</div><div><br></div><div> type MyStr = type string;</div>
<div> type MyInt = type Int32;</div><div><br></div><div>Second thing: Bugs. Look at Critical - fix is needed to perform compatibility with Delphi and proper work.</div><div><br></div><div> <a href="http://bugs.freepascal.org/view.php?id=24283">http://bugs.freepascal.org/view.php?id=24283</a> (CRITICAL! Very Important!)</div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24282">http://bugs.freepascal.org/view.php?id=24282</a> (CRITICAL! Very Important!)</div><div> <a href="http://bugs.freepascal.org/view.php?id=24254">http://bugs.freepascal.org/view.php?id=24254</a> (CRITICAL! for TArray.Sort<T>)</div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24287">http://bugs.freepascal.org/view.php?id=24287</a> (Very Important!)</div><div> <a href="http://bugs.freepascal.org/view.php?id=24072">http://bugs.freepascal.org/view.php?id=24072</a> (Very Important!)</div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24097">http://bugs.freepascal.org/view.php?id=24097</a> (Important!)</div><div> <a href="http://bugs.freepascal.org/view.php?id=24064">http://bugs.freepascal.org/view.php?id=24064</a> (Important!)</div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24071">http://bugs.freepascal.org/view.php?id=24071</a> (Important!)</div><div> <a href="http://bugs.freepascal.org/view.php?id=24285">http://bugs.freepascal.org/view.php?id=24285</a> (Important!)</div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24286">http://bugs.freepascal.org/view.php?id=24286</a> similar to 24285</div><div> <a href="http://bugs.freepascal.org/view.php?id=24458">http://bugs.freepascal.org/view.php?id=24458</a></div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24098">http://bugs.freepascal.org/view.php?id=24098</a> (Frustrating)</div><div> <a href="http://bugs.freepascal.org/view.php?id=24073">http://bugs.freepascal.org/view.php?id=24073</a></div>
<div> <a href="http://bugs.freepascal.org/view.php?id=24463">http://bugs.freepascal.org/view.php?id=24463</a></div><div><br></div><div><br></div>-- <br><span style="font-family:arial,sans-serif;font-size:13px">Regards,</span><br>
HNB</div>