Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a dictionary when the Key and the Value are the same?

I want to hold about 30 strings in a static "collection". I then need to check the path of an incoming web request against this list.

I was thinking of using a StringDictionary with the Key and the Value having the the same values. However it just seems odd when all I really want is a key look up, so I can check for existence rather than look up a value to use.

Am I worrying about nothing?

Pat

like image 201
Pat Long - Munkii Yebee Avatar asked Dec 03 '22 16:12

Pat Long - Munkii Yebee


2 Answers

What language are you using?

.NET supports Hashset<>, which fits what you're describing.

like image 161
teedyay Avatar answered Jan 06 '23 06:01

teedyay


If you just need a key lookup to check for existence, use a Set instead.

like image 37
Eric Petroelje Avatar answered Jan 06 '23 06:01

Eric Petroelje