forked from tboox/tbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* includes | ||
*/ | ||
#include "../demo.h" | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* main | ||
*/ | ||
tb_int_t tb_demo_utils_fnv32_main(tb_int_t argc, tb_char_t** argv) | ||
{ | ||
// data | ||
tb_byte_t* data = (tb_byte_t*)argv[1]; | ||
|
||
// trace | ||
tb_printf("[fnv32]: %x\n", tb_fnv32_encode(data)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/*!The Treasure Box Library | ||
* | ||
* TBox is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* TBox is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with TBox; | ||
* If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> | ||
* | ||
* Copyright (C) 2016, Olexander Yermakov All rights reserved. | ||
* | ||
* @author alexyer | ||
* @file fnv32.c | ||
* @ingroup utils | ||
* | ||
*/ | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* includes | ||
*/ | ||
#include "fnv32.h" | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* macros | ||
*/ | ||
|
||
// FNV prime | ||
#define FNV_32_PRIME (0x01000193) | ||
#define FNV0 (0x811c9dc5) | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* implementation | ||
*/ | ||
tb_uint32_t tb_fnv32_encode(tb_byte_t const* data) | ||
{ | ||
tb_uint32_t hval = FNV0; | ||
|
||
while (*data) | ||
{ | ||
hval *= FNV_32_PRIME; | ||
hval ^= (unsigned int)*data++; | ||
} | ||
|
||
return hval; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*!The Treasure Box Library | ||
* | ||
* TBox is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation; either version 2.1 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* TBox is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with TBox; | ||
* If not, see <a href="http://www.gnu.org/licenses/"> http://www.gnu.org/licenses/</a> | ||
* | ||
* Copyright (C) 2016, Olexander Yermakov All rights reserved. | ||
* | ||
* @author alexyer | ||
* @file fnv32.h | ||
* @ingroup utils | ||
* | ||
*/ | ||
#ifndef TB_UTILS_FNV32_H | ||
#define TB_UTILS_FNV32_H | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* includes | ||
*/ | ||
#include "prefix.h" | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* extern | ||
*/ | ||
__tb_extern_c_enter__ | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* interfaces | ||
*/ | ||
|
||
/*! encode fnv32 | ||
* | ||
* @param data the data | ||
* | ||
* @return the fnv32 value | ||
*/ | ||
tb_uint32_t tb_fnv32_encode(tb_byte_t const* data); | ||
|
||
/* ////////////////////////////////////////////////////////////////////////////////////// | ||
* extern | ||
*/ | ||
__tb_extern_c_leave__ | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,6 @@ | |
#include "adler32.h" | ||
#include "singleton.h" | ||
#include "lock_profiler.h" | ||
#include "fnv32.h" | ||
|
||
#endif |