Find unique strings for a string array
-
*shrug* I think Hashset< T>.Add(T item) returning bool if it was unique is close enough. People use LINQ because it makes the code more readable. Generally CPU is cheap and good programmers aren't. Its ok to have a 10% overhead if your code is more reliable and easier to maintain as a result.
Mark Churchill Director, Dunn & Churchill Pty Ltd Free Download: Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.
Alpha release: Entanglar: Transparant multiplayer framework for .Net games.Thanks Mark, 1. "*shrug* I think Hashset< T>.Add(T item) returning bool if it was unique is close enough." -- I am still confused why do you think .Net built-in Hashset is good enough. Any comments? 2. I know about LINQ but not very experienced. My concern about LINQ is, I do not think it is more readable, why do you think it is more readable? 3. LINQ is only 10% slower? I think it is much slower in my experience. Do you have any performance benchmarking data? regards, George
-
What are the advantages of your Set class over .Net Set class? regards, George
Operators.
-
George_George wrote:
BTW: if LINQ is slow, why people will use LINQ?
I think Mark is right. We can get the benefits from LINQ for integrating the data and object. But I am not sure about the performance of LINQ. Though I do believe Mircosoft would make greate efforts to improve it.
LuckyBoy
In my experience and other guys besides me, the performnace feedback of LINQ is bad. :-) What about yours? regards, George
-
Sounds to me like you should be using a set data structure, if you never need the duplicate strings.
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
Thanks Dan! But there is no such data structure in .Net, correct? regards, George
-
public class set { private List theList; public bool Add(T item) { if (theList.Contains(item)) return false; theList.Add(item); return true; } } This is the start of a set class, a container that only contains one of any object.
Christian Graus Driven to the arms of OSX by Vista.
Thanks Christian, I like your idea. I am surprised why there is no built-in Set class in .Net. :-) regards, George
-
May be
Array.FindAll
can help you. Check out MSDN for it. Another way could be: 1. Create a list/hashtable. Then loop through the array. 2. Check if the element exists in the list/hashtable. 3. If it does its a duplicate value. Remove it from array. 4. If it doesnt add it to the list/hashtable.C isn't that hard: void (*(*f[])())() defines f as an array of unspecified size, of pointers to functions that return pointers to functions that return void "Always program as if the person who will be maintaining your program is a violent psychopath that knows where you live." - Martin Golding
Hi d@nish, I have studied related MSDN page about Array.FindAll, but I do not think it could help me in my solution. Do you have any pesudo code to show your idea of using Array.FindAll to make a unique string array? regards, George
-
Generic does means only List.We have some more like Dictionary,SortedList,Queue,Stack but list suits your requirement best.
Cheers!! Brij
Thanks for your clarification, Brij! regards, George
-
Operators.
Could you show more description please? What operators do you think your class provides has advantages over .Net built-in ones? regards, George
-
Thanks Dan! But there is no such data structure in .Net, correct? regards, George
Hey There isnt an inbuilt one but take a look at this post, or you could even implement your own if you are bored and have some time :P http://stackoverflow.com/questions/10458/is-there-a-set-data-structure-in-net[^] Hope that helps
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
-
In my experience and other guys besides me, the performnace feedback of LINQ is bad. :-) What about yours? regards, George
In fact, I did not use LINQ quite often in my project. Hence I could not give you any comment about performance of LINQ, especially without investigating from performance tool. However, I have to admit the creativity of LINQ. For a certain degree, it presents the .net technology tendency-integrate data. Although maybe the final goal is ambitious and full of issues, such as performance, complexity, nobody would ignore the benefits form LINQ. :)
LuckyBoy
-
Hey There isnt an inbuilt one but take a look at this post, or you could even implement your own if you are bored and have some time :P http://stackoverflow.com/questions/10458/is-there-a-set-data-structure-in-net[^] Hope that helps
At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan
Thanks Dan! Good stuff! regards, George
-
In fact, I did not use LINQ quite often in my project. Hence I could not give you any comment about performance of LINQ, especially without investigating from performance tool. However, I have to admit the creativity of LINQ. For a certain degree, it presents the .net technology tendency-integrate data. Although maybe the final goal is ambitious and full of issues, such as performance, complexity, nobody would ignore the benefits form LINQ. :)
LuckyBoy
Hi LuckyBoy, I think ising ADO.Net is fine enough, why bothering using LINQ? :-) regards, George
-
Hi LuckyBoy, I think ising ADO.Net is fine enough, why bothering using LINQ? :-) regards, George
Well, Language Integrated Query, maybe to provide a common QUERY method for various data source from different domains, such as ADO.net, XML, SQL server, is the way how microsoft simplify the access for data and object. But it is still young, so let us try to be nice and patient.
Tan Li I Love KongFu~
-
Well, Language Integrated Query, maybe to provide a common QUERY method for various data source from different domains, such as ADO.net, XML, SQL server, is the way how microsoft simplify the access for data and object. But it is still young, so let us try to be nice and patient.
Tan Li I Love KongFu~
Thanks Tan Li! regards, George
-
Thanks Tan Li! regards, George
Welcome~
Tan Li I Love KongFu~