Home All Groups Group Topic Archive Search About

Any such thing as a single column HashTable?

Author
22 Mar 2007 4:54 PM
Joseph Geretz
Basically, I just need an efficient way to store and retrieve keys from a
list. I don't need key/value pairs. I've implemented this with the standard
HashTable, but the value column is a waste since every key has the same
value, "".

Thanks for your advice.

- Joe Geretz -

Author
22 Mar 2007 5:02 PM
Kevin Spencer
Array of strings?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

Show quote
"Joseph Geretz" <jgeretz@nospam.com> wrote in message
news:%23ZQYOMKbHHA.1296@TK2MSFTNGP02.phx.gbl...
> Basically, I just need an efficient way to store and retrieve keys from a
> list. I don't need key/value pairs. I've implemented this with the
> standard HashTable, but the value column is a waste since every key has
> the same value, "".
>
> Thanks for your advice.
>
> - Joe Geretz -
>
Author
22 Mar 2007 5:26 PM
Joseph Geretz
Hi Kevin,

> Array of strings?

Will this provide as efficient lookup as the HashTable?

Thanks,

- Joseph Geretz -

Show quote
"Kevin Spencer" <unclechut***@nothinks.com> wrote in message
news:O858PPKbHHA.4220@TK2MSFTNGP03.phx.gbl...
> Array of strings?
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
>
> Printing Components, Email Components,
> Networking Components, Controls, much more.
> DSI PrintManager, Miradyne Component Libraries:
> http://www.miradyne.net
>
> "Joseph Geretz" <jgeretz@nospam.com> wrote in message
> news:%23ZQYOMKbHHA.1296@TK2MSFTNGP02.phx.gbl...
>> Basically, I just need an efficient way to store and retrieve keys from a
>> list. I don't need key/value pairs. I've implemented this with the
>> standard HashTable, but the value column is a waste since every key has
>> the same value, "".
>>
>> Thanks for your advice.
>>
>> - Joe Geretz -
>>
>
>
Author
22 Mar 2007 5:08 PM
Jon Skeet [C# MVP]
On Mar 22, 4:54 pm, "Joseph Geretz" <jger...@nospam.com> wrote:
> Basically, I just need an efficient way to store and retrieve keys from a
> list. I don't need key/value pairs. I've implemented this with the standard
> HashTable, but the value column is a waste since every key has the same
> value, "".

So basically you want a set, right? No, there's nothing built into the
framework. Normally people just use HashTable/Dictionary<K,V> and use
a dummy value.

Jon
Author
22 Mar 2007 5:45 PM
Nicholas Paldino [.NET/C# MVP]
It might be a little early, but there will be the HashSet class in Orcas
which will introduce this class.  Just something to be aware of in the
future.


--
          - Nicholas Paldino [.NET/C# MVP]
          - mvp@spam.guard.caspershouse.com

Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:1174583295.016401.78460@l77g2000hsb.googlegroups.com...
> On Mar 22, 4:54 pm, "Joseph Geretz" <jger...@nospam.com> wrote:
>> Basically, I just need an efficient way to store and retrieve keys from a
>> list. I don't need key/value pairs. I've implemented this with the
>> standard
>> HashTable, but the value column is a waste since every key has the same
>> value, "".
>
> So basically you want a set, right? No, there's nothing built into the
> framework. Normally people just use HashTable/Dictionary<K,V> and use
> a dummy value.
>
> Jon
>
Author
22 Mar 2007 5:53 PM
Jon Skeet [C# MVP]
Nicholas Paldino [.NET/C# MVP] <mvp@spam.guard.caspershouse.com> wrote:
>     It might be a little early, but there will be the HashSet class in Orcas
> which will introduce this class.  Just something to be aware of in the
> future.

Hurrah! Only 5 years after it should have been present :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
22 Mar 2007 8:16 PM
Peter Bromberg [C# MVP]
I can't wait. :-)
Peter
Show quote
"Nicholas Paldino [.NET/C# MVP]" wrote:

>     It might be a little early, but there will be the HashSet class in Orcas
> which will introduce this class.  Just something to be aware of in the
> future.
>
>
> --
>           - Nicholas Paldino [.NET/C# MVP]
>           - mvp@spam.guard.caspershouse.com
>
> "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
> news:1174583295.016401.78460@l77g2000hsb.googlegroups.com...
> > On Mar 22, 4:54 pm, "Joseph Geretz" <jger...@nospam.com> wrote:
> >> Basically, I just need an efficient way to store and retrieve keys from a
> >> list. I don't need key/value pairs. I've implemented this with the
> >> standard
> >> HashTable, but the value column is a waste since every key has the same
> >> value, "".
> >
> > So basically you want a set, right? No, there's nothing built into the
> > framework. Normally people just use HashTable/Dictionary<K,V> and use
> > a dummy value.
> >
> > Jon
> >
>
>
>
Author
23 Mar 2007 4:44 PM
Brian Gideon
On Mar 22, 12:45 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.com> wrote:
>     It might be a little early, but there will be the HashSet class in Orcas
> which will introduce this class.  Just something to be aware of in the
> future.
>
> --
>           - Nicholas Paldino [.NET/C# MVP]
>           - m...@spam.guard.caspershouse.com
>

I was not aware of that until now.  I'm guessing it'll have union,
intersection, difference, etc. methods?  That would be nice.  Thanks
for the tip.
Author
22 Mar 2007 5:27 PM
Rad [Visual C# MVP]
On Thu, 22 Mar 2007 12:54:49 -0400, Joseph Geretz wrote:

> Basically, I just need an efficient way to store and retrieve keys from a
> list. I don't need key/value pairs. I've implemented this with the standard
> HashTable, but the value column is a waste since every key has the same
> value, "".
>
> Thanks for your advice.
>
> - Joe Geretz -

An array?
Author
22 Mar 2007 8:21 PM
Joseph Geretz
Hi Rad,

> An array?

Will this provide as efficient lookup as the HashTable?

Thanks,

- Joseph Geretz -

Show quote
"Rad [Visual C# MVP]" <nospam@nospam.com> wrote in message
news:4mwnai36wsnt$.dlg@thinkersroom.com...
> On Thu, 22 Mar 2007 12:54:49 -0400, Joseph Geretz wrote:
>
>> Basically, I just need an efficient way to store and retrieve keys from a
>> list. I don't need key/value pairs. I've implemented this with the
>> standard
>> HashTable, but the value column is a waste since every key has the same
>> value, "".
>>
>> Thanks for your advice.
>>
>> - Joe Geretz -
>
> An array?
> --
> Bits.Bytes
> http://bytes.thinkersroom.com
Author
22 Mar 2007 9:57 PM
EmeraldShield
>
>> An array?
>
> Will this provide as efficient lookup as the HashTable?
>

No, HashTable is your fastest lookup hands down.  Just put an INT in the
data with 0.  Then you can just use the keys.
Author
22 Mar 2007 10:05 PM
Jon Skeet [C# MVP]
EmeraldShield <emeraldshield@noemail.noemail> wrote:
> No, HashTable is your fastest lookup hands down.  Just put an INT in the
> data with 0.  Then you can just use the keys.

Using a plain HashTable, that's a really bad idea - the 0 would get
boxed every time. Using something like "" or even making the key also
the value is more efficient.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Author
22 Mar 2007 10:24 PM
Joseph Geretz
Thanks Jon,

I've been using "" for the value.

- Joe Geretz -

Show quote
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MPG.206d0de5c0a95f6998da01@msnews.microsoft.com...
> EmeraldShield <emeraldshield@noemail.noemail> wrote:
>> No, HashTable is your fastest lookup hands down.  Just put an INT in the
>> data with 0.  Then you can just use the keys.
>
> Using a plain HashTable, that's a really bad idea - the 0 would get
> boxed every time. Using something like "" or even making the key also
> the value is more efficient.
>
> --
> Jon Skeet - <sk***@pobox.com>
> http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
Author
23 Mar 2007 12:35 PM
Kevin Spencer
> Will this provide as efficient lookup as the HashTable?

What are you trying to look up?

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
Networking Components, Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

Show quote
"Joseph Geretz" <jgeretz@nospam.com> wrote in message
news:uCXGR$LbHHA.3616@TK2MSFTNGP05.phx.gbl...
> Hi Rad,
>
>> An array?
>
> Will this provide as efficient lookup as the HashTable?
>
> Thanks,
>
> - Joseph Geretz -
>
> "Rad [Visual C# MVP]" <nospam@nospam.com> wrote in message
> news:4mwnai36wsnt$.dlg@thinkersroom.com...
>> On Thu, 22 Mar 2007 12:54:49 -0400, Joseph Geretz wrote:
>>
>>> Basically, I just need an efficient way to store and retrieve keys from
>>> a
>>> list. I don't need key/value pairs. I've implemented this with the
>>> standard
>>> HashTable, but the value column is a waste since every key has the same
>>> value, "".
>>>
>>> Thanks for your advice.
>>>
>>> - Joe Geretz -
>>
>> An array?
>> --
>> Bits.Bytes
>> http://bytes.thinkersroom.com
>
>
Author
22 Mar 2007 8:19 PM
Peter Bromberg [C# MVP]
How about a StringDictionary? http://msdn2.microsoft.com/en-us/library/system.collections.specialized.stringdictionary_members.aspx

It still has that nasty Value member, but its strongly typed and has the
nice convenience lookup methods.
Peter

Show quote
"Joseph Geretz" wrote:

> Basically, I just need an efficient way to store and retrieve keys from a
> list. I don't need key/value pairs. I've implemented this with the standard
> HashTable, but the value column is a waste since every key has the same
> value, "".
>
> Thanks for your advice.
>
> - Joe Geretz -
>
>
>

AddThis Social Bookmark Button