473,394 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

The Set Class in C++ and Java

Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have been
searching in C# for a similar container as in c++ or collection as in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards

Oct 1 '06 #1
16 2092
There is no equivalent in C# for the Java Set class, unfortunately. I did,
however, come across an excellent implementation of a Set class here:
http://www.devhood.com/tools/tool_de...px?tool_id=174

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have been
searching in C# for a similar container as in c++ or collection as in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards

Oct 1 '06 #2

Kevin Spencer wrote:
There is no equivalent in C# for the Java Set class, unfortunately. I did,
however, come across an excellent implementation of a Set class here:
http://www.devhood.com/tools/tool_de...px?tool_id=174

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have been
searching in C# for a similar container as in c++ or collection as in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards
I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken

Oct 1 '06 #3
"coosa" <co*****@gmail.coma écrit dans le message de news:
11**********************@c28g2000cwb.googlegroups. com...

| I believe the Set.cs link http://www.devhood.com/tools/myDownload is
| broken

The link works from here, but I wouldn't bother using the class as it is not
typesafe at all, items in the set are added and removed as objects.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Oct 1 '06 #4
I am able to download the file. I don't know where you got the URL for the
file that you posted, because the link I used was an ASP.Net Control on the
page which performs a PostBack to retrieve the file. If you look on the page
near the top of the article, you will see the following text:

Download This Tool: Set.cs

The text "Set.cs" is the hyperlink to download the code. I would post it
myself, but I'm not sure that would be kosher, since I was not the author.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...
>
Kevin Spencer wrote:
>There is no equivalent in C# for the Java Set class, unfortunately. I
did,
however, come across an excellent implementation of a Set class here:
http://www.devhood.com/tools/tool_de...px?tool_id=174

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegr oups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have been
searching in C# for a similar container as in c++ or collection as in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards

I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken

Oct 1 '06 #5
Kevin Spencer wrote:
I am able to download the file. I don't know where you got the URL for the
file that you posted, because the link I used was an ASP.Net Control on the
page which performs a PostBack to retrieve the file. If you look on the page
near the top of the article, you will see the following text:

Download This Tool: Set.cs

The text "Set.cs" is the hyperlink to download the code. I would post it
myself, but I'm not sure that would be kosher, since I was not the author.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11**********************@c28g2000cwb.googlegr oups.com...

Kevin Spencer wrote:
There is no equivalent in C# for the Java Set class, unfortunately. I
did,
however, come across an excellent implementation of a Set class here:
http://www.devhood.com/tools/tool_de...px?tool_id=174

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have been
searching in C# for a similar container as in c++ or collection as in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards
I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken
My bad, my mozilla firefox prevented the scripts for the page, so i
couldn't download it! :-)
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

Oct 1 '06 #6
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.
The Java Set Interface is not strongly-typed either. In fact, it can contain
any combination of data in it, not just one type. See
http://java.sun.com/j2se/1.4.2/docs/.../util/Set.html. I saw quite a
number of other C# Set Class implementations (see
http://www.google.com/search?hl=en&q=C%23+Set+Class), but the one that I
pointed you to was the closest one to the Java Set Interface, which I
thought was what you were looking for.

In any case, you are free to create your own Collection classes, derive from
any existing Collection class, and implement whatever functionality you
desire. Perhaps, considering your desire for strong typing, you might want
to start from one of the System.Collections.ObjectModel
(http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
or System.Collections.Generic
(http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
namespace classes.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
>"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegr oups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have
been
searching in C# for a similar container as in c++ or collection as
in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards
I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken

My bad, my mozilla firefox prevented the scripts for the page, so i
couldn't download it! :-)
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

Oct 1 '06 #7
Kevin Spencer <uc*@ftc.govwrote:
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

The Java Set Interface is not strongly-typed either. In fact, it can contain
any combination of data in it, not just one type. See
http://java.sun.com/j2se/1.4.2/docs/.../util/Set.html.
Well, that was pre-generics in Java. Look at:
http://java.sun.com/j2se/1.5.0/docs/.../util/Set.html

Just to clarify :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 2 '06 #8
Understood, Jon. However, I do think that the ability to include instances
of multiple types is useful, and of course, this is still possible with the
generic Set class if you define the type as object.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
Kevin Spencer <uc*@ftc.govwrote:
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

The Java Set Interface is not strongly-typed either. In fact, it can
contain
any combination of data in it, not just one type. See
http://java.sun.com/j2se/1.4.2/docs/.../util/Set.html.

Well, that was pre-generics in Java. Look at:
http://java.sun.com/j2se/1.5.0/docs/.../util/Set.html

Just to clarify :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Oct 2 '06 #9

Kevin Spencer wrote:
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

The Java Set Interface is not strongly-typed either. In fact, it can contain
any combination of data in it, not just one type. See
http://java.sun.com/j2se/1.4.2/docs/.../util/Set.html. I saw quite a
number of other C# Set Class implementations (see
http://www.google.com/search?hl=en&q=C%23+Set+Class), but the one that I
pointed you to was the closest one to the Java Set Interface, which I
thought was what you were looking for.

In any case, you are free to create your own Collection classes, derive from
any existing Collection class, and implement whatever functionality you
desire. Perhaps, considering your desire for strong typing, you might want
to start from one of the System.Collections.ObjectModel
(http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
or System.Collections.Generic
(http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
namespace classes.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have
been
searching in C# for a similar container as in c++ or collection as
in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards
I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken
My bad, my mozilla firefox prevented the scripts for the page, so i
couldn't download it! :-)
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.
That is not true at all,

Since JDK 1.5 Update 2, Java came up with alot of stong typed generics
including the vector , set, ...etc. classes.
Earlier you could not for instance use a statement in Java like this:
java.util.Vector <SomeClassv; It took every thing as object and u
needed to cast. However, as from Update 2 i guess of 1.5 jdk, they
adapted the STL implementation of strong typing.

Oct 3 '06 #10

Kevin Spencer wrote:
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.

The Java Set Interface is not strongly-typed either. In fact, it can contain
any combination of data in it, not just one type. See
http://java.sun.com/j2se/1.4.2/docs/.../util/Set.html. I saw quite a
number of other C# Set Class implementations (see
http://www.google.com/search?hl=en&q=C%23+Set+Class), but the one that I
pointed you to was the closest one to the Java Set Interface, which I
thought was what you were looking for.

In any case, you are free to create your own Collection classes, derive from
any existing Collection class, and implement whatever functionality you
desire. Perhaps, considering your desire for strong typing, you might want
to start from one of the System.Collections.ObjectModel
(http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
or System.Collections.Generic
(http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
namespace classes.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

A watched clock never boils.

"coosa" <co*****@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
"coosa" <co*****@gmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
Dear all,

I'm familiar with the Set Class in C++ and Java; however, i have
been
searching in C# for a similar container as in c++ or collection as
in
java, but couldn't find one.
Could some one tell me about the the Set implementation inside .NET?

Best regards
I believe the Set.cs link http://www.devhood.com/tools/myDownload is
broken
My bad, my mozilla firefox prevented the scripts for the page, so i
couldn't download it! :-)
any way, i have checked the file; it doesn't first implement generics
and doesn't really consider strong typing.
Any way; i really hope that Microsoft comes out with a Set
implementation in their future releases.
As an alternative, i see the HashTable, but considering a constantly
sorted range complexity of the tree, a HashTable is not always the
better choice since the fast lookup is what makes it very powerful.
That is not true at all,

Since JDK 1.5 Update 2, Java came up with alot of stong typed generics
including the vector , set, ...etc. classes.
Earlier you could not for instance use a statement in Java like this:
java.util.Vector <SomeClassv; It took every thing as object and u
needed to cast. However, as from Update 2 i guess of 1.5 jdk, they
adapted the STL implementation of strong typing.

Oct 3 '06 #11
coosa wrote:
Since JDK 1.5 Update 2, Java came up with alot of stong typed generics
including the vector , set, ...etc. classes.
Earlier you could not for instance use a statement in Java like this:
java.util.Vector <SomeClassv; It took every thing as object and u
needed to cast. However, as from Update 2 i guess of 1.5 jdk, they
adapted the STL implementation of strong typing.
Generics were in Java 1.5 from the start. It was not added
in update 2.

Java generics and C++ STL are not the same.

Arne
Oct 4 '06 #12

Arne Vajhøj wrote:
coosa wrote:
Since JDK 1.5 Update 2, Java came up with alot of stong typed generics
including the vector , set, ...etc. classes.
Earlier you could not for instance use a statement in Java like this:
java.util.Vector <SomeClassv; It took every thing as object and u
needed to cast. However, as from Update 2 i guess of 1.5 jdk, they
adapted the STL implementation of strong typing.

Generics were in Java 1.5 from the start. It was not added
in update 2.

Java generics and C++ STL are not the same.

Arne
I'm aware they are not the same, but so far i recall the adding of a
template class for the Vectors in java by update 2 <since i by 1.5 i
couldn't find such in the api until i downloaded update 2.
But whether update 1, 2 or from the star tof 1.5, i just wanted to say
that Java supports generics

Oct 4 '06 #13
coosa wrote:
Arne Vajhøj wrote:
>Generics were in Java 1.5 from the start. It was not added
in update 2.

Java generics and C++ STL are not the same.

I'm aware they are not the same, but so far i recall the adding of a
template class for the Vectors in java by update 2 <since i by 1.5 i
couldn't find such in the api until i downloaded update 2.
I still have the first release of 1.5 installed.

Vector is generic.

They do not add new functionality to updates, they only
fix bugs.
But whether update 1, 2 or from the star tof 1.5, i just wanted to say
that Java supports generics
That is true !

Arne
Oct 5 '06 #14

Arne Vajhøj wrote:
coosa wrote:
Arne Vajhøj wrote:
Generics were in Java 1.5 from the start. It was not added
in update 2.

Java generics and C++ STL are not the same.
I'm aware they are not the same, but so far i recall the adding of a
template class for the Vectors in java by update 2 <since i by 1.5 i
couldn't find such in the api until i downloaded update 2.

I still have the first release of 1.5 installed.

Vector is generic.

They do not add new functionality to updates, they only
fix bugs.
But whether update 1, 2 or from the star tof 1.5, i just wanted to say
that Java supports generics

That is true !

Arne
As far as I'm aware Java generics are just syntactic sugar enforced at
compile time, but the resultant code will still be a collection of
Objects.

C# generics result in a collection of the correct type, so I generic
list specified as <intwill actually be a list of ints with no
boxing/unboxing required.

(I am not saying that one language is better than the other, just
pointing out a difference)

Nick
http://seecharp.blogspot.com/

Oct 5 '06 #15
nick_nw wrote:
Arne Vajhøj wrote:
>coosa wrote:
>>But whether update 1, 2 or from the star tof 1.5, i just wanted to say
that Java supports generics
>That is true !
As far as I'm aware Java generics are just syntactic sugar enforced at
compile time, but the resultant code will still be a collection of
Objects.
Java and C# has almost the same syntax for generics, but
the implementation in Java byte code and MSIL is very
different.

Java generics basically disappear in the Java byte code. In
most cases it is not significant. But in some cases it
can cause unexpected results for the programmer who have
not understood the concept.
C# generics result in a collection of the correct type, so I generic
list specified as <intwill actually be a list of ints with no
boxing/unboxing required.
I can not see any connection between type erasure and
boxing/unboxing.

ArrayList<intis not valid in Java. Accessing an
ArrayList<Integerdoes not cause any boxing/unboxing.

Boxing/unboxing between Integer and int obviously
causes boxing/unboxing.

Arne
Oct 6 '06 #16
Arne Vajhøj <ar**@vajhoej.dkwrote:
As far as I'm aware Java generics are just syntactic sugar enforced at
compile time, but the resultant code will still be a collection of
Objects.
Java and C# has almost the same syntax for generics, but
the implementation in Java byte code and MSIL is very
different.
Well, they have similar syntax for a small part of it - the way a
generic type name is written, eg List<String>. They differ in:

o How constraints are expressed
o How generic methods are declared
o Covarance/contravariance
Java generics basically disappear in the Java byte code. In
most cases it is not significant. But in some cases it
can cause unexpected results for the programmer who have
not understood the concept.
Unfortunately it makes things very limiting in some ways, because the
information isn't available at runtime. It becomes unsafe (in unobvious
ways) to cast to a generic type, whereas in .NET the cast can be
checked properly at runtime.

Of course, Java has covariance and contravariance which C# doesn't
support, so it's not all one-way...
C# generics result in a collection of the correct type, so I generic
list specified as <intwill actually be a list of ints with no
boxing/unboxing required.
I can not see any connection between type erasure and
boxing/unboxing.

ArrayList<intis not valid in Java. Accessing an
ArrayList<Integerdoes not cause any boxing/unboxing.

Boxing/unboxing between Integer and int obviously
causes boxing/unboxing.
It's worth remembering that another feature of Java 5 is auto-boxing
and auto-unboxing though, so if you do:

List<Integerlist = new ArrayList<Integer>();
list.add(5);
int x = list.get(0);

that's okay.

What's slightly surprising is that boxing doesn't always create a new
object:

Integer a1 = 5;
Integer a2 = 5; // Now a1==a2

but

Integer a3 = 4000;
Integer a4 = 4000; // a3!=a4

(Obviously a3.equals(a4), but the references aren't equal.)

Just a little bit of trivia...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 6 '06 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Fu Bo Xia | last post by:
the java.lang.Object.forName method takes a java class name and returns a Class object associated with that class. eg. Class myClass = Object.forName("java.lang.String"); by if i only know the...
19
by: Dave | last post by:
Hi, I have done some research, trying to Clear The Screen in java code. The first option was the obv: system.out.print("\n\n\n\n\n\n\n\n\n\n\n\n"); then i heard about this method:...
4
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
1
by: Andrew James | last post by:
All, I'm having some trouble with understanding python's importing behaviour in my application. I'm using psyco to optimise part of my code, but I'm not sure whether it inherits throughout the...
14
by: Mick | last post by:
I wrote a C# program that interfaces with a data vendor over the web using an API they supplied and their examples in C#. Now I have another data vendor's API and example that I want to add to...
1
by: bjwillykajilly | last post by:
Well, I got an assignment due this morning, so i guess ill end up turning it in a day late eh. anyways. I have a couple problems that I don't know what to do with. the objective is here: Write a...
1
by: aapexclient | last post by:
I have a problem with Java finding my custom class directory. I have searched the forums and tried everything, but nothing seems to work. The <javapgm>.java compiled cleanly and created...
2
by: inetjack | last post by:
Hi, This is a little test application, generating and compiling code at runtime. The loadClassLoader() method of the Factory Object suppose to unload all class previously loaded. It does not...
4
by: vasavimaruthi | last post by:
hi, i got class not found exception of a small jdbc program in windows. the program is like this import java.sql.*; public class Db1 { public static void main(String a)...
1
by: sandhyabhavani | last post by:
This article is used to zip a file or directory using vb.net. The classes and method to zip a file is availale in java.io, java.util, java.util.zip class library.To import these you have to add a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.