custom in-memory collection sorting

Posts   
 
    
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 20-Oct-2004 00:44:12   

Hi,

Is there a way to access the basic collection Sort method in an entity collection? I've defined a method to compare 2 entities to custom-sort them based on some values but I can't use it since the Sort method seems to be hidden.

Thanks,

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 20-Oct-2004 09:30:27   

The Sort() method added in the v1.0.2004.1 runtimes calls the sortroutine ApplySort(). The sorting routine uses a SortedList class for the sorting. There is no C-style quicksort algorithm implemented.

Frans Bouma | Lead developer LLBLGen Pro
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 20-Oct-2004 12:43:20   

Is there a way to re-sort a collection customely?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 20-Oct-2004 12:50:04   

Not by your own algorithm, as I didn't make essential elements public for that (which apparently wasn't that clever. flushed ) You can re-call Sort(fieldindex, listdirection) to re-sort the collection on another field for example. Internally it keeps a list of the elements in the original order, it just re-sorts that and re-adds the elements to the list after it's cleared. An essential element to avoid grids giving errors is that it surpresses events when the clear happens during a sort.

So re-calling Sort(index, direction) will resort the collection in-memory.

Frans Bouma | Lead developer LLBLGen Pro
Asimov
User
Posts: 113
Joined: 05-Dec-2003
# Posted on: 20-Oct-2004 22:56:15   

Unfortunately, in this case, I can't sort on a field to achieve the proper result, I need to sort using a weird compare function simple_smile I tried to re-order the items in my collection using my homemade CompareTo(MyEntity entity) method and a quick sort algorithm, but I was looking for a method to make a shallow copy of an entity in order to switch them in my collection, is there such a function in llblgen ?

Thank you!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 21-Oct-2004 10:17:32   

shallow copy? No, there isn't. But why do you need a shallow copy for quicksort? You can better use ArrayList objects or even arrays with your quicksort algo I think and simply re-add the end result to the collection.

It should work without problems when the collection isn't part of an entity (i.e. thus not not customer.Orders). First unbind the collection from a bound grid, sort the entities in a separate array, clear the collection, re-add the objects, re-bind the collection.

I've added to the todo the necessity for a generic approach to this problem.

Frans Bouma | Lead developer LLBLGen Pro