![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: Sorting Callback Function Required Topic Summary: Efficient sorting callback function required for paragraph numbers Created On: 22-Jun-2007 08:44 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
I have a listview with numerous columns.
The listview is configured for sorting on all columns. I can successfully sort on string, date, int, real. But the first column contains paragraph numbers, i.e. 1.1, 1.2, 1.3 etc. My callback on this column works, but it takes an age to sort the column because of all the processing required to compare two legal numbers. The callback function for sorting strings is really simple: int doSortString(string s1, string s2) { return(cistrcmp(s1, s2)) } The callback for sorting integers needs to convert from the string column value to an int and then do the comparison: int doSortInteger(string s1, string s2) { int i1 = intOf(s1) int i2 = intOf(s2) if (i1 > i2) { return(1) } else if (i2 > i1) { return(-1) } return(0) } You get the idea? So, does anyone have a really fast way to compare two legal numbers? ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Hi Tony,
possibly you could use a "cache" Skip list to store a numerical interpretation of the paragraph number. Let's assume that one part of paragraph number is always less than 100 so you could compute an int|real to compare: last number + 100 * (number before last) + 100*100*(number before before last .... Then in sorting callback you need only to find the numbers and return integer|real comparision. Another option could be to insert leading zeros for each hierarchy in paragraph number. Then normal string comparision should be possible (compare only the substring at beginning of both strings until mininum of both lengths of strings) Hope that helps you, Greetings Reik ------------------------- Evosoft GmbH for Siemens Industry Sector Berlin, Germany |
|
![]() |
|
![]() |
|
I came up with this which works fast enough to sort a large listview with no noticeable delay. Much much faster than my previous approach which was to add preceeding zeroes etc...
Note this function fails horribly if a non-legal number string is passed. ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
So your program doesn't fail, use isValidInt(string s) to check that its a valid integer.
------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
Thanks David, you are right that the script needs some protection against bad parameters.
I am making use of a feature of the intOf() function that means it returns an integer as long as the beginning of the string is a valid int and ignores the rest of the string. intOf("1.2") returns 1, but isValidInt("1.2") returns false. These functions are not as closely related as I might have hoped. This means that isValidInt is of no use here. Instead, use noError...lastError to surround calls to intOf() as follows: noError i1 = intOf(s1) i2 = intOf(s2) if (lastError != "") { return(0) } ------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
Sorting Callback Function Required
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.