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

Hashtable that doesn't store the key?

Is it possible to create a hashtable that doesn't store the key? I have a very large
hashtable and I just want it to store the HashCode and the Value (two Int16s).
Thanks - JackRazz
Nov 16 '05 #1
8 1575
Jack,

And how do you than want to find it back?

Cor
Nov 16 '05 #2

"JackRazz" <Ja******@NotValid.com> a écrit dans le message de news:
%2******************@TK2MSFTNGP14.phx.gbl...
Is it possible to create a hashtable that doesn't store the key? I have a
very large
hashtable and I just want it to store the HashCode and the Value (two
Int16s).
How will it distinguish 2 keys that have the same HashCode if you don't
store the keys? Equality on HashCode is just a hint that the keys may be
equal, but you have to compare the keys to be sure that they match, unless
you have a perfect hashing function (no collision).

Bruno.


Thanks - JackRazz

Nov 16 '05 #3
Hi JackRazz,

Could You be more descriptive with your problem?

There's an inconsistent in your text:
"I have a very large hashtable" & "I just want it to store (two Int16s)"

If you want to store only two *shorts* then why do you want to use
the hashtable?
Is it possible to create a hashtable that doesn't store the key?


I'm afraid that it is impossible.
*Key* is a main feature of hashtable collection, so only values can
contains *nulls*.

Maybe i missed somethig, so give me your feedback.

Regards
Marcin
Nov 16 '05 #4
Bruno,
Thanks for the reply. I googled 'perfect hashing' and now have a much clearer
understanding of what can be done with hashtables. Perfect hashing won't work for me
because I don't know the keys ahead of time.

"Bruno Jouhier [MVP]" <bj******@club-internet.fr> wrote in message
news:uN****************@tk2msftngp13.phx.gbl...
|
| "JackRazz" <Ja******@NotValid.com> a écrit dans le message de news:
| %2******************@TK2MSFTNGP14.phx.gbl...
| > Is it possible to create a hashtable that doesn't store the key? I have a
| > very large
| > hashtable and I just want it to store the HashCode and the Value (two
| > Int16s).
|
| How will it distinguish 2 keys that have the same HashCode if you don't
| store the keys? Equality on HashCode is just a hint that the keys may be
| equal, but you have to compare the keys to be sure that they match, unless
| you have a perfect hashing function (no collision).
|
| Bruno.
|
| >
| >
| > Thanks - JackRazz
| >
| >
|
|
Nov 16 '05 #5
Marcin,
I wanted to store two int16's as the values where the key is a string. I'm new to
hashtables and was hoping for the almost perfect hashtable that didn't require me to
store the key, but I now see the impossiblity of what I wanted to do.

Thanks for the reply - JackRazz
"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:cs**********@nemesis.news.tpi.pl...
| Hi JackRazz,
|
| Could You be more descriptive with your problem?
|
| There's an inconsistent in your text:
| "I have a very large hashtable" & "I just want it to store (two Int16s)"
|
| If you want to store only two *shorts* then why do you want to use
| the hashtable?
|
| > Is it possible to create a hashtable that doesn't store the key?
|
| I'm afraid that it is impossible.
| *Key* is a main feature of hashtable collection, so only values can
| contains *nulls*.
|
| Maybe i missed somethig, so give me your feedback.
|
| Regards
| Marcin
Nov 16 '05 #6
Hi JackRazz,
Marcin,
I wanted to store two int16's as the values where the key is a string.
Hmmm... maybe i missed something.

// but try this:
string key="myKey";
short[] twoShorts=new short[2];
twoShorts[0]=1;
twoShorts[1]=11;

hashTable.Add(key, twoShorts);

// so you can get those shorts by:
short[] tempShorts=hashTable["myKey"];
I'm new to
hashtables and was hoping for the almost perfect hashtable that didn't require me to
store the key, but I now see the impossiblity of what I wanted to do.


Hmmm... i don't what do you expect from hashtable, but i think
that you should look up the other .NET collection.

HTH
Marcin
Nov 16 '05 #7
Marcin,
Thats exactly what I'm trying to do, but with a difference. The keys I'm passing in
are all at least 5 chars long and sometimes they are phrases of 25 characters. If I
had say 400,000 items in a hashtable, the key would impact memory heavily. I was
simply trying to use a hashtable, with the hash code only being stored, not the key
due to its memory impact. I'm a bit new to hashtables, so I was thinking that this
might be possible (perfect hashing), but it doesn't like it is, unless I knew the
keys at design time (like say keywords in a compiler).

Anyhow, I'm moving on for now using the .net hashtable, with the key stored. In 15
years, there will probably be the perfect hash that doesn't care how many cycles are
used, etc (:

Thanks for the help - JackRazz


"Marcin Grzębski" <mg*******@taxussi.spamstop.com.spamstop.pl> wrote in message
news:cs**********@mamut.aster.pl...
| Hi JackRazz,
|
| > Marcin,
| > I wanted to store two int16's as the values where the key is a string.
|
| Hmmm... maybe i missed something.
|
| // but try this:
| string key="myKey";
| short[] twoShorts=new short[2];
| twoShorts[0]=1;
| twoShorts[1]=11;
|
| hashTable.Add(key, twoShorts);
|
| // so you can get those shorts by:
| short[] tempShorts=hashTable["myKey"];
|
| > I'm new to
| > hashtables and was hoping for the almost perfect hashtable that didn't require me
to
| > store the key, but I now see the impossiblity of what I wanted to do.
|
| Hmmm... i don't what do you expect from hashtable, but i think
| that you should look up the other .NET collection.
|
| HTH
| Marcin
Nov 16 '05 #8
JackRazz wrote:
Marcin, | > I'm new to
| > hashtables and was hoping for the almost perfect hashtable that didn't require me
to
| > store the key, but I now see the impossiblity of what I wanted to do.


Well... what you describe is known as a cryptograhic hash: a
hash-function where it is virtually impossible to make two inputs which
maps to the same hashed value.

For example, when you digitally sign something, what you sign is not
really the entire document, but typically a cryptographic hash of it
(usually MD5 or SHA-1), but signing the hash is almost as good, since
noone will (hopefully) be able to come up with another text with the
same hashed value.

The key-space of IDictionary is only 2^32, which is (way) too small,
SHA-1 is 2^160, for relying on cryptographic hashing, but there may be
something else you can do.

If you can reject duplicate inserts, you can reject duplicate
hash-values instead. This effectively creates a partitioning of the
key-space, creating sets of equivalent keys.

While this would mean that you would be preventing certain sets of keys
from being in the database at the same time, it might be what you seek.

For example, if the keys are usernames or something similar, you could
say username already-taken... try another one.

BTW: If the keys are actually passwords, do not use the above solution,
2^32 is a small number in todays world :)

--
Helge
Nov 16 '05 #9

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

Similar topics

4
by: Vladimir C. | last post by:
Hashtable map = new Hashtable(); map = 10; map = 20; foreach(DictionaryEntry e in map) { e.Value = 100; Console.WriteLine("{0}: {1}", key, map); }
4
by: Anders Borum | last post by:
Hello! I have a list of singleton classes (model managers) that store objects internally using hashtables. Each of these classes use a single hashtable to store e.g. users, pages, elements and...
3
by: A. Burch | last post by:
I'm wanting to use a Hashtable. I have 2 (keys, objectvalues) pairs of data to store. I'm using a static declartion for the Hashtable the instance of the class that is the object. If I try and...
1
by: francois | last post by:
Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object. the class of the object is defined serializable as the following: public...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
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: JackRazz | last post by:
Is it possible to create a hashtable that doesn't store the key? I have a very large hashtable and I just want it to store the HashCode and the Value (two Int16s). Thanks - JackRazz
17
by: John A Grandy | last post by:
For a Hashtable that is expected to contain no more than 100 DictionaryEntry elements , what is the best load factor ? ( This Hashtable is a encapsulted in a class , an instance of which is...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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...
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,...

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.