Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSet<int> not unspecified?

QSet<int> not unspecified?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by Taz742
    #1

    Hi.
    Why QSet<int> not sorted?

        QSet<int> st;
        st.insert(5);
        st.insert(3);
        st.insert(17);
    
        for (auto it = st.begin(); it != st.end(); ++it) {
            qDebug() << *it;
        }//output is: 17, 3, 5.
    

    Documentation say:
    It stores values in an unspecified order and provides very fast lookup of the values. Internally, QSet<T> is implemented as a QHash.

    I excepted similar to std::set<T>

    Do what you want.

    JonBJ K 2 Replies Last reply
    0
    • Taz742T Taz742

      Hi.
      Why QSet<int> not sorted?

          QSet<int> st;
          st.insert(5);
          st.insert(3);
          st.insert(17);
      
          for (auto it = st.begin(); it != st.end(); ++it) {
              qDebug() << *it;
          }//output is: 17, 3, 5.
      

      Documentation say:
      It stores values in an unspecified order and provides very fast lookup of the values. Internally, QSet<T> is implemented as a QHash.

      I excepted similar to std::set<T>

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Taz742 said in QSet<int> not sorted?:

      Hi.
      Why QSet<int> not sorted?

      Documentation say:
      It stores values in an unspecified order

      Umm, precisely because it states the order is "unspecified" not "sorted"?

      QSet will be an unsorted hashtable. Not sorted (for speed), you must sort if wanted....

      Taz742T 1 Reply Last reply
      3
      • JonBJ JonB

        @Taz742 said in QSet<int> not sorted?:

        Hi.
        Why QSet<int> not sorted?

        Documentation say:
        It stores values in an unspecified order

        Umm, precisely because it states the order is "unspecified" not "sorted"?

        QSet will be an unsorted hashtable. Not sorted (for speed), you must sort if wanted....

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by
        #3

        @JNBarchan said in QSet<int> not sorted?:

        Umm, precisely because it states the order is "unspecified" not "sorted"?

        Again my bad english..

        @JNBarchan said in QSet<int> not sorted?:

        QSet will be an unsorted hashtable. Not sorted (for speed), you must sort if wanted....

        It's a little weird to sort set <T>. When talk about the set <t>, I'm accustomed to it's already sorted.

        Do what you want.

        JonBJ 1 Reply Last reply
        0
        • Taz742T Taz742

          Hi.
          Why QSet<int> not sorted?

              QSet<int> st;
              st.insert(5);
              st.insert(3);
              st.insert(17);
          
              for (auto it = st.begin(); it != st.end(); ++it) {
                  qDebug() << *it;
              }//output is: 17, 3, 5.
          

          Documentation say:
          It stores values in an unspecified order and provides very fast lookup of the values. Internally, QSet<T> is implemented as a QHash.

          I excepted similar to std::set<T>

          K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          @Taz742

          Obviously for performance reasons as you have found already in the documentation.

          There is an example how to get sorted values

          Vote the answer(s) that helped you to solve your issue(s)

          Taz742T 1 Reply Last reply
          0
          • Taz742T Taz742

            @JNBarchan said in QSet<int> not sorted?:

            Umm, precisely because it states the order is "unspecified" not "sorted"?

            Again my bad english..

            @JNBarchan said in QSet<int> not sorted?:

            QSet will be an unsorted hashtable. Not sorted (for speed), you must sort if wanted....

            It's a little weird to sort set <T>. When talk about the set <t>, I'm accustomed to it's already sorted.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @Taz742

            When talk about the set <t>, I'm accustomed to it's already sorted.

            Well, I don't know where you get that idea/code from, depends on implementation, sets are often unsorted. For QSet by not storing sorted and using hash instead it will be very fast for look up & insertion, so it's a good implementation.

            1 Reply Last reply
            0
            • K koahnig

              @Taz742

              Obviously for performance reasons as you have found already in the documentation.

              There is an example how to get sorted values

              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by
              #6

              @koahnig said in QSet<int> not unspecified?:

              Obviously for performance reasons as you have found already in the documentation.
              There is an example how to get sorted values

              Yes i already read all, what documentation says.

              @JNBarchan said in QSet<int> not unspecified?:

              Well, I don't know where you get that idea/code from, depends on implementation, sets are often unsorted.

              @koahnig @JNBarchan I have no problem with QSet <T>, i'm just surprised why it does not look like it from std::set <T>.

              Do what you want.

              JonBJ 1 Reply Last reply
              0
              • Taz742T Taz742

                @koahnig said in QSet<int> not unspecified?:

                Obviously for performance reasons as you have found already in the documentation.
                There is an example how to get sorted values

                Yes i already read all, what documentation says.

                @JNBarchan said in QSet<int> not unspecified?:

                Well, I don't know where you get that idea/code from, depends on implementation, sets are often unsorted.

                @koahnig @JNBarchan I have no problem with QSet <T>, i'm just surprised why it does not look like it from std::set <T>.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @Taz742
                Different implementations have different properties! If you're saying std::set is actually stored sorted (as opposed to just being presented to you that way), sorted lookup is typically O(log(n)) while hashed is typically O(1).

                Taz742T 1 Reply Last reply
                3
                • JonBJ JonB

                  @Taz742
                  Different implementations have different properties! If you're saying std::set is actually stored sorted (as opposed to just being presented to you that way), sorted lookup is typically O(log(n)) while hashed is typically O(1).

                  Taz742T Offline
                  Taz742T Offline
                  Taz742
                  wrote on last edited by
                  #8

                  @JNBarchan
                  Oh many thank.

                  Do what you want.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved