Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-12

Lazarus support for Sorting is completely inadequate.

30 messages · 13 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Avishai

Lazarus support for Sorting is completely inadequate. You can not sort a list of strings without knowing the language of the list. This should be a simple process. I would like to try to improve this, but I will need some help from the Lazarus community.

It appears that each Control that has a List has its own separate Sort routine and each is different. I would think that there would be a single Sort routine and could be called by each control.

This could be a starting point that could be expanded to include other Languages and Sort Methods, but it is only a suggestion.

{===== Sorting =====}

const
  SortAscending: Boolean = True;
function SortHebrew(List: TStringList; Index1, Index2: Integer):
Integer;  {Hebrew}
begin
  Result:= UTF8CompareStr(List[Index1],List[Index2]);
  if not SortAscending then
    Result:= -Result;
end;
function SortPortuguese(List: TStringList; Index1, Index2: Integer):
Integer;  {Portuguese}
begin
  Result:= WideCompareText(UTF8Decode(List[Index1]),UTF8Decode(List[Index2]));
  if not SortAscending then
    Result:= -Result;
end;

{===== Numeric Sort =====}

function DoNumSort(List: TStringList; Index1, Index2: Integer): Integer;
var
  N1, N2: Double;
begin
  N1:= StrToFloatDef(List[Index1],0);
  N2:= StrToFloatDef(List[Index2],0);
  if N1 < N2 then
    result := -1
  else if N1 > N2 then
    result := 1
  else
  result := 0;
  if not SortAscending then
    Result:= -Result;
end;
procedure SortNumeric(Items: TStrings);
var
  Alist: TStringList;
begin
  Alist:= TStringList.Create;
    with Items do begin
      Alist.CommaText:= CommaText;
      Alist.CustomSort(@DoNumSort);
      CommaText:= Alist.commaText;
    end;
  FreeAndNil(Alist);
end;

{ This is the User Sort main routine }
{ Example Call: SortStringList(Memo1.Lines, HebrewSort); } { Example Call: SortStringList(ListBox1.Items, HebrewSort); } { Example Call: SortStringList(ComboBox1.Items, HebrewSort); }

function SortStringList(AStringList: TStrings; SortStyle: Integer): Integer;
var
  SortList: TStringList;
begin
  SortList:= TStringList.Create;
    SortList.CaseSensitive:= True;
    SortList.Assign(AStringList);
	{ Sort according to Language }
    case SortStyle of
      EnglishSort: SortList.Sort;
      HebrewSort: SortList.CustomSort(@SortHebrew);
      PortugueseSort: SortList.CustomSort(@SortPortuguese);
      NumericSort: SortList.CustomSort(@DoNumSort);
	  { need input from Lazarus community for other Sort Methods }
    end;
    AStringList.Assign(SortList);
  FreeAndNil(SortList);
end;
Shalom, Avishai ????? ????

Reply by email

Mattias Gaertner
to Avishai
Show quoted text 8 lines
Lazarus support for Sorting is completely inadequate. You can not sort a list of strings without knowing the language of the list. This should be a simple process. I would like to try to improve this, but I will need some help from the Lazarus community. It appears that each Control that has a List has its own separate Sort routine and each is different. I would think that there would be a single Sort routine and could be called by each control.

I'm not sure if I can follow you here. Maybe this helps:

A string list can be sorted with a single line of code or you can write your own compare function. The default sort algorithm is quicksort and there are other available too.
So support for "Sorting" is good.

Maybe you are missing some "String compare functions"?

There are many basic compare functions in the RTL, FCL and LazUtils. For instance CompareStr, CompareText, AnsiCompareText, UTF8CompareStr, UTF8CompareText.
All these functions have their pros and cons.

Keep in mind that some human languages have multiple official compare functions and it gets even more difficult when mixing languages (unicode).

Show quoted text 78 lines
This could be a starting point that could be expanded to include other Languages and Sort Methods, but it is only a suggestion. {===== Sorting =====} const SortAscending: Boolean = True; function SortHebrew(List: TStringList; Index1, Index2: Integer): Integer; {Hebrew} begin Result:= UTF8CompareStr(List[Index1],List[Index2]); if not SortAscending then Result:= -Result; end; function SortPortuguese(List: TStringList; Index1, Index2: Integer): Integer; {Portuguese} begin Result:= WideCompareText(UTF8Decode(List[Index1]),UTF8Decode(List[Index2])); if not SortAscending then Result:= -Result; end; {===== Numeric Sort =====} function DoNumSort(List: TStringList; Index1, Index2: Integer): Integer; var N1, N2: Double; begin N1:= StrToFloatDef(List[Index1],0); N2:= StrToFloatDef(List[Index2],0); if N1 < N2 then result := -1 else if N1 > N2 then result := 1 else result := 0; if not SortAscending then Result:= -Result; end; procedure SortNumeric(Items: TStrings); var Alist: TStringList; begin Alist:= TStringList.Create; with Items do begin Alist.CommaText:= CommaText; Alist.CustomSort(@DoNumSort); CommaText:= Alist.commaText; end; FreeAndNil(Alist); end; { This is the User Sort main routine } { Example Call: SortStringList(Memo1.Lines, HebrewSort); } { Example Call: SortStringList(ListBox1.Items, HebrewSort); } { Example Call: SortStringList(ComboBox1.Items, HebrewSort); } function SortStringList(AStringList: TStrings; SortStyle: Integer): Integer; var SortList: TStringList; begin SortList:= TStringList.Create; SortList.CaseSensitive:= True; SortList.Assign(AStringList); { Sort according to Language } case SortStyle of EnglishSort: SortList.Sort; HebrewSort: SortList.CustomSort(@SortHebrew); PortugueseSort: SortList.CustomSort(@SortPortuguese); NumericSort: SortList.CustomSort(@DoNumSort); { need input from Lazarus community for other Sort Methods } end; AStringList.Assign(SortList); FreeAndNil(SortList); end;

Maybe you are searching for a unit with lots of string compare functions?

Mattias

Reply by email

Avishai
to Mattias Gaertner

The problem is that there is no way to know which sort algorithm to use for which language without a lot of experimenting. It took quite a bit of time for me to find one that worked for Hebrew.

But more than that, for globalization/localization the Language may not be known in advance.

An example:
Your app. is Globalized/Localized for String display Language. But you have a Sorted ListBox with Default Sort. The user selects Russian for his language. The app. knows the language, but the ListBox Sort is wrong.

There should be a central Sort routine that can decide which Sort method to use based on the Language.

I'm asking for help to achieve this. I have no idea what sort methods to use for non-Latin languages. Russian, Croatian, Greek... Once completed and tested, it could be made a part of Lazarus, or at the very least, some guide could be available to help others.

Apart from that, why have different sort methods for different controls that give different results? TListbox, TComboBox, TStringList, TStringGrid all give different results. And as far as I know, there is no Numeric Sort. Not hard to write, but why isn't it there?

So I don't agree that Lazarus has good sort support.

Mattias Gaertner wrote 121 lines
On Sat, 1 Dec 2012 16:43:34 +0200 Avishai wrote: > Lazarus support for Sorting is completely inadequate. You can not > sort a list of strings without knowing the language of the list. This > should be a simple process. I would like to try to improve this, but I > will need some help from the Lazarus community. > > It appears that each Control that has a List has its own separate Sort > routine and each is different. I would think that there would be a > single Sort routine and could be called by each control. I'm not sure if I can follow you here. Maybe this helps: A string list can be sorted with a single line of code or you can write your own compare function. The default sort algorithm is quicksort and there are other available too. So support for "Sorting" is good. Maybe you are missing some "String compare functions"? There are many basic compare functions in the RTL, FCL and LazUtils. For instance CompareStr, CompareText, AnsiCompareText, UTF8CompareStr, UTF8CompareText. All these functions have their pros and cons. Keep in mind that some human languages have multiple official compare functions and it gets even more difficult when mixing languages (unicode). > This could be a starting point that could be expanded to include other > Languages and Sort Methods, but it is only a suggestion. > > {===== Sorting =====} > > const > SortAscending: Boolean = True; > > function SortHebrew(List: TStringList; Index1, Index2: Integer): > Integer; {Hebrew} > begin > Result:= UTF8CompareStr(List[Index1],List[Index2]); > if not SortAscending then > Result:= -Result; > end; > > function SortPortuguese(List: TStringList; Index1, Index2: Integer): > Integer; {Portuguese} > begin > Result:= WideCompareText(UTF8Decode(List[Index1]),UTF8Decode(List[Index2])); > if not SortAscending then > Result:= -Result; > end; > > {===== Numeric Sort =====} > > function DoNumSort(List: TStringList; Index1, Index2: Integer): Integer; > var > N1, N2: Double; > begin > N1:= StrToFloatDef(List[Index1],0); > N2:= StrToFloatDef(List[Index2],0); > if N1 < N2 then > result := -1 > else if N1 > N2 then > result := 1 > else > result := 0; > if not SortAscending then > Result:= -Result; > end; > > procedure SortNumeric(Items: TStrings); > var > Alist: TStringList; > begin > Alist:= TStringList.Create; > with Items do begin > Alist.CommaText:= CommaText; > Alist.CustomSort(@DoNumSort); > CommaText:= Alist.commaText; > end; > FreeAndNil(Alist); > end; > > { This is the User Sort main routine } > { Example Call: SortStringList(Memo1.Lines, HebrewSort); } > { Example Call: SortStringList(ListBox1.Items, HebrewSort); } > { Example Call: SortStringList(ComboBox1.Items, HebrewSort); } > > function SortStringList(AStringList: TStrings; SortStyle: Integer): Integer; > var > SortList: TStringList; > begin > SortList:= TStringList.Create; > SortList.CaseSensitive:= True; > SortList.Assign(AStringList); > { Sort according to Language } > case SortStyle of > EnglishSort: SortList.Sort; > HebrewSort: SortList.CustomSort(@SortHebrew); > PortugueseSort: SortList.CustomSort(@SortPortuguese); > NumericSort: SortList.CustomSort(@DoNumSort); > { need input from Lazarus community for other Sort Methods } > end; > AStringList.Assign(SortList); > FreeAndNil(SortList); > end; Maybe you are searching for a unit with lots of string compare functions? Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ????

Reply by email

Benito van der Zander
to Mattias Gaertner: On Sat, 1 Dec 2012 16:43:34 +0200 I'm not sure if I can follow you here. Maybe this helps:
and there are other available too.

Which and where?

I recently grepped the fpc source to find a stable sort, and instead

I only found QuickSort implementations.

Seven of them! In TFPList.Sort, TStringList.QuickSort,

TFPSList.QuickSort, TFPBaseDitherer.QuickSort,
TFPMedianCutQuantizer.QuickSort, TFPMedianCutQuantizer.QuickSortBoxes and paslzxcomp.qsort

Plus another one in the LCL in TCustomGrid.Sort.

I would also call that "completely inadequate", and in addition unnecessarily overcomplicated.

If all theses classes would use the same sorting function, you could just write a single comparison function,
for the languages you have...

Benito

Mattias Gaertner wrote 119 lines
On Sat, 1 Dec 2012 16:43:34 +0200 Avishai wrote: > Lazarus support for Sorting is completely inadequate. You can not > sort a list of strings without knowing the language of the list. This > should be a simple process. I would like to try to improve this, but I > will need some help from the Lazarus community. > > It appears that each Control that has a List has its own separate Sort > routine and each is different. I would think that there would be a > single Sort routine and could be called by each control. I'm not sure if I can follow you here. Maybe this helps: A string list can be sorted with a single line of code or you can write your own compare function. The default sort algorithm is quicksort and there are other available too. So support for "Sorting" is good. Maybe you are missing some "String compare functions"? There are many basic compare functions in the RTL, FCL and LazUtils. For instance CompareStr, CompareText, AnsiCompareText, UTF8CompareStr, UTF8CompareText. All these functions have their pros and cons. Keep in mind that some human languages have multiple official compare functions and it gets even more difficult when mixing languages (unicode). > This could be a starting point that could be expanded to include other > Languages and Sort Methods, but it is only a suggestion. > > {===== Sorting =====} > > const > SortAscending: Boolean = True; > > function SortHebrew(List: TStringList; Index1, Index2: Integer): > Integer; {Hebrew} > begin > Result:= UTF8CompareStr(List[Index1],List[Index2]); > if not SortAscending then > Result:= -Result; > end; > > function SortPortuguese(List: TStringList; Index1, Index2: Integer): > Integer; {Portuguese} > begin > Result:= WideCompareText(UTF8Decode(List[Index1]),UTF8Decode(List[Index2])); > if not SortAscending then > Result:= -Result; > end; > > {===== Numeric Sort =====} > > function DoNumSort(List: TStringList; Index1, Index2: Integer): Integer; > var > N1, N2: Double; > begin > N1:= StrToFloatDef(List[Index1],0); > N2:= StrToFloatDef(List[Index2],0); > if N1< N2 then > result := -1 > else if N1> N2 then > result := 1 > else > result := 0; > if not SortAscending then > Result:= -Result; > end; > > procedure SortNumeric(Items: TStrings); > var > Alist: TStringList; > begin > Alist:= TStringList.Create; > with Items do begin > Alist.CommaText:= CommaText; > Alist.CustomSort(@DoNumSort); > CommaText:= Alist.commaText; > end; > FreeAndNil(Alist); > end; > > { This is the User Sort main routine } > { Example Call: SortStringList(Memo1.Lines, HebrewSort); } > { Example Call: SortStringList(ListBox1.Items, HebrewSort); } > { Example Call: SortStringList(ComboBox1.Items, HebrewSort); } > > function SortStringList(AStringList: TStrings; SortStyle: Integer): Integer; > var > SortList: TStringList; > begin > SortList:= TStringList.Create; > SortList.CaseSensitive:= True; > SortList.Assign(AStringList); > { Sort according to Language } > case SortStyle of > EnglishSort: SortList.Sort; > HebrewSort: SortList.CustomSort(@SortHebrew); > PortugueseSort: SortList.CustomSort(@SortPortuguese); > NumericSort: SortList.CustomSort(@DoNumSort); > { need input from Lazarus community for other Sort Methods } > end; > AStringList.Assign(SortList); > FreeAndNil(SortList); > end; Maybe you are searching for a unit with lots of string compare functions? Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Avishai
to Benito van der Zander

"you could just write a single comparison function, for the languages you have..."

That is assuming you know in advance what language will be used. If you don't, then what? I can send someone a '.po' but I can't change the Sort method if it isn't already in code. What sort method should I include for Japanese???

Benito van der Zander wrote
you could just write a single comparison function, for the languages you have...
Shalom, Avishai ????? ????

Reply by email

Chavoux Luyt
to Avishai

This is where one would want generics... I am not sure if this is implemented in Object Pascal yet (but it is part of C++ and other languages). I remember it being on the wish list for Delphi for a long time, but don't know if it ever got implemented?

It would be nice if all Lazarus components could use a single fpc library for its sorting.

Cheers
Chavoux

Avishai wrote 27 lines
"you could just write a single comparison function, for the languages you have..." That is assuming you know in advance what language will be used. If you don't, then what? I can send someone a '.po' but I can't change the Sort method if it isn't already in code. What sort method should I include for Japanese??? On Sat, Dec 1, 2012 at 7:21 PM, Benito van der Zander wrote: > you could just write a single comparison function, > for the languages you have... -- Shalom, Avishai ????? ???? -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20121201/2b2374de/attachment.html>

Reply by email

Sven Barth
to Chavoux Luyt
Chavoux Luyt wrote
This is where one would want generics... I am not sure if this is implemented in Object Pascal yet (but it is part of C++ and other languages). I remember it being on the wish list for Delphi for a long time, but don't know if it ever got implemented?

FPC has support for generics since around 2006 and has matured since (especially in 2.7.1 since I began working on them). Delphi has support for generics since Delphi 2009.

For more information about FPC's generics (in 2.6.0) you can take a look here: http://www.freepascal.org/docs-html/ref/refch8.html#x91-1010008

You can also look at
$fpcdir/rtl/objpas/fgl.pas (generic lists and map) and
$fpcdir/packages/fcl-stl/

Regards,
Sven

Reply by email

Avishai
to Sven Barth

Another point about Sorting. Am I the only one that is bothered by the fact that TListBox and TComboBox default sort is not Case Sensitive? Example: Put in a list of your name over and over. Use caps on only some of them in random order. Then do a sort. To me, it should group the uppercase together in one group and the lowercase in another group. That's not what happens. I think the same is true for TStringList and TStringGrid, but at least TStringList has an override. TStringList.CaseSensitive.

So to get acceptable results for TListBox sort, I have to first assign the list to a TStringList, Set TStringList.CaseSensitive:= True, do the sort and then put it back to the TListBox. Not difficult but...

Sven Barth wrote 30 lines
On 01.12.2012 18:44, Chavoux Luyt wrote: > > This is where one would want generics... I am not sure if this is > implemented in Object Pascal yet (but it is part of C++ and other > languages). I remember it being on the wish list for Delphi for a long > time, but don't know if it ever got implemented? FPC has support for generics since around 2006 and has matured since (especially in 2.7.1 since I began working on them). Delphi has support for generics since Delphi 2009. For more information about FPC's generics (in 2.6.0) you can take a look here: http://www.freepascal.org/docs-html/ref/refch8.html#x91-1010008 You can also look at $fpcdir/rtl/objpas/fgl.pas (generic lists and map) and $fpcdir/packages/fcl-stl/ Regards, Sven -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ????

Reply by email

Reinier Olislagers
to Avishai: The problem is that there is no way to know which sort algorithm to use for which…
Avishai wrote 12 lines
The problem is that there is no way to know which sort algorithm to use for which language without a lot of experimenting. It took quite a bit of time for me to find one that worked for Hebrew. But more than that, for globalization/localization the Language may not be known in advance. An example: Your app. is Globalized/Localized for String display Language. But you have a Sorted ListBox with Default Sort. The user selects Russian for his language. The app. knows the language, but the ListBox Sort is wrong.

1. So you want to have a set of default (in Lazarus) or perhaps pluggable (with units of your own) sorting routines that...

There should be a central Sort routine that can decide which Sort method to use based on the Language.

2. ... apply to all GUI I mentioned in the forum threads on sorting, that sounds like a very good idea.

Regardless of the implementation of 1. I think the sort routines for the various controls (point 2) could be centralized already... unless there are valid reasons for that.

I would suggest to create 2 separate bug reports covering point 1 and 2..

Show quoted text 5 lines
I'm asking for help to achieve this. I have no idea what sort methods to use for non-Latin languages. Russian, Croatian, Greek... Once completed and tested, it could be made a part of Lazarus, or at the very least, some guide could be available to help others.

So finally, you'd like
3. ready made sorting for item 1 for various languages. Once again, seems quite sensible not to have to reinvent the wheel all the time.
Presumably sorting order etc could be derived from how other databases sort (e.g. the Firebird or PostgreSQL databases).

Seems like a candidate for another bug report.

Regards,
Reinier

Reply by email

Juha Manninen
to Reinier Olislagers

The default sort routine is quicksort and it works well in every situation. It uses a compare function which returns -1, 0 or 1 depending on its parameters. You need different compare functions, not different sort functions to support the languages.
Mattias tried to explain it already.
There could also be other sort functions / algorithms like merge sort or even bubble sort, but that is another issue.

Otherwise the idea was good. All GUI controls and maybe StringList, too, should use the same locale specific compare function.

Having separate quicksort routines in many containers is not as bad as it sounds. The quicksort routine is short and well-established (will not change) and it must use the container's data directly inside a tight loop.

Juha

Reply by email

Hans-Peter Diettrich
to Avishai: The problem is that there is no way to know which sort algorithm to use for which…
The problem is that there is no way to know which sort algorithm to use for which language without a lot of experimenting. It took quite a bit of time for me to find one that worked for Hebrew.

IMO the Unicode support libraries include various comparison functions, not only for every language, but also for different sort orders (alphabetic, alphanumeric, phone book...). So it's a matter of making that support available to FPC/Lazarus.

But more than that, for globalization/localization the Language may not be known in advance.

Right :-(

A codepage can apply to multiple languages, so that usually the user or coder has to specify the language to use for sorting. Both have the option to set/use the OS codepage/language. But this won't help much when a list can contain strings of multiple languages, in the worst case at the same time!

DoDi

Reply by email

Alexander Klenin
to Juha Manninen: The default sort routine is quicksort and it works well in every situation. It uses a…
Juha Manninen wrote 7 lines
The default sort routine is quicksort and it works well in every situation. It uses a compare function which returns -1, 0 or 1 depending on its parameters. You need different compare functions, not different sort functions to support the languages. Mattias tried to explain it already. There could also be other sort functions / algorithms like merge sort or even bubble sort, but that is another issue.

There are two independent issues here.
First is a possible lack of Unicode collation support in Lazarus -- I am not sure about it,
but I was under the impression that UTF8Compare provides such support. If I am wrong, then it is certainly a serious omission.

The other is a lack of standard algorithm and data structures support. This is a most prominent factor behind the sharp decline of Pascal's relevancy as a teaching language.
In fact, just this Friday I performed an informal presentation at the conference of
top Russian teachers of informatics (it.mipt.ru/conference) The main topic was "Free Pascal is not dead, please do not abandon it yet".

Recent addition of FCL-STL was a great move which promises some future for Pascal in education. It has many shortcomings, but is definitely a step in right direction,
compared to the current mess. I hope it did not come too late.

Having separate quicksort routines in many containers is not as bad as it sounds. The quicksort routine is short and well-established (will not change) and it must use the container's data directly inside a tight loop.

Not quite so. On the one hand, quicksort is unstable, which is not good when sorting non-trivial containers. On the other, constant factor in sorting algorithms
is usually dominated by calls to the comparator, which can not be eliminated without generics.

Alexander S. Klenin

Reply by email

Juha Manninen
to Alexander Klenin
Alexander Klenin wrote
quicksort is unstable, which is not good when sorting non-trivial containers.

How is it unstable? I may have gaps in my knowledge.

Yes, the lack of standard algorithms and container classes is a big problem. I must study the improved FCL-STL.

Juha

Reply by email

Mattias Gaertner
to Juha Manninen: How is it unstable? I may have gaps in my knowledge. Yes, the lack of standard algorithms…
On Sun, Dec 2, 2012 at 10:39 AM, Alexander Klenin wrote: > quicksort is unstable, which is not good when sorting non-trivial containers. How is it unstable? I may have gaps in my knowledge.

http://en.wikipedia.org/wiki/Sorting_algorithm

Quicksort has some more drawbacks, of which some can be easily remedied. The FCL implementation has some of these improvements.

Yes, the lack of standard algorithms and container classes is a big problem. I must study the improved FCL-STL.

Mattias

Reply by email

Michael Van Canneyt
to Alexander Klenin: There are two independent issues here. First is a possible lack of Unicode collation…
Alexander Klenin wrote 27 lines
On Sun, Dec 2, 2012 at 3:53 AM, Juha Manninen wrote: > The default sort routine is quicksort and it works well in every situation. > It uses a compare function which returns -1, 0 or 1 depending on its parameters. > You need different compare functions, not different sort functions to > support the languages. > Mattias tried to explain it already. > There could also be other sort functions / algorithms like merge sort > or even bubble sort, but that is another issue. There are two independent issues here. First is a possible lack of Unicode collation support in Lazarus -- I am not sure about it, but I was under the impression that UTF8Compare provides such support. If I am wrong, then it is certainly a serious omission. The other is a lack of standard algorithm and data structures support. This is a most prominent factor behind the sharp decline of Pascal's relevancy as a teaching language. In fact, just this Friday I performed an informal presentation at the conference of top Russian teachers of informatics (it.mipt.ru/conference) The main topic was "Free Pascal is not dead, please do not abandon it yet". Recent addition of FCL-STL was a great move which promises some future for Pascal in education. It has many shortcomings, but is definitely a step in right direction, compared to the current mess. I hope it did not come too late.

Can we hope to see some patches that remedy these shortcomings ?

Some time ago, We received an alternative implementation of these generic classes, but since we do not use generics intensively, we're not really in the position to make well-founded decisions. As a result, the new implementation is simply floating...

So, a maintainer for the FCL-STL generics classes would be welcome.

Michael.

Reply by email

Alexander Klenin
to Michael Van Canneyt
Michael Van Canneyt wrote
Some time ago, We received an alternative implementation of these generic classes, but since we do not use generics intensively, we're not really in the position to make well-founded decisions. As a result, the new implementation is simply floating...

Is that alternative implementation available somewhere? Note that the current FCL-STL is not too bad, I do not see a need for complete replacement,
just for incremental improvements.

So, a maintainer for the FCL-STL generics classes would be welcome.

I'll see what I can do. Would you accept git-generated patchsets?

Alexander S. Klenin

Reply by email

Michael Van Canneyt
to Alexander Klenin
Alexander Klenin wrote 8 lines
On Sun, Dec 2, 2012 at 2:53 PM, Michael Van Canneyt wrote: > Some time ago, We received an alternative implementation of these generic > classes, but since we do not use generics intensively, we're not really in > the position to make well-founded decisions. > As a result, the new implementation is simply floating... Is that alternative implementation available somewhere?

I got them by mail. I can send them, if you are interested ? I'll then also give you the email address of the submitter.

Show quoted text 6 lines
Note that the current FCL-STL is not too bad, I do not see a need for complete replacement, just for incremental improvements. > So, a maintainer for the FCL-STL generics classes would be welcome. I'll see what I can do. Would you accept git-generated patchsets?

Well, I use subversion.
But as long as patch can handle them, no problem.

And if it turns out you will do lots of work on them, I'll see about giving you write access to that part of subversion.

Michael.

Reply by email

Alexander Klenin
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
> Is that alternative implementation available somewhere? I got them by mail. I can send them, if you are interested ? I'll then also give you the email address of the submitter.

Yes, please. Also, is the submitter of the current STL code still active?

Alexander S. Klenin

Reply by email

Michael Van Canneyt
to Alexander Klenin
Alexander Klenin wrote 9 lines
On Sun, Dec 2, 2012 at 3:29 PM, Michael Van Canneyt wrote: > >> Is that alternative implementation available somewhere? > > > I got them by mail. I can send them, if you are interested ? > I'll then also give you the email address of the submitter. Yes, please. Also, is the submitter of the current STL code still active?

Sent in private mail.

Michael.

Reply by email

Bart
to Avishai: Lazarus support for Sorting is completely inadequate. You can not sort a list of strings…
Avishai wrote
Lazarus support for Sorting is completely inadequate. ....

At the risk of repeating myself or someone else:

Every component that has a (string-based) sorting routine might also have a CustomSort like:

TBasicComponent.CustomSort(const CompareFunc: TCompareFunc);
where
type
  TCompareFunc = function(Item1, Item2: Pointer): Integer;

Or perhaps a property of type TCompareFunc that controls the default sort routine?

The challenge (for Avishai's point of view) would then be to supply appropriate compare functions for different languages and situations. The compare function also solves the "do i want case-sensitivity" issue.

Just my 2 cents...

Bart

Reply by email

Avishai
to Bart

My interest is that there be a Sort method that is "Langauge aware" and that it Not be driven by Locale. Letting Locale set a default sort method makes sense, but you should be able to override that default. As for CaseSensitive Sort, I have tried and failed to think of a situation where I wouldn't want a CaseSensitive Sort, assuming the Language has Case (Hebrew does not). It should also have "Property SortAscending: Boolean = True".

For me the only real issue is collecting the proper Sort methods (compare functions) for the different languages and constructing a wrapper to implement them. With the help of the Lazarus community, I don't think that should be difficult.

Bart wrote 30 lines
On 12/1/12, Avishai wrote: > Lazarus support for Sorting is completely inadequate. .... At the risk of repeating myself or someone else: Every component that has a (string-based) sorting routine might also have a CustomSort like: TBasicComponent.CustomSort(const CompareFunc: TCompareFunc); where type TCompareFunc = function(Item1, Item2: Pointer): Integer; Or perhaps a property of type TCompareFunc that controls the default sort routine? The challenge (for Avishai's point of view) would then be to supply appropriate compare functions for different languages and situations. The compare function also solves the "do i want case-sensitivity" issue. Just my 2 cents... Bart -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Shalom, Avishai ????? ????

Reply by email

Hans-Peter Diettrich
to Avishai
My interest is that there be a Sort method that is "Langauge aware" and that it Not be driven by Locale. Letting Locale set a default sort method makes sense, but you should be able to override that default.

Something like OnCompareItem?

As for CaseSensitive Sort, I have tried and failed to think of a situation where I wouldn't want a CaseSensitive Sort, assuming the Language has Case (Hebrew does not).

There exist enough situations, e.g. the identifiers in Pascal source code are case insensitive.

It should also have "Property SortAscending: Boolean = True".

This can become a property of the sorting procedure.

For me the only real issue is collecting the proper Sort methods (compare functions) for the different languages and constructing a wrapper to implement them. With the help of the Lazarus community, I don't think that should be difficult.

Did you already examine all list classes in the libraries, what sorting features they have, and how these are different? Then you can suggest a more common interface that could be implemented for all these lists.

The general compare function needs a mapping table, from character codes (codepoints) into the sort order. Then its mostly stupid work, to implement the mapping tables for every language, case sensitivity and sorting mode.

Some languages, like German, deserve a comparison function that also handles digraphs, so that e.g. 'ae' can sort like '?', or just before or after '?'. In case-insensitive sorting all forms of 'AE', 'Ae' and 'ae' have to map to the same sort order value. The same for ligatures or true digraphs (Unicode: not canoncial), like 'a?' standing exactly for '?'. For such languages I'd suggest to use the Unicode library functions, which should already cover all these issues.

DoDi

Reply by email

Michael Schnell
to Juha Manninen: The default sort routine is quicksort and it works well in every situation. It uses a…
Juha Manninen wrote
All GUI controls and maybe StringList,

If they use something else than a simple "<" / "=" / ">" in the user code does this asks for extreme confusion.

This the way to go would be to just to make the string compare globally configurable.

Of course this is more an FPC issue than a Lazarus issue.

As I feel that FPC is in the verge of a transition to use the Delphi XE compatible "NewStrings" as the default string type, this seems like a viable and doable enhancement right now.

-Michael

Reply by email

Reinier Olislagers
to Michael Schnell
Michael Schnell wrote 11 lines
On 12/02/2012 12:53 AM, Juha Manninen wrote: > All GUI controls and maybe StringList, > If they use something else than a simple "<" / "=" / ">" in the user code does this asks for extreme confusion. This the way to go would be to just to make the string compare globally configurable. Of course this is more an FPC issue than a Lazarus issue.

Sounds like a very good plan to do this at the FPC level as text-mode programs dealing with strings may benefit from this as well.

Reply by email

Michael Schnell
Avishai wrote
Non Case Sensitive gives a result like "A a a A A a A". This is a form of randomness.

If course: if the sort order considers things to be equal while the display considers them to be not equal, the sorted result looks random. This is by design. And with Unicode this and/or the vice versa case (characters that look identical but are coded in multiple ways) is unavoidable.

But besides "not case sensitive" ("A" and "a" are sorted as equal) you can define sort orders like

....ABCDE....abcde....

or

....AaBbCcDdEe....

or

....aAbBcCdDeD...

or (regarding German)

....AB.....?....

or

....A?B....

which all make sense in appropriate applications.

-Michael

Reply by email