Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
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
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
 22-Jun-2007 08:44
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 22-Jun-2007 10:30
User is offline View Users Profile Print this message


Reik Schroeder

Posts: 361
Joined: 28-Jul-2003

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
Report this to a Moderator Report this to a Moderator
 22-Jun-2007 12:56
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
 22-Jun-2007 13:32
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

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
Report this to a Moderator Report this to a Moderator
 26-Jun-2007 09:28
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

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
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.