summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example.c23
-rw-r--r--main.c49
-rw-r--r--murmurhash.c6
-rw-r--r--murmurhash.h19
-rw-r--r--test.c6
5 files changed, 45 insertions, 58 deletions
diff --git a/example.c b/example.c
index e8a840c..b5da670 100644
--- a/example.c
+++ b/example.c
@@ -1,13 +1,18 @@
+/**
+ * `example.c' - murmurhash
+ *
+ * copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
+ */
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
-#include <murmurhash.h>
-int main(void)
-{
- uint32_t seed = 0;
- const char *key = "kinkajou"; // // 0xb6d99cf8
- uint32_t hash = murmurhash(key, (uint32_t)strlen(key), seed);
- printf("murmurhash(%s) = 0x%x\n", key, hash);
- return 0;
-} \ No newline at end of file
+#include "murmurhash.h"
+
+int main (void) {
+ uint32_t seed = 0;
+ const char *key = "kinkajou"; // // 0xb6d99cf8
+ uint32_t hash = murmurhash(key, (uint32_t) strlen(key), seed);
+ printf("murmurhash(%s) = 0x%x\n", key, hash);
+ return 0;
+}
diff --git a/main.c b/main.c
index e3c680b..83ce046 100644
--- a/main.c
+++ b/main.c
@@ -1,31 +1,35 @@
-
/**
* `main.c' - murmurhash
*
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
+ * copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
*/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
+
#include "murmurhash.h"
-static void
-usage () {
+#define hash(key) murmurhash(key, (uint32_t) strlen(key), (uint32_t) atoi(seed));
+#define isopt(opt, str) (0 == strncmp(opt, str, strlen(str)))
+#define setopt(opt, key, var) { \
+ size_t len = strlen(key) + 1; \
+ for (int i = 0; i < len; ++i) { (*opt)++; } \
+ var = opt; \
+}
+
+static void usage () {
fprintf(stderr, "usage: murmur [-hV] [options]\n");
}
-static void
-help () {
+static void help () {
fprintf(stderr, "\noptions:\n");
fprintf(stderr, "\n --seed=[seed] hash seed (optional)");
fprintf(stderr, "\n");
}
-static char *
-read_stdin () {
+static char* read_stdin () {
size_t bsize = 1024;
size_t size = 1;
char buf[bsize];
@@ -64,24 +68,15 @@ read_stdin () {
return NULL;
}
-#define isopt(opt, str) (0 == strncmp(opt, str, strlen(str)))
-
-#define setopt(opt, key, var) { \
- size_t len = strlen(key) + 1; \
- for (int i = 0; i < len; ++i) { (*opt)++; } \
- var = opt; \
-}
-
-int
-main (int argc, char **argv) {
- char *buf = NULL;
- char *key = NULL;
- char *seed = NULL;
+int main (int argc, char** argv) {
+ char* buf = NULL;
+ char* key = NULL;
+ char* seed = NULL;
uint32_t h = 0;
// parse opts
- {
- char *opt = NULL;
+ do {
+ char* opt = NULL;
opt = *argv++; // unused
while ((opt = *argv++)) {
@@ -111,14 +106,12 @@ main (int argc, char **argv) {
}
}
}
- }
+ } while (0);
if (NULL == seed) {
seed = "0";
}
-#define hash(key) murmurhash(key, (uint32_t) strlen(key), (uint32_t) atoi(seed));
-
if (1 == isatty(0)) { return 1; }
else if (ferror(stdin)) { return 1; }
else {
@@ -136,7 +129,5 @@ main (int argc, char **argv) {
} while (NULL != key);
}
-#undef hash
-
return 0;
}
diff --git a/murmurhash.c b/murmurhash.c
index 5a4588e..d3327ac 100644
--- a/murmurhash.c
+++ b/murmurhash.c
@@ -1,9 +1,8 @@
/**
- * `murmurhash.h' - murmurhash
+ * `murmurhash.c' - murmurhash
*
* copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
*/
-
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
@@ -26,8 +25,7 @@ static uint32_t htole32 (uint32_t value) {
#endif
#endif
-uint32_t
-murmurhash (const char *key, uint32_t len, uint32_t seed) {
+uint32_t murmurhash (const char *key, uint32_t len, uint32_t seed) {
uint32_t c1 = 0xcc9e2d51;
uint32_t c2 = 0x1b873593;
uint32_t r1 = 15;
diff --git a/murmurhash.h b/murmurhash.h
index b6b6e43..598085a 100644
--- a/murmurhash.h
+++ b/murmurhash.h
@@ -1,30 +1,25 @@
/**
* `murmurhash.h' - murmurhash
*
- * copyright (c) 2014-2022 joseph werle <joseph.werle@gmail.com>
+ * copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
*/
-
#ifndef MURMURHASH_H
#define MURMURHASH_H
#include <stdint.h>
-#define MURMURHASH_VERSION "0.1.0"
+#define MURMURHASH_VERSION "0.2.0"
#ifdef __cplusplus
extern "C" {
#endif
+ /**
+ * Returns a murmur hash of `key' based on `seed'
+ * using the MurmurHash3 algorithm
+ */
-/**
- * Returns a murmur hash of `key' based on `seed'
- * using the MurmurHash3 algorithm
- */
-
-uint32_t
-murmurhash (const char *, uint32_t, uint32_t);
-
+ uint32_t murmurhash (const char*, uint32_t, uint32_t);
#ifdef __cplusplus
}
#endif
-
#endif
diff --git a/test.c b/test.c
index 8c52d43..903f417 100644
--- a/test.c
+++ b/test.c
@@ -1,8 +1,7 @@
-
/**
* `test.c' - murmurhash
*
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com>
+ * copyright (c) 2014-2025 joseph werle <joseph.werle@gmail.com>
*/
#include <stdio.h>
@@ -12,8 +11,7 @@
#include <assert.h>
#include "murmurhash.h"
-int
-main (void) {
+int main (void) {
uint32_t hash = 0;
uint32_t seed = 0;