Alex Rivera | Logout

What data structures in .NET do O(1) on Contains() calls?

Asked 2010-09-28T01:47:00.133
9

I'm drawing a blank here; I can't find it, unless I'm really overlooking something under my nose.

I'm trying to store a list of ints in a data structure.
But after I add them, I will later in code check if an int exists in the list already.

The generic List<int> does an O(n) operation with its Contains().
I want something that works as fast as Dictionary<>'s Contains(), which does an O(1) operation because it hashes the keys.

I know the answer is something so simple and that I've worked for too long today I can't remember it.

Help!

Edit
Report

1 Answer

10

Will HashSet<T> work for you?

answered 2010-09-28T01:49:06.660

Your Answer