--- /dev/null
+/* MIT License
+ *
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+#ifndef _HASH_H_
+#define _HASH_H_
+
+// C
+#include <stdint.h>
+#include <stdlib.h>
+
+uint32_t create_hash(const char *msg, size_t len);
+#endif /* _HASH_H_ */
--- /dev/null
+/* Copyright (c) 2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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. */
+
+// C
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+
+// DLog
+#include "hash.h"
+
+#define NUM_BUCKETS 10
+#define NELEMS(array) (sizeof array / sizeof *array)
+#define RANDOM_ITERATIONS 5000
+#define SEED 0
+
+static size_t index = 0;
+static char printables[36]; // a-z 0-9
+static uint32_t hash_values[(sizeof printables * sizeof printables * sizeof printables) + RANDOM_ITERATIONS * 3];
+static size_t collisions = 0;
+
+static void add_hash(const char *msg, size_t msg_size)
+{
+ const uint32_t new_hash = create_hash(msg, msg_size);
+
+ for (size_t i = 0; i < index; i++) {
+ if (hash_values[i] != new_hash)
+ continue;
+ collisions++;
+ fprintf(stderr, "collided hash: [ %"PRIu32" ], from message: [ %.*s ]\n", hash_values[i], msg_size, msg);
+ return;
+ }
+
+ hash_values[index] = new_hash;
+ index++;
+}
+
+static void validate_hash()
+{
+ static const size_t BUCKET_SIZE = UINT32_MAX / NUM_BUCKETS + 1;
+ static const size_t BUCKET_AVG_COUNT = NELEMS(hash_values) / NUM_BUCKETS;
+ size_t buckets[NUM_BUCKETS] = {0};
+
+ for (size_t i = 0; i < index; i++) {
+ const int bucket = hash_values[i] / BUCKET_SIZE;
+ buckets[bucket]++;
+ }
+
+ /* One collision may appear, because of large number
+ * of elements, but if more, it should be checked. */
+ assert(collisions < 2);
+
+ for (size_t i = 0; i < NUM_BUCKETS; i++) {
+ assert(buckets[i] < (1.1 * BUCKET_AVG_COUNT));
+ assert(buckets[i] > (0.9 * BUCKET_AVG_COUNT));
+ }
+}
+
+static void test_permutations()
+{
+ char hash[3];
+
+ for (size_t i = 0; i < sizeof printables; i++)
+ for (size_t j = 0; j < sizeof printables; j++)
+ for (size_t k = 0; k < sizeof printables; k++) {
+ hash[0] = printables[i];
+ hash[1] = printables[j];
+ hash[2] = printables[k];
+ add_hash(hash, sizeof hash);
+ }
+}
+
+static void test_random(size_t size)
+{
+ char hash[size];
+
+ for (int i = 0; i < sizeof hash; i++)
+ hash[i] = printables[rand() % sizeof printables];
+
+ add_hash(hash, sizeof hash);
+}
+
+int main()
+{
+ srand(SEED);
+
+ for (char c = 'a'; c <= 'z'; ++c)
+ printables[c - 'a'] = c;
+
+ for (char c = '0'; c <= '9'; ++c)
+ printables[c - '0' + 'z' - 'a' + 1] = c;
+
+ test_permutations();
+
+ for (size_t i = 0; i < RANDOM_ITERATIONS; i++) {
+ test_random(10);
+ test_random(30);
+ test_random(200);
+ }
+
+ validate_hash();
+ return 0;
+}