Yes Egan, TSet sounds interesting. What a pity is not documented anywhere in FPC space.
I did find this http://history.ioinformatics.org/conf/c6_boza.pdf - looks like a 2012 conference talk. Enough to spark a bit of interest.
....There's also this paper by the same author.
Ah, thats heaps more informative. If I can make sense of it, and find some time, I will write something, initially as a wiki page, and then if people like yourself consider it not comple rubbish, as a doc patch.
... So, is TSet really just capapable of managing longints (or integer, shortints) ? Thats all ? ...
IIRC, TSet is built on top of the LLRbTree implementation, which is always slower than AvlTree. And yes, TSet is a Set, not a SortedList.Also, it is a rather old library and in my opinion too STL-centric.
...In essence a sorted list with no duplcates allowed is a "set"....
You can consider this version:Code: Pascal [Select][+][-]program TSetDemo;{$mode objfpc}{$H+}{$modeswitch advancedrecords}uses SysUtils, gvector, gset, gutil; type PNote = ^TNote; TNote = record Title : string; ID : string; end; TLess = record class function c(L, R: PNote): Boolean; static; end; class function TLess.c(L, R: PNote): Boolean;begin Result := L^.ID < R^.ID;end; type TNoteSet = specialize TSet<PNote, TLess>; procedure TestTSet;var S: TNoteSet; it: TNoteSet.TIterator; p: PNote;const Notes: array of TNote = ( (Title: 'Title1'; ID: '111'), (Title: 'Title2'; ID: '222'), (Title: 'Title3'; ID: '333'), (Title: 'Title4'; ID: '444'));begin S := TNoteSet.Create; S.Insert(@Notes[3]); S.Insert(@Notes[2]); S.Insert(@Notes[1]); S.Insert(@Notes[0]); it := S.Min; repeat p := it.GetData; writeln('Title: ', p^.Title, ', ID: ', p^.ID); until not it.Next; it.Free; S.free;end; begin TestTSet;end.
...If iterating through it, one can also use the enumerator: