By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,056 Members | 1,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,056 IT Pros & Developers. It's quick & easy.

The Set Class in C++ and Java

P: n/a
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
Share this Question
Share on Google+
16 Replies


P: n/a
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

P: n/a

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

P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.