OSDN Git Service

Added function to compute parity.
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 21 Mar 2015 20:28:26 +0000 (21:28 +0100)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 21 Mar 2015 20:28:26 +0000 (21:28 +0100)
include/MUtils/Global.h
src/Global.cpp

index c67e050..bc5a438 100644 (file)
@@ -84,6 +84,9 @@ namespace MUtils
        MUTILS_API quint32 next_rand32(void);
        MUTILS_API quint64 next_rand64(void);
 
+       //Parity
+       MUTILS_API bool parity(quint32 value);
+
        //Remove File/Dir
        MUTILS_API bool remove_file(const QString &fileName);
        MUTILS_API bool remove_directory(const QString &folderPath, const bool &recursive);
index 684bcc2..42d2189 100644 (file)
@@ -110,6 +110,23 @@ QString MUtils::rand_str(const bool &bLong)
 }
 
 ///////////////////////////////////////////////////////////////////////////////
+// COMPUTE PARITY
+///////////////////////////////////////////////////////////////////////////////
+
+/*
+ * Compute parity in parallel
+ * http://www.graphics.stanford.edu/~seander/bithacks.html#ParityParallel
+ */
+bool MUtils::parity(quint32 value)
+{
+       value ^= value >> 16;
+       value ^= value >> 8;
+       value ^= value >> 4;
+       value &= 0xf;
+       return ((0x6996 >> value) & 1) != 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
 // TEMP FOLDER
 ///////////////////////////////////////////////////////////////////////////////