Click here to Skip to main content
15,899,313 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Luc Pattyn7-Nov-08 14:26
sitebuilderLuc Pattyn7-Nov-08 14:26 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat97-Nov-08 18:56
supercat97-Nov-08 18:56 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Kevin McFarlane8-Nov-08 0:50
Kevin McFarlane8-Nov-08 0:50 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat98-Nov-08 9:37
supercat98-Nov-08 9:37 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Kevin McFarlane8-Nov-08 9:43
Kevin McFarlane8-Nov-08 9:43 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Luc Pattyn8-Nov-08 2:49
sitebuilderLuc Pattyn8-Nov-08 2:49 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Mark Salsbery8-Nov-08 6:15
Mark Salsbery8-Nov-08 6:15 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat98-Nov-08 9:25
supercat98-Nov-08 9:25 
Luc Pattyn wrote:
1. Array.IndexOf() returns the first match, which makes it essentially a linear search.
What you want is a "find any" that scales well, let's say a hash table.


There are a number of approaches that can be used. I figured I would try the IndexOf approach to see how far it would scale before the linear term became too dominant. The answer is, not quite far enough.

As noted, the most common number of items is probably below ten. Presently I start with a 16-element array and double the number of elements every time it overflows. If I start with a hash table, then the small dictionaries are going to be stored very inefficiently. Perhaps the thing to do would be to start with an array, and switch to a 16-way hash table when the number of elements exceeds 256, a 256-way hash table if the number of elements exceeds 4096, and a 4096-way hash table if it exceeds 65,536. Regenerating the hash tables at each boundary case wouldn't be free, but such the vast majority of elements would be regenerated at most once.

Luc Pattyn wrote:
3.
3. Wouldn't it be better to inherit from Dictionary and add the functionality you want? I guess you can replace the Add and Remove methods, so you are aware of those operations, then create your own IEnumerable implementation which could use indices and "return yield".


The Dictionary class does not expose its inner workings. While it would be possible to implement something like the 'DeleteForAll' method that's available on a List, such a method would have to queue up a list of keys and then process deletion using the list. This would require a key lookup for every entry to be deleted, whereas a well-constructed DeleteForAll primitive shouldn't require any key lookups.

Luc Pattyn wrote:
4. It may be unwise to come up with an IEnumerable that behaves quite differently from regular
IEnumerables, those that do fail when the collection gets modified at all.


So you're saying that working sensibly when a collection is changed during enumeration would be a breaking change?

Luc Pattyn wrote:
5. You might use Reflector (or look into the Rotor source) to see how they went about it
in the first place.


I'm not familiar with those things.

BTW, after posting my earlier message, I was thinking that for my hierarchical collection it might be better to build in whatever sort of dictionary implementation I'm using rather than using a dictionary-style object, since copy-on-write cloning would probably work wonders for performance and I don't think such a paradigm is apt to be useful with anything resembling a standard Dictionary (a Dictionary could implement copy-on-write shallow cloning, but in my scenario what's needed is copy-on-write deep cloning; that would require that when an object held in the dictionary is modified, it notify the dictionary so that the dictionary can perform the necessary hard cloning operation).
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Luc Pattyn8-Nov-08 12:36
sitebuilderLuc Pattyn8-Nov-08 12:36 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat98-Nov-08 14:08
supercat98-Nov-08 14:08 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Luc Pattyn8-Nov-08 15:38
sitebuilderLuc Pattyn8-Nov-08 15:38 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat99-Nov-08 6:17
supercat99-Nov-08 6:17 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Luc Pattyn9-Nov-08 7:57
sitebuilderLuc Pattyn9-Nov-08 7:57 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's [modified] Pin
supercat99-Nov-08 15:29
supercat99-Nov-08 15:29 
AnswerRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
Mark Churchill9-Nov-08 12:44
Mark Churchill9-Nov-08 12:44 
GeneralRe: Any fast way to do Array.IndexOf(Of Integer)() without DLL's Pin
supercat99-Nov-08 15:50
supercat99-Nov-08 15:50 
QuestionI am a novice at this, where can I post a job for .net developer? Pin
PhyllisM7-Nov-08 9:54
PhyllisM7-Nov-08 9:54 
AnswerRe: I am a novice at this, where can I post a job for .net developer? Pin
Colin Angus Mackay7-Nov-08 10:37
Colin Angus Mackay7-Nov-08 10:37 
GeneralRe: I am a novice at this, where can I post a job for .net developer? Pin
Mark Salsbery8-Nov-08 6:20
Mark Salsbery8-Nov-08 6:20 
GeneralRe: I am a novice at this, where can I post a job for .net developer? Pin
Colin Angus Mackay8-Nov-08 6:43
Colin Angus Mackay8-Nov-08 6:43 
GeneralRe: I am a novice at this, where can I post a job for .net developer? Pin
#realJSOP9-Nov-08 23:55
professional#realJSOP9-Nov-08 23:55 
GeneralRe: I am a novice at this, where can I post a job for .net developer? Pin
Paul Conrad8-Nov-08 13:20
professionalPaul Conrad8-Nov-08 13:20 
AnswerRe: I am a novice at this, where can I post a job for .net developer? Pin
Paul Conrad8-Nov-08 13:18
professionalPaul Conrad8-Nov-08 13:18 
AnswerRe: I am a novice at this, where can I post a job for .net developer? Pin
#realJSOP10-Nov-08 0:02
professional#realJSOP10-Nov-08 0:02 
Questiondatabase library Pin
joindotnet7-Nov-08 1:16
joindotnet7-Nov-08 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.