Re: fastest sorted list type?



On Sun, 13 Jan 2008 04:23:00 -0800, colin <colin.rowe1@xxxxxxxxxxxxxxxxxx> wrote:

No. You write the comparer. Note what I wrote: "if you were sorting
class instances directly".

ah sorry maybe I read what you wrote a bit quick or I wrote what I wrote a
bit quick,
cant remember now, I was just off to bed ...

Yes I know, what I meant was its an int so you cant add an interface to it,
at least not to my knowledge, although ive been looking through .net 3.5 and
notice you can add
pseudo member functions, maybe theyl add this to ints to in 5.0 ....

I'm not aware of any scenario you've mentioned in which what you're sorting is "just an int".

Yes, you have a scenario in which you are sorting a list of ints, but when you actually compare two entries in that list you aren't comparing the integers themselves, but rather the data in an object to which the int refers.

the binary Add was what I had written before wich did exactly what you are
mentioning,
I just had to add an extra parameter for the comparer.

Right. And with that parameter, you are given complete, absolute control over how the comparison is done. Which makes sense, really. If you're using an integer index into some array and sorting a list of those indices, you obviously must be able to override the default "compare two integers" behavior. And once you're overriding that default behavior, you can implement whatever behavior your heart desires.

[...]
Im getting an old programmer now, ive forgoton so much it seems,
It was nice to be able to forget about low level stuff when I moved to c#
think maybe I forgot a bit too much lol.
I just didnt know what was under the hood of the List<T>.Sort() so I assumed
it wasnt very good,
seems now I was mistaken ...
I did read somewhere the SortedList<T> and SortedDictionary<T> were very
fast maybe its al the same as List<T>

My experience has been that the .NET classes are all generally written with care and with minimal performance problems. You should start out with the assumption that a given class is very good, and then investigate further if for some reason that appears to turn out not to be the case.

Even where a class appears to not be very good, it will usually turn out that it's simply sensitive to misuse. In the rare situation in which the class really isn't very good, then you can think about writing your own.

your replies are actually very clear and helpfull
and a few other peoples too, I thank you a lot,

You're welcome.

I always seem to hurry mine,
usualy becuase ive spent ages trying to solve a problem and
need a break cos my head hurts but think il just ask on
the forum maybe il have an answer when i get back .. :D
(am I lazy or what!)

No comment. :)

[...]
I dont know if you saw my other post but I intend to try and sort the data
very crudly by using the length
as an index, the maximum length can be determined as the data is being created,
sorting the data into bins of 1% would make little diference to the outcome,
ofc each 1% bin could then be sorted.
I did have a look on google and wiki lists al the sort algorothms nicely,
but doesnt list this type.

I gues it is just a classic case of dividing the data down into smaller
chunks.

I'm not really clear on what you're describing, but it sounds a little like a merge sort. In case you're looking for a term you can use to search for additional information on refining the implementation you've come up with.

Pete
.



Relevant Pages