473,670 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1587
Jack,

And how do you than want to find it back?

Cor
Nov 16 '05 #2

"JackRazz" <Ja******@NotVa lid.com> a écrit dans le message de news:
%2************* *****@TK2MSFTNG P14.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******@clu b-internet.fr> wrote in message
news:uN******** ********@tk2msf tngp13.phx.gbl. ..
|
| "JackRazz" <Ja******@NotVa lid.com> a écrit dans le message de news:
| %2************* *****@TK2MSFTNG P14.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*******@taxu ssi.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(k ey, twoShorts);

// so you can get those shorts by:
short[] tempShorts=hash Table["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*******@taxu ssi.spamstop.co m.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(k ey, twoShorts);
|
| // so you can get those shorts by:
| short[] tempShorts=hash Table["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
17477
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
8349
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 so on (I have complete control of the objects stored). I am currently using a set of abstract cache classes that my model managers subclass. The hashtable in a model managers could, potentially, store more than 25.000 objects (let's imagine...
3
1282
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 retreive the first object after storing after the 2 (key, objectvalues) are stored I always get the last object value stored. Why doesn't qrec = (Q)HT give a copy of the last or in this code the second of the 2 objects? How should the code be...
1
8710
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 class Event {
5
2817
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 like it to return an XML serialized version of an object.
8
1684
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 on string). So, for example, when I want to know if the file "xyz.abc" is in the cache, I can write myTable.ContainsKey ( "xyz.abc" ) or if a given DB key is in the hash I can write myTable.ContainsKey ( 123 ). Or do the keys all have to be of...
8
1003
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
5073
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 cached and methods on which are called by n threads ( n is approx = 25 ) )
9
3107
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 to store multicast delegates in a hash table, and then fire the delegates one of two ways (after registering/ creating the delegates, etc).
0
8469
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7419
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.