The Set Class in C++ and Java

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • coosa

    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

  • Kevin Spencer

    #2
    Re: The Set Class in C++ and Java

    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:


    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Software Composer
    Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


    A watched clock never boils.

    "coosa" <coosa76@gmail. comwrote in message
    news:1159702414 .112222.83780@k 70g2000cwa.goog legroups.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
    >

    Comment

    • coosa

      #3
      Re: The Set Class in C++ and Java


      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:

      >
      --
      HTH,
      >
      Kevin Spencer
      Microsoft MVP
      Software Composer
      Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

      >
      A watched clock never boils.
      >
      "coosa" <coosa76@gmail. comwrote in message
      news:1159702414 .112222.83780@k 70g2000cwa.goog legroups.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

      Comment

      • Joanna Carter [TeamB]

        #4
        Re: The Set Class in C++ and Java

        "coosa" <coosa76@gmail. coma écrit dans le message de news:
        1159718633.0540 03.286170@c28g2 00...legr oups.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


        Comment

        • Kevin Spencer

          #5
          Re: The Set Class in C++ and Java

          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
          Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


          A watched clock never boils.

          "coosa" <coosa76@gmail. comwrote in message
          news:1159718633 .054003.286170@ c28g2000cwb.goo glegroups.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" <coosa76@gmail. comwrote in message
          >news:115970241 4.112222.83780@ k70g2000cwa.goo glegroups.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
          >

          Comment

          • coosa

            #6
            Re: The Set Class in C++ and Java

            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
            Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

            >
            A watched clock never boils.
            >
            "coosa" <coosa76@gmail. comwrote in message
            news:1159718633 .054003.286170@ c28g2000cwb.goo glegroups.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:

            >
            --
            HTH,
            >
            Kevin Spencer
            Microsoft MVP
            Software Composer
            Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

            >
            A watched clock never boils.
            >
            "coosa" <coosa76@gmail. comwrote in message
            news:1159702414 .112222.83780@k 70g2000cwa.goog legroups.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.

            Comment

            • Kevin Spencer

              #7
              Re: The Set Class in C++ and Java

              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.Collecti ons.ObjectModel
              (http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
              or System.Collecti ons.Generic
              (http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
              namespace classes.

              --
              HTH,

              Kevin Spencer
              Microsoft MVP
              Software Composer
              Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


              A watched clock never boils.

              "coosa" <coosa76@gmail. comwrote in message
              news:1159724719 .136866.127420@ i3g2000cwc.goog legroups.com...
              >"coosa" <coosa76@gmail. comwrote in message
              >news:115970241 4.112222.83780@ k70g2000cwa.goo glegroups.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.
              >

              Comment

              • Jon Skeet [C# MVP]

                #8
                Re: The Set Class in C++ and Java

                Kevin Spencer <uce@ftc.govwro te:
                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:


                Just to clarify :)

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

                Comment

                • Kevin Spencer

                  #9
                  Re: The Set Class in C++ and Java

                  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
                  Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.


                  A watched clock never boils.

                  "Jon Skeet [C# MVP]" <skeet@pobox.co mwrote in message
                  news:MPG.1f8ac3 01e43a2f6398d4f f@msnews.micros oft.com...
                  Kevin Spencer <uce@ftc.govwro te:
                  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:

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

                  Comment

                  • coosa

                    #10
                    Re: The Set Class in C++ and Java


                    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.Collecti ons.ObjectModel
                    (http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
                    or System.Collecti ons.Generic
                    (http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
                    namespace classes.
                    >
                    --
                    HTH,
                    >
                    Kevin Spencer
                    Microsoft MVP
                    Software Composer
                    Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

                    >
                    A watched clock never boils.
                    >
                    "coosa" <coosa76@gmail. comwrote in message
                    news:1159724719 .136866.127420@ i3g2000cwc.goog legroups.com...
                    "coosa" <coosa76@gmail. comwrote in message
                    news:1159702414 .112222.83780@k 70g2000cwa.goog legroups.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.Vecto r <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.

                    Comment

                    • coosa

                      #11
                      Re: The Set Class in C++ and Java


                      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.Collecti ons.ObjectModel
                      (http://msdn2.microsoft.com/en-us/lib...jectmodel.aspx)
                      or System.Collecti ons.Generic
                      (http://msdn2.microsoft.com/en-us/lib...s.generic.aspx)
                      namespace classes.
                      >
                      --
                      HTH,
                      >
                      Kevin Spencer
                      Microsoft MVP
                      Software Composer
                      Thoughts and Ideas about programming, philosophy, science, arts, life, God, and related subjects.

                      >
                      A watched clock never boils.
                      >
                      "coosa" <coosa76@gmail. comwrote in message
                      news:1159724719 .136866.127420@ i3g2000cwc.goog legroups.com...
                      "coosa" <coosa76@gmail. comwrote in message
                      news:1159702414 .112222.83780@k 70g2000cwa.goog legroups.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.Vecto r <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.

                      Comment

                      • Arne Vajhøj

                        #12
                        Re: The Set Class in C++ and Java

                        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.Vecto r <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

                        Comment

                        • coosa

                          #13
                          Re: The Set Class in C++ and Java


                          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.Vecto r <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

                          Comment

                          • Arne Vajhøj

                            #14
                            Re: The Set Class in C++ and Java

                            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

                            Comment

                            • nick_nw

                              #15
                              Re: The Set Class in C++ and Java


                              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


                              Comment

                              Working...