Algorithms_in_C
1.0.0
Set of algorithms implemented in C.
|
◆ adler32()
uint32_t adler32 |
( |
const char * |
s | ) |
|
32-bit Adler algorithm implementation
- Parameters
-
s | NULL terminated ASCII string to hash |
- Returns
- 32-bit hash result
22 const uint32_t MODADLER = 65521;
27 a = (a + s[i]) % MODADLER;
28 b = (b + a) % MODADLER;
◆ crc32()
uint32_t crc32 |
( |
const char * |
s | ) |
|
32-bit CRC algorithm implementation
- Parameters
-
s | NULL terminated ASCII string to hash |
- Returns
- 32-bit hash result
22 uint32_t crc = 0xffffffff;
28 for (uint8_t j = 8; j > 0; --j)
30 crc = (crc >> 1) ^ (0xEDB88320 & (-(crc & 1)));
35 return crc ^ 0xffffffff;
◆ djb2()
uint64_t djb2 |
( |
const char * |
s | ) |
|
DJB2 algorithm implementation.
- Parameters
-
s | NULL terminated string to hash |
- Returns
- 64-bit hash result
24 hash = ((hash << 5) + hash) + s[i];
◆ sdbm()
uint64_t sdbm |
( |
const char * |
s | ) |
|
SDBM algorithm implementation.
- Parameters
-
s | NULL terminated string to hash |
- Returns
- 64-bit hash result
24 hash = s[i] + (hash << 6) + (hash << 16) - hash;
◆ test_adler32()
Test function for adler32.
- Returns
- None
40 assert(
adler32(
"Hello World") == 403375133);
41 assert(
adler32(
"Hello World!") == 474547262);
42 assert(
adler32(
"Hello world") == 413860925);
43 assert(
adler32(
"Hello world!") == 487130206);
44 printf(
"Tests passed\n");
◆ test_crc32()
Test function for crc32.
- Returns
- None
44 assert(
crc32(
"Hello World") == 1243066710);
45 assert(
crc32(
"Hello World!") == 472456355);
46 assert(
crc32(
"Hello world") == 2346098258);
47 assert(
crc32(
"Hello world!") == 461707669);
52 printf(
"Tests passed\n");
◆ test_djb2()
Test function for djb2.
- Returns
- none
36 assert(
djb2(
"Hello World") == 13827776004929097857);
37 assert(
djb2(
"Hello World!") == 13594750393630990530);
38 assert(
djb2(
"Hello world") == 13827776004967047329);
39 assert(
djb2(
"Hello world!") == 13594750394883323106);
40 printf(
"Tests passed\n");
◆ test_sdbm()
Test function for sdbm.
- Returns
- None
36 assert(
sdbm(
"Hello World") == 12881824461405877380);
37 assert(
sdbm(
"Hello World!") == 7903571203300273309);
38 assert(
sdbm(
"Hello world") == 15154913742888948900);
39 assert(
sdbm(
"Hello world!") == 15254999417003201661);
40 printf(
"Tests passed\n");
◆ test_xor8()
Test function for xor8.
- Returns
- None
37 assert(
xor8(
"Hello World") == 228);
38 assert(
xor8(
"Hello World!") == 195);
39 assert(
xor8(
"Hello world") == 196);
40 assert(
xor8(
"Hello world!") == 163);
41 printf(
"Tests passed\n");
◆ xor8()
uint8_t xor8 |
( |
const char * |
s | ) |
|
8-bit XOR algorithm implementation
- Parameters
-
s | NULL terminated ASCII string to hash |
- Returns
- 8-bit hash result
25 hash = (hash + s[i]) & 0xff;
28 return (((hash ^ 0xff) + 1) & 0xff);
uint8_t xor8(const char *s)
8-bit XOR algorithm implementation
Definition: hash_xor8.c:19
uint64_t djb2(const char *s)
DJB2 algorithm implementation.
Definition: hash_djb2.c:18
uint32_t crc32(const char *s)
32-bit CRC algorithm implementation
Definition: hash_crc32.c:20
uint64_t sdbm(const char *s)
SDBM algorithm implementation.
Definition: hash_sdbm.c:18
uint32_t adler32(const char *s)
32-bit Adler algorithm implementation
Definition: hash_adler32.c:18