473,395 Members | 1,720 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,395 software developers and data experts.

Hashtable with special access of values

hk
Hello,

I would like to create a special version of hashtable,
either inherited from hastable or from DictionaryBase.

I would like to be able to access the class from outside
in the following fassion:

spec_htb.Add("key","abc");
spec_htb.Add("key123",123);

spec_htb["key"] returns doubles but fails on the strings
spec_htb.Strings["key"] returns just strings, fails on doubles
spec_htb.Doubles["key"] returns just doubles, fails on strings

Internally the class should save everything to just one table
independent from the type.

Any suggestions how to accomplish this?

Regards,

Holger

Nov 17 '05 #1
1 1675
When you say "fails", do you mean "acts like they're not there"?

I would composition here rather than inheritance: create a new class
that encapsulates two hash tables, one for strings and one for doubles.
Implement your methods to look in one hash table or the other depending
upon what's needed.

That said, there would be some interesting issues to resolve here:

What happens when you say

spec_htb["key"] = 0.25;

and the entry for "key" already exists and is a string? Do you replace
it? Do you allow up to _two_ entries for "key", one a string and one a
double? Or do you throw an exception?

Are there any operations that return mixed hash table entries, some
doubles and some strings? What about enumerators, do they enumerate
over everything in the composite table, or do you have separate
enumerators for doubles and strings?

Anyway, the answers to some of these questions might change the design.
Good luck.

Nov 17 '05 #2

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

Similar topics

3
by: frazer | last post by:
hi i have a hashtable which has some items in it. when i enumerate it using the IDictionaryEnumerator . it gives me the items in reverse order. why is that. how do i correct it? thnx
10
by: Brian | last post by:
I'm reasonably new to C#, and using a class containing a hashtable collection to feed a treeview. My problem is that I can't pull the data from the hashtable! Here's the code I have: if...
8
by: SenthilVel | last post by:
how to get the corresponding values for a given Key in hashtable ??
16
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
6
by: Steven Wolf | last post by:
Hi guys, can a hashtable be faster than a sql server?? i made my own O/R mapping with an "entity cache" (caching all mapped objects). So, when i get some data from my sql server, i map that data...
10
by: SK | last post by:
Hey, i have a hashtable, where I am adding some values. Now when I iterate through them then they start in reverse order, why is that happening and how can I get rid of it? Thanks
1
by: Slonocode | last post by:
I have a collection of objects in a hashtable. The objects have a datamember that is empty. I need to loop through the items in the hashtable and add data to the datamember that is empty. ...
8
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed...
8
by: Martin Pöpping | last post by:
Hello, I´ve implemented a Hashtable with Int-Keys and Double Values. Now I want to get the i-th Int-Key of my hashtable. How do I do that? I tried it like that: ICollection intKeys =...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.