473,325 Members | 2,771 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,325 software developers and data experts.

How to check if a string exists in a set of strings?

Hi All,

What is the fastest way to check the existence of a string in a set of
strings?

I have thought of putting the set of strings in a HashMap and then us
containsKey() to do the check but I don't like because this is the
objective of HashMap.

What else do you recommend?

Thanks in advance.

Jul 17 '05 #1
11 4798
Andrew Thompson wrote:
On Fri, 12 Mar 2004 03:05:46 GMT, someone wrote:

What is the fastest way to check the existence of a string in a set of
strings?

HashMap

I have thought of putting the set of strings in a HashMap and then us
containsKey() to do the check but I don't like because this is the
objective of HashMap.

?!?! So, you would not think to
use Applet class for an Applet,
because that is the objective of
Applet?


Sorry, I miss-typed it. I meant NOT the objective because in my case I
don't key-value pairs, I have only keys.
Reminds me of 'Flying High'
"But no ..wait. That's _exactly_
what they'll be expecting."

What else do you recommend?

HashMap, ..and posting information
or questions that makes sense.


Jul 17 '05 #2
someone wrote:

Sorry, I miss-typed it. I meant NOT the objective because in my case I
don't key-value pairs, I have only keys.


Then, clearly, use HashSet.
Jul 17 '05 #3
Andrew Thompson wrote:
On Fri, 12 Mar 2004 03:28:12 GMT, someone wrote:

Andrew Thompson wrote:
On Fri, 12 Mar 2004 03:05:46 GMT, someone wrote:
..
What is the fastest way to check the existence of a string in a set of
strings?
..
I have thought of putting the set of strings in a HashMap and then us
containsKey() to do the check but I don't like because this is the
objective of HashMap.

...
Sorry, I miss-typed it. I meant NOT the objective..

Ahaaa! Thanks for clarifying.
[ As you may have guessed, that
read quite ..oddly. ]

I expect Carl's answer solved the problem?


Yes, of course!
[ defunct group c.l.j deleted *again* ]


Jul 17 '05 #4
Carl Howells wrote:
someone wrote:

Sorry, I miss-typed it. I meant NOT the objective because in my case I
don't key-value pairs, I have only keys.

Then, clearly, use HashSet.


Carl, thanks a lot!!!

Jul 17 '05 #5
someone wrote:
Sorry, I miss-typed it. I meant NOT the objective because in my case
I don't key-value pairs, I have only keys.


Then, clearly, use HashSet.

Carl, thanks a lot!!!


Although HashSet is in fact nothing but a wrapper around a HashMap that hides the
values functionality.

Jul 17 '05 #6
Michael Borgwardt wrote:
someone wrote:
Sorry, I miss-typed it. I meant NOT the objective because in my case
I don't key-value pairs, I have only keys.


Then, clearly, use HashSet.


Carl, thanks a lot!!!

Although HashSet is in fact nothing but a wrapper around a HashMap that
hides the
values functionality.


What do you suggest?

Jul 17 '05 #7
someone wrote:
Although HashSet is in fact nothing but a wrapper around a HashMap
that hides the values functionality.

What do you suggest?


Oh, using HashSet is fine, it makes the intent clearer. I just wanted
to point out that you still end up using a HashMap underneath (with
null values).
Jul 17 '05 #8
Michael Borgwardt wrote:
someone wrote:
Although HashSet is in fact nothing but a wrapper around a HashMap
that hides the values functionality.


What do you suggest?

Oh, using HashSet is fine, it makes the intent clearer. I just wanted
to point out that you still end up using a HashMap underneath (with
null values).


In fact, I noticed a performance difference between HashMap and HashSet
for my case, HashSet was faster.

Jul 17 '05 #9

"someone" <so*****@somewhere.com> wrote in message
news:40**************@somewhere.com...
Michael Borgwardt wrote:
someone wrote:
Although HashSet is in fact nothing but a wrapper around a HashMap
that hides the values functionality.

What do you suggest?

Oh, using HashSet is fine, it makes the intent clearer. I just wanted
to point out that you still end up using a HashMap underneath (with
null values).


In fact, I noticed a performance difference between HashMap and HashSet
for my case, HashSet was faster.


That is very unlikely since HashSet does no more than forward calls to a
private HashMap.

Silvio Bierman
Jul 17 '05 #10
Silvio Bierman wrote:
"someone" <so*****@somewhere.com> wrote in message
news:40**************@somewhere.com...
Michael Borgwardt wrote:
someone wrote:
>Although HashSet is in fact nothing but a wrapper around a HashMap
>that hides the values functionality.

What do you suggest?
Oh, using HashSet is fine, it makes the intent clearer. I just wanted
to point out that you still end up using a HashMap underneath (with
null values).


In fact, I noticed a performance difference between HashMap and HashSet
for my case, HashSet was faster.

That is very unlikely since HashSet does no more than forward calls to a
private HashMap.


Maybe this is due to saving the overhead of assigning the value field of
the key-value pair!?

Jul 17 '05 #11

"someone" <so*****@somewhere.com> wrote in message
news:40**************@somewhere.com...
Silvio Bierman wrote:
"someone" <so*****@somewhere.com> wrote in message
news:40**************@somewhere.com...
Michael Borgwardt wrote:

someone wrote:
>>Although HashSet is in fact nothing but a wrapper around a HashMap
>>that hides the values functionality.
>
>
>
>What do you suggest?
Oh, using HashSet is fine, it makes the intent clearer. I just wanted
to point out that you still end up using a HashMap underneath (with
null values).

In fact, I noticed a performance difference between HashMap and HashSet
for my case, HashSet was faster.

That is very unlikely since HashSet does no more than forward calls to a
private HashMap.


Maybe this is due to saving the overhead of assigning the value field of
the key-value pair!?


I think you are missing the point here. HashSet does not save that overhead
since it DOES assign a value field for every key you insert (with value
null). So if you compare HashSet to using HashMap with null-values for each
key yourself HashSet is totally equivalent except for adding the overhead of
forwarding the call to the internal HashMap.

Note that this is a minor detail and using HashSet for this situation is
always better than using HashMap with null-values since it makes your intent
explicit. The performance penalty induced by the HashSet implementation is
negligible.

Regards,

Silvio Bierman
Jul 17 '05 #12

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

Similar topics

2
by: Mike | last post by:
I´ve got a number of SPAN elements named "mySpan1", "mySpan2", "mySpan3" etc, and want to set their "style.display" to "inline". This works (only needs to work on IE5.5+): for (var x = 1; x <...
2
by: Chris Windsor | last post by:
I hope the following describe what I'm trying to do: I have created a tool to be used by product analysts when studying different cell phone designs. Part of the tool is a set of 11 forms on a...
22
by: spike | last post by:
How do i reset a string? I just want to empty it som that it does not contain any characters Say it contains "hello world" at the time... I want it to contain "". Nothing that is.. Thanx
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
9
by: a | last post by:
I need to write a regular expression to match a quoted string in which the double quote character itself is represented by 2 double quotes. For example: "beginning ""nested quoted string"" end"...
2
by: CCLeasing | last post by:
If (Directory.Exists(@"c:\indigo\" + txtOfficial + @"\" + comOffice.Text + @"\" + numTerm.Value.ToString())) { storereport(); } else { Directory.CreateDirectory(@"c:\indigo\" + txtOfficial +...
3
by: trint | last post by:
How can I do this with my c# code with my website(because the file is there, but the code doesn't return it)?: if(File.Exists(String.Format("~/images/categories/{0}", sFileName)) return...
6
by: dudeja.rajat | last post by:
Hi, How to check if something is a list or a dictionary or just a string? Eg: for item in self.__libVerDict.itervalues(): self.cbAnalysisLibVersion(END, item) where __libVerDict is a...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.