MINOR: standard: add a simple popcount function
This function returns the number of ones in a word.
diff --git a/include/common/standard.h b/include/common/standard.h
index 4813065..221d8b8 100644
--- a/include/common/standard.h
+++ b/include/common/standard.h
@@ -519,6 +519,17 @@
return result;
}
+/* Simple popcount implementation. It returns the number of ones in a word */
+static inline unsigned int popcount(unsigned int a)
+{
+ unsigned int cnt;
+ for (cnt = 0; a; a >>= 1) {
+ if (a & 1)
+ cnt++;
+ }
+ return cnt;
+}
+
/* copies at most <n> characters from <src> and always terminates with '\0' */
char *my_strndup(const char *src, int n);