Is there a collection among .NET collection that doesn't allow duplicates?
ArrayList is very suitable for what I need, except it allows duplicate values.
I've searched the System.Collections namespace but couldn't find anything alike.
Printable View
Is there a collection among .NET collection that doesn't allow duplicates?
ArrayList is very suitable for what I need, except it allows duplicate values.
I've searched the System.Collections namespace but couldn't find anything alike.
Couldn't find one myself so knocked up a simple implementation of Set
Thank you Norfy, very nice implementation.
I was going to implement a set anyway,
just wanted to check if there's already an implementation among .NET's collections.
No problem, just thought I would save you some typing.
For that alone could you 'rate this post'? :)
I would like to, but...
Quote:
You must spread some Reputation around before giving it to Norfy again.
Ah yes, multiple inheritance post ;)
Yes. :blush:Quote:
Originally Posted by Norfy
Quite simply, the behaviour of the keys collection of a Hashtable is that of a set.Quote:
Originally Posted by mehdi62b (Rating Comment)
For small sets then an IList is ok but for larger sets a Hashtable is quicker.
there are some interesting collections that NHibernate uses...
the DLL is Iesi.Collections.
I don't know the licensing policy, but i think they're ok generally. :)
we want to just look for in an collection and keys in hashtable are just an ICollection ...hastable is fast but when we give a key and want its item,well its time is O(1)Quote:
Originally Posted by Norfy
but when we want to get whether an item is included or not..
no difference between a hashtable(keys) and IList...(both of them are an ICollection)
both of them have O(n).
Sorry mehdi62b I couldn't follow your comment.
Whether you ask a Hashtable for a value or if it contains a key the access time is not linear O(n) , it uses hashing for both.
The keys are returned as an ICollection but are not implemented as such internally.
I meant when we ask a hashtable whetere it contains a key the time is not O(1)..I meant it doesn't use hashing...Quote:
Originally Posted by Norfy
and you tell it use hashing(how?) ..I don't know exactly..
no problem...should have a look at one of my book :wave:
Have you checked out Reflector yet?Quote:
Originally Posted by mehdi62b
Nice tool, lets you browse the (decompiled) core .NET libraries.
I will check that link :thumb:
Hi Norfy,
thank you very much for that link..I didn't know it..its very usefull tool
and yes,you were right..
public virtual bool Contains(object item);Declaring Type:System.Collections.ArrayList
and it clearly shows it has O(n)Code:public virtual bool Contains(object item)
{
if (item == null)
{
for (int num1 = 0; num1 < this._size; num1++)
{
if (this._items[num1] == null)
{
return true;
}
}
return false;
}
for (int num2 = 0; num2 < this._size; num2++)
{
if (item.Equals(this._items[num2]))
{
return true;
}
}
return false;
}
and to be countinued...