473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Hashtable or array of structs?

I am implementing an application which requires the storage of a large
number of items in a cache.

I have 3-tuple key reprented by a struct, as well as an n-tuple (n is
fixed) dataset, also represented by a struct. At run time, I will no
exactly the number of items in the hashtable (I will have populated it
myself by loading the data from a database). During the course of the
applications lifetime, I will retrieve data in the hashtable and update it.

My question about the suitability of using a hashtable (as opposed to a
simple array of structs) is this:

The table will be 100% full - and I know that hashtables begin to suffer
a performance hit once they get to about 70% filled. (or maybe I should
create the hashtable to be able to hold a larger number of items than I
know I will need? - The number is fixed and does not vary after initial
population).

If my key was a single item, then it would be relatively trivial to
implement the cache as an array of structs. However, The are three items
that uniquely identify a record (this 3-tuple actually form the
composite primary key loaded from the db schema).

I would much prefer to implement this as a hashtable, as I can easily
use the composite lookup key. I have also chosen the keys to be
integers, to further speed the computation of the has key. I would
appreciate any feedback on this choice.

Thanks

Nov 15 '05 #1
2 2360
Alfonso Morra wrote:
.... snip ...
I would much prefer to implement this as a hashtable, as I can
easily use the composite lookup key. I have also chosen the keys
to be integers, to further speed the computation of the has key.
I would appreciate any feedback on this choice.


Take a look at hashlib and the example programs with it. It will
allow entering one item in multiple databases and easy
experimentation with hashfunctions. Another usage example is
id2id-20. Both can be found at:

<http://cbfalconer.home.att.net/download/>

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!

Nov 15 '05 #2

"Alfonso Morra" <sw***********@the-ring.com> wrote

My question about the suitability of using a hashtable (as opposed to a
simple array of structs) is this:

The table will be 100% full - and I know that hashtables begin to suffer a
performance hit once they get to about 70% filled. (or maybe I should
create the hashtable to be able to hold a larger number of items than I
know I will need? - The number is fixed and does not vary after initial
population).
You need free slots in a hash table, or the algorithm begind to break down.
So you will need memory for about 2 * the number of entries.
If my key was a single item, then it would be relatively trivial to
implement the cache as an array of structs. However, The are three items
that uniquely identify a record (this 3-tuple actually form the composite
primary key loaded from the db schema).

If I understand this correctly you will need three arrays / hashtables for
each entry. If the keys are mutable then array indexing is a poor choice -
you will need to constantly rebuild the arrays.
Make the hashtables store pointers to reduce memory overhead and avoid
synchronisation problems.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Otto Barnes | last post by:
Hello all, I have written a hashtable class that holds a dyanically allocated array of structs which holds data about a visualization model. This data is parsed via xerces from XML into this...
5
by: Paminu | last post by:
Why make an array of pointers to structs, when it is possible to just make an array of structs? I have this struct: struct test { int a; int b;
7
by: Joseph Lee | last post by:
Hi All, I am having problem when i am using hashtable to keep an array of bytes value as keys. Take a look at the code snippet below --------------------------------------------------- ...
3
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
2
by: D. Shane Fowlkes | last post by:
I've been reading up on Arrays in ASP.NET. I'm going to create an two dimensional array of some type to contain 5 columns but a variable amount of rows. I read up on the ArrayList function and...
1
by: Alexander Widera | last post by:
hello, how can I convert a hashtable to an arraylist or array? I want to sort the hashtable... but this isn't posible, so i have to convert it to an hashtable. thank you, alex
4
by: Joseph Bergevin | last post by:
Why can't I use an int for a key? Doing so evidently doesn't result in unique IDs being generated. I can convert the array into a delimited string, which works fine, but then I have a good deal of...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
9
by: raylopez99 | last post by:
Hello all— I’m trying to get the below to work and cannot get the format right. It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx What it is: I’m trying...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.