winforms - C# Removing Dublettes from List -
i have got list changing every second. want check list, if gets big. first step delete double entries list.
there many ways accomplish this. have seen hashtables
, linq
, others. problem need fast way accomplish this.
there quite lot of entries in list, , user shouldn't see application freezing, if possible, because application showing animation.
i don't know, if can use hashtables
, because order of objects inside of list should kept untouched, if possible.
i tried using linq , groupby, working on visual studio 2008, not contain linq statement.
the objects not simple. imagine object car. can have manufacturer, manufacturing time, model name, etc.
i want see if manufacturer , model name twice inside of list. manufacturing time not important , should ignored.
in end want delete double entries list.
i happy suggestions. if have ideas please write them down , see.
rather delete double entries when list gets big, not better not allow double entries in first place? 1 way combine collection index of sort.
the normal practice use have 2 collections - 1 data , 1 index.
list<myclass> _collection; dictionary<myclasskey, myclass> _index;
then when add, first check index , add if it's not there - otherwise don't add.
void add(myclass item) { if (!_index.containskey[item.key]) { _collection.add(item); _index.add(item.key, item); } }
this remove problem of deleting duplicates later , therefore no ui slowdown.
obviously code above not thread safe - it's illustrate point.
Comments
Post a Comment