Re: what is the best datatype for..
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Tue, 20 Nov 2007 00:53:20 -0800 (PST)
On Nov 20, 12:56 am, "Hilton" <nos...@xxxxxxxxxx> wrote:
<snip>
Nope, no scanning whatsoever.
If you know you'll have say 1000 possible indices, then define an array of
1000 structs, then when you see a value of 605, you simply do
"array[605].count++" (i.e. your basic histogram code). I bet that is faster
than any dictionary implementation.
That depends on how many samples there are. Suppose there's only one
sample, but a range of size 100,000 - with the dictionary approach,
you'd only have a single entry to sort, whereas with your approach
you'd have to sort 100,000 entries. Which of those do you think would
be quicker?
(Note that using a struct may well be slower than using a class, by
the way - when sorting, each swap would be swapping more data. I
wouldn't like to say without testing though.)
Personally I'd go for the simplest code first and only optimise when
it's shown to be necessary - but at that point I'd definitely be
benchmarking instead of guessing. I would *try* using a Dictionary to
collect the values, then converting it to a list and sorting the list.
That way you wouldn't pay a penalty for unused values, although
there's a higher constant factor due to more copying being involved.
Jon
.
- Follow-Ups:
- Re: what is the best datatype for..
- From: Scott Gifford
- Re: what is the best datatype for..
- From: Hilton
- Re: what is the best datatype for..
- References:
- what is the best datatype for..
- From: calvert4rent
- Re: what is the best datatype for..
- From: Hilton
- Re: what is the best datatype for..
- From: Peter Duniho
- Re: what is the best datatype for..
- From: Hilton
- what is the best datatype for..
- Prev by Date: Re: Label Printing
- Next by Date: Re: Sending POST to a web page
- Previous by thread: Re: what is the best datatype for..
- Next by thread: Re: what is the best datatype for..
- Index(es):
Relevant Pages
|