summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qalgorithms.qdoc
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-05-18 20:12:35 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-03 11:38:35 +0200
commit76e0223619da02911d02813961ef631a5e02d826 (patch)
tree0fafdd9293508a89c7baed92b8d269dc93a36670 /src/corelib/tools/qalgorithms.qdoc
parent6e7b8f79cb852ee1a6262a22aabd328b0e1b6dc0 (diff)
Add qPopulationCount() function, extracted from QBitArray
This functionality is used in multiple places in Qt itself, so it makes sense to have a global function for this. This also allows to map this onto specialized assembler instructions, should an architecture provide them, later on. Also added comprehensive tests, using a 4-bit lookup-table implementation as a reference. Change-Id: I8c4ea72cce54506ebb9fbe61141dbb5f1b7a660f Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/corelib/tools/qalgorithms.qdoc')
-rw-r--r--src/corelib/tools/qalgorithms.qdoc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/corelib/tools/qalgorithms.qdoc b/src/corelib/tools/qalgorithms.qdoc
index cc544af868..7c3aa1a3b2 100644
--- a/src/corelib/tools/qalgorithms.qdoc
+++ b/src/corelib/tools/qalgorithms.qdoc
@@ -635,3 +635,34 @@ of \a value in the variable passed as a reference in argument \a n.
\sa {qLess()}{qLess<T>()}
*/
+
+
+/*!
+ \fn uint qPopulationCount(quint8 v)
+ \relates <QtAlgorithms>
+ \since 5.2
+
+ Returns the number of bits set in \a v. This number also called
+ the Hamming Weight of \a v.
+ */
+
+/*!
+ \fn uint qPopulationCount(quint16 v)
+ \relates <QtAlgorithms>
+ \since 5.2
+ \overload
+ */
+
+/*!
+ \fn uint qPopulationCount(quint32 v)
+ \relates <QtAlgorithms>
+ \since 5.2
+ \overload
+ */
+
+/*!
+ \fn uint qPopulationCount(quint64 v)
+ \relates <QtAlgorithms>
+ \since 5.2
+ \overload
+ */