Using HashMap over QMap

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using HashMap over QMap

kartikx
Hi all,

I was working on categorizing Face Suggestions by Suggested Name. This would lead to a grouping of similar faces, which would be particularly helpful in the Unconfirmed Tag View.

To do the categorization, I have been able to implement methods to obtain a Map of Face Regions -> Suggested Names for each Image. This would have multiple elements if an image has multiple faces. I have committed the implementation already.

Since, I don't have any reason for my keys to be sorted, I was wondering if I should use a HashMap instead of a QMap?  I have currently used a QMap because all methods related to Faces use it.

Thanks in advance
Kartik
Reply | Threaded
Open this post in threaded view
|

Re: Using HashMap over QMap

Maik Qualmann
A QHashMap brings a speed advantage for a large number of entries, because
access is constant time. A QMap can be faster with a few, say up to 200
entries. With Qt4 there were sometimes problems if the key was a string in a
QHashMap, which was not unique when converted to a hash. That should no longer
occur with Qt5. So, many thousands of entries with a lot of access ->
QHashMap. Keep in mind that the keys of a QMap are sorted automatically.

Maik

Am Donnerstag, 9. Juli 2020, 15:24:31 CEST schrieb Kartik Ramesh:

> Hi all,
>
> I was working on categorizing Face Suggestions by Suggested Name. This
> would lead to a grouping of similar faces, which would be particularly
> helpful in the Unconfirmed Tag View.
>
> To do the categorization, I have been able to implement methods to obtain a
> Map of Face Regions -> Suggested Names for each Image. This would have
> multiple elements if an image has multiple faces. I have committed the
> implementation already.
>
> Since, I don't have any reason for my keys to be sorted, I was wondering if
> I should use a HashMap instead of a QMap?  I have currently used a QMap
> because all methods related to Faces use it.
>
> Thanks in advance
> Kartik




Reply | Threaded
Open this post in threaded view
|

Re: Using HashMap over QMap

kartikx
Thank you for the insight. I wasn't aware that a QMap would perform better for smaller entries. Since my map would contain only small number of entries on average (as number of faces in an image will not be very large), I think I should stick with the QMap implementation.

Thanks
Kartik

On Thu, 9 Jul 2020, 22:54 Maik Qualmann, <[hidden email]> wrote:
A QHashMap brings a speed advantage for a large number of entries, because
access is constant time. A QMap can be faster with a few, say up to 200
entries. With Qt4 there were sometimes problems if the key was a string in a
QHashMap, which was not unique when converted to a hash. That should no longer
occur with Qt5. So, many thousands of entries with a lot of access ->
QHashMap. Keep in mind that the keys of a QMap are sorted automatically.

Maik

Am Donnerstag, 9. Juli 2020, 15:24:31 CEST schrieb Kartik Ramesh:
> Hi all,
>
> I was working on categorizing Face Suggestions by Suggested Name. This
> would lead to a grouping of similar faces, which would be particularly
> helpful in the Unconfirmed Tag View.
>
> To do the categorization, I have been able to implement methods to obtain a
> Map of Face Regions -> Suggested Names for each Image. This would have
> multiple elements if an image has multiple faces. I have committed the
> implementation already.
>
> Since, I don't have any reason for my keys to be sorted, I was wondering if
> I should use a HashMap instead of a QMap?  I have currently used a QMap
> because all methods related to Faces use it.
>
> Thanks in advance
> Kartik




Reply | Threaded
Open this post in threaded view
|

Re: Using HashMap over QMap

Maik Qualmann
One more thing about the QMap. Please no longer use insertMulti(). Then use a
QMultiMap. The insertMulti() function is deprecated in QT-5.15. I have already
replaced some, but there are still some. With new code, we have to be careful.

Maik

Am Donnerstag, 9. Juli 2020, 19:32:47 CEST schrieb Kartik Ramesh:

> Thank you for the insight. I wasn't aware that a QMap would perform better
> for smaller entries. Since my map would contain only small number of
> entries on average (as number of faces in an image will not be very large),
> I think I should stick with the QMap implementation.
>
> Thanks
> Kartik
>
> On Thu, 9 Jul 2020, 22:54 Maik Qualmann, <[hidden email]> wrote:
> > A QHashMap brings a speed advantage for a large number of entries, because
> > access is constant time. A QMap can be faster with a few, say up to 200
> > entries. With Qt4 there were sometimes problems if the key was a string in
> > a
> > QHashMap, which was not unique when converted to a hash. That should no
> > longer
> > occur with Qt5. So, many thousands of entries with a lot of access ->
> > QHashMap. Keep in mind that the keys of a QMap are sorted automatically.
> >
> > Maik
> >
> > Am Donnerstag, 9. Juli 2020, 15:24:31 CEST schrieb Kartik Ramesh:
> > > Hi all,
> > >
> > > I was working on categorizing Face Suggestions by Suggested Name. This
> > > would lead to a grouping of similar faces, which would be particularly
> > > helpful in the Unconfirmed Tag View.
> > >
> > > To do the categorization, I have been able to implement methods to
> >
> > obtain a
> >
> > > Map of Face Regions -> Suggested Names for each Image. This would have
> > > multiple elements if an image has multiple faces. I have committed the
> > > implementation already.
> > >
> > > Since, I don't have any reason for my keys to be sorted, I was wondering
> >
> > if
> >
> > > I should use a HashMap instead of a QMap?  I have currently used a QMap
> > > because all methods related to Faces use it.
> > >
> > > Thanks in advance
> > > Kartik




Reply | Threaded
Open this post in threaded view
|

Re: Using HashMap over QMap

kartikx
Thanks for the heads up, I'll take care of this.

Kartik

On Thu, 9 Jul 2020, 23:15 Maik Qualmann, <[hidden email]> wrote:
One more thing about the QMap. Please no longer use insertMulti(). Then use a
QMultiMap. The insertMulti() function is deprecated in QT-5.15. I have already
replaced some, but there are still some. With new code, we have to be careful.

Maik

Am Donnerstag, 9. Juli 2020, 19:32:47 CEST schrieb Kartik Ramesh:
> Thank you for the insight. I wasn't aware that a QMap would perform better
> for smaller entries. Since my map would contain only small number of
> entries on average (as number of faces in an image will not be very large),
> I think I should stick with the QMap implementation.
>
> Thanks
> Kartik
>
> On Thu, 9 Jul 2020, 22:54 Maik Qualmann, <[hidden email]> wrote:
> > A QHashMap brings a speed advantage for a large number of entries, because
> > access is constant time. A QMap can be faster with a few, say up to 200
> > entries. With Qt4 there were sometimes problems if the key was a string in
> > a
> > QHashMap, which was not unique when converted to a hash. That should no
> > longer
> > occur with Qt5. So, many thousands of entries with a lot of access ->
> > QHashMap. Keep in mind that the keys of a QMap are sorted automatically.
> >
> > Maik
> >
> > Am Donnerstag, 9. Juli 2020, 15:24:31 CEST schrieb Kartik Ramesh:
> > > Hi all,
> > >
> > > I was working on categorizing Face Suggestions by Suggested Name. This
> > > would lead to a grouping of similar faces, which would be particularly
> > > helpful in the Unconfirmed Tag View.
> > >
> > > To do the categorization, I have been able to implement methods to
> >
> > obtain a
> >
> > > Map of Face Regions -> Suggested Names for each Image. This would have
> > > multiple elements if an image has multiple faces. I have committed the
> > > implementation already.
> > >
> > > Since, I don't have any reason for my keys to be sorted, I was wondering
> >
> > if
> >
> > > I should use a HashMap instead of a QMap?  I have currently used a QMap
> > > because all methods related to Faces use it.
> > >
> > > Thanks in advance
> > > Kartik




Reply | Threaded
Open this post in threaded view
|

Re: Using HashMap over QMap

Maik Qualmann
In reply to this post by Maik Qualmann
I checked again, here is the benchmark:

https://woboq.com/blog/qmap_qhash_benchmark.html

A QMap is only up to 20 entries faster, but clearly. But I think that you also
have no more than 20 entries in the QMap.

Maik

Am Donnerstag, 9. Juli 2020, 19:42:54 CEST schrieben Sie:

> One more thing about the QMap. Please no longer use insertMulti(). Then use
> a QMultiMap. The insertMulti() function is deprecated in QT-5.15. I have
> already replaced some, but there are still some. With new code, we have to
> be careful.
>
> Maik
>
> Am Donnerstag, 9. Juli 2020, 19:32:47 CEST schrieb Kartik Ramesh:
> > Thank you for the insight. I wasn't aware that a QMap would perform better
> > for smaller entries. Since my map would contain only small number of
> > entries on average (as number of faces in an image will not be very
> > large),
> > I think I should stick with the QMap implementation.
> >
> > Thanks
> > Kartik
> >
> > On Thu, 9 Jul 2020, 22:54 Maik Qualmann, <[hidden email]> wrote:
> > > A QHashMap brings a speed advantage for a large number of entries,
> > > because
> > > access is constant time. A QMap can be faster with a few, say up to 200
> > > entries. With Qt4 there were sometimes problems if the key was a string
> > > in
> > > a
> > > QHashMap, which was not unique when converted to a hash. That should no
> > > longer
> > > occur with Qt5. So, many thousands of entries with a lot of access ->
> > > QHashMap. Keep in mind that the keys of a QMap are sorted automatically.
> > >
> > > Maik
> > >
> > > Am Donnerstag, 9. Juli 2020, 15:24:31 CEST schrieb Kartik Ramesh:
> > > > Hi all,
> > > >
> > > > I was working on categorizing Face Suggestions by Suggested Name. This
> > > > would lead to a grouping of similar faces, which would be particularly
> > > > helpful in the Unconfirmed Tag View.
> > > >
> > > > To do the categorization, I have been able to implement methods to
> > >
> > > obtain a
> > >
> > > > Map of Face Regions -> Suggested Names for each Image. This would have
> > > > multiple elements if an image has multiple faces. I have committed the
> > > > implementation already.
> > > >
> > > > Since, I don't have any reason for my keys to be sorted, I was
> > > > wondering
> > >
> > > if
> > >
> > > > I should use a HashMap instead of a QMap?  I have currently used a
> > > > QMap
> > > > because all methods related to Faces use it.
> > > >
> > > > Thanks in advance
> > > > Kartik