Skip to content
Snippets Groups Projects
Commit a57e77e4 authored by Oleg Hahm's avatar Oleg Hahm
Browse files

sys: remove hash_string module

hash_string implements djb2 which is already part of `sys/hashes/`
parent f7005e04
No related branches found
No related tags found
No related merge requests found
include $(RIOTBASE)/Makefile.base
/*
* Copyright (C) 2013 Kaspar Schleiser <kaspar@schleiser.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup sys_hash_string
* @ingroup sys
*
* @brief Hash string implementation
*
* @{
* @file
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include <string.h>
#include "hash_string.h"
unsigned long hash_string(unsigned char *str)
{
unsigned long hash = 5381;
int c;
while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
}
return hash;
}
int cmp_string(char *a, char *b)
{
return (strcmp(a, b) == 0);
}
/*
* Copyright (C) 2010 Kaspar Schleiser
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#ifndef __HASH_STRING_H
#define __HASH_STRING_H
#ifdef __cplusplus
extern "C" {
#endif
unsigned long hash_string(unsigned char *str);
int cmp_string(char *a, char *b);
#ifdef __cplusplus
}
#endif
#endif /* __HASH_STRING_H */
include $(RIOTBASE)/Makefile.base
USEMODULE += hash_string
/*
* Copyright (C) 2015 Kushal Singh <kushal.spiderman.singh@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
#include "tests-hash_string.h"
#include "hash_string.h"
static void test_hash_value(void)
{
TEST_ASSERT_EQUAL_INT(177621, hash_string((unsigned char *)"0"));
TEST_ASSERT_EQUAL_INT(685012521, hash_string((unsigned char *)"0123456789ab"
"cde-0123456789abcde-0123456789"
"abcde-0123456789abcde-"));
TEST_ASSERT_EQUAL_INT(900068641, hash_string((unsigned char *)"Frank jagt "
"im komplett verwahrlosten Taxi"
" quer durch Bayern"));
TEST_ASSERT_EQUAL_INT(1857959484, hash_string((unsigned char *)"12A5B6cd_"));
TEST_ASSERT_EQUAL_INT(5381, hash_string((unsigned char *)""));
}
Test *tests_hash_string_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_hash_value),
};
EMB_UNIT_TESTCALLER(hash_string_tests, NULL, NULL, fixtures);
return (Test *)&hash_string_tests;
}
void tests_hash_string(void)
{
TESTS_RUN(tests_hash_string_tests());
}
/*
* Copyright (C) 2015 Kushal Singh <kushal.spiderman.singh@gmail.com>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @addtogroup unittests
* @{
*
* @file
* @brief Unittests for the ``hash_string`` module
*
* @author Kushal Singh <kushal.spiderman.singh@gmail.com>
*/
#ifndef TESTS_HASH_STRING_H_
#define TESTS_HASH_STRING_H_
#include "embUnit.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief The entry point of this test suite.
*/
void tests_hash_string(void);
/**
* @brief Generates tests for hash_string
*
* @return embUnit tests if successful, NULL if not.
*/
Test *tests_hash_string_tests(void);
#ifdef __cplusplus
}
#endif
#endif /* TESTS_HASH_STRING_H_ */
/** @} */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment