OSDN Git Service

Add common hash functions so we don't have to redefine everywhere
authorZach Johnson <zachoverflow@google.com>
Tue, 26 Aug 2014 01:21:12 +0000 (18:21 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Mon, 16 Mar 2015 23:51:29 +0000 (16:51 -0700)
osi/Android.mk
osi/include/hash_functions.h [new file with mode: 0644]
osi/src/hash_functions.c [new file with mode: 0644]

index f290240..fb5c899 100644 (file)
@@ -30,6 +30,7 @@ LOCAL_SRC_FILES := \
     ./src/data_dispatcher.c \
     ./src/eager_reader.c \
     ./src/fixed_queue.c \
+    ./src/hash_functions.c \
     ./src/hash_map.c \
     ./src/list.c \
     ./src/reactor.c \
diff --git a/osi/include/hash_functions.h b/osi/include/hash_functions.h
new file mode 100644 (file)
index 0000000..443b3ee
--- /dev/null
@@ -0,0 +1,25 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2014 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#pragma once
+
+#include "hash_map.h"
+
+hash_index_t hash_function_naive(const void *key);
+
+hash_index_t hash_function_knuth(const void *key);
diff --git a/osi/src/hash_functions.c b/osi/src/hash_functions.c
new file mode 100644 (file)
index 0000000..e0170f4
--- /dev/null
@@ -0,0 +1,27 @@
+/******************************************************************************
+ *
+ *  Copyright (C) 2014 Google, Inc.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at:
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ ******************************************************************************/
+
+#include "hash_functions.h"
+
+hash_index_t hash_function_naive(const void *key) {
+  return (hash_index_t)key;
+}
+
+hash_index_t hash_function_knuth(const void *key) {
+  return ((hash_index_t)key) * 2654435761;
+}