Unsolved QSet<int> not unspecified?
-
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>
-
@Taz742 said in QSet<int> not sorted?:
Hi.
Why QSet<int> not sorted?Documentation say:
It stores values in an unspecified orderUmm, 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.... -
@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.
-
Obviously for performance reasons as you have found already in the documentation.
There is an example how to get sorted values
-
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. -
@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 valuesYes 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>.
-
@Taz742
Different implementations have different properties! If you're sayingstd::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). -
@JNBarchan
Oh many thank.