Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# creating a fixed size hashtable

I want to be able to create a fixed size hashmap of say 100 buckets, and if I need to store over 100 items then collisions and overwriting will just have to happen. The hashtable class has a IsFixedSize property however it is readonly.

Am I thinking about this completely wrongly, or is there a solution to this?

like image 706
Projectile Fish Avatar asked Mar 08 '26 02:03

Projectile Fish


1 Answers

Collections in the .NET framework don't allow for a lot of fine-tuning. Although you might find one efficient enough for your needs. Try some viable ones out before optimizing.

If you don't roll your own then you might find a 3rd party alternative that has more fine-grained controls. For example, see The C5 Generic Collection Library for C# and CLI as a possible start. Check into the various Hash* classes on their documentation page.

If you decide to roll your own then you'll want to implement some of the standard interfaces for collections and/or lists, enumerations, etc so they work as expected with C# foreach and language and .NET features.

You might also take an efficient C++ implementation if you have one and there are ways of using it in C#/.NET. It might take a bit of finagling but there are answers on SO about how to accomplish this kind of thing.

like image 145
John K Avatar answered Mar 10 '26 15:03

John K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!