mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
remove redundant files
This commit is contained in:
parent
c3b44aaaa8
commit
a5c0083954
82
hash/hash.c
82
hash/hash.c
@ -1,82 +0,0 @@
|
||||
/*
|
||||
author: Christian Bender
|
||||
This is the implementation unit of the hash-functions.
|
||||
|
||||
Overview about hash-functions:
|
||||
|
||||
- sdbm
|
||||
- djb2
|
||||
- xor8 (8 bits)
|
||||
- adler_32 (32 bits)
|
||||
*/
|
||||
|
||||
long long sdbm(char s[])
|
||||
{
|
||||
long long hash = 0;
|
||||
int i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
hash = s[i] + (hash << 6) + (hash << 16) - hash;
|
||||
i++;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
long long djb2(char s[])
|
||||
{
|
||||
long long hash = 5381; /* init value */
|
||||
int i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
hash = ((hash << 5) + hash) + s[i];
|
||||
i++;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
char xor8(char s[])
|
||||
{
|
||||
int hash = 0;
|
||||
int i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
hash = (hash + s[i]) & 0xff;
|
||||
i++;
|
||||
}
|
||||
return (((hash ^ 0xff) + 1) & 0xff);
|
||||
}
|
||||
|
||||
int adler_32(char s[])
|
||||
{
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
const int MODADLER = 65521;
|
||||
|
||||
int i = 0;
|
||||
while (s[i] != '\0')
|
||||
{
|
||||
a = (a + s[i]) % MODADLER;
|
||||
b = (b + a) % MODADLER;
|
||||
i++;
|
||||
}
|
||||
return (b << 16) | a;
|
||||
}
|
||||
|
||||
/* crc32 Hash-Algorithm*/
|
||||
#include <inttypes.h>
|
||||
|
||||
uint32_t crc32(char *data)
|
||||
{
|
||||
int i = 0;
|
||||
uint32_t crc = 0xffffffff;
|
||||
while (data[i] != '\0')
|
||||
{
|
||||
uint8_t byte = data[i];
|
||||
crc = crc ^ byte;
|
||||
for (int j = 8; j > 0; --j)
|
||||
crc = (crc >> 1) ^ (0xEDB88320 & (-(crc & 1)));
|
||||
|
||||
i++;
|
||||
}
|
||||
return crc ^ 0xffffffff;
|
||||
}
|
49
hash/hash.h
49
hash/hash.h
@ -1,49 +0,0 @@
|
||||
/*
|
||||
author: Christian Bender
|
||||
This file contains the public interface
|
||||
|
||||
Overview about hash-functions:
|
||||
|
||||
- sdbm
|
||||
- djb2
|
||||
- xor8 (8 bit)
|
||||
- adler_32 (32 bits)
|
||||
*/
|
||||
|
||||
#ifndef __HASH__H
|
||||
#define __HASH__H
|
||||
|
||||
/*
|
||||
sdbm: implements the sdbm hash-algorithm
|
||||
returns a whole number of type long long.
|
||||
*/
|
||||
long long sdbm(char[]);
|
||||
|
||||
/*
|
||||
djb2: implements the djb2 hash-algorithm
|
||||
returns a whole number of type long long.
|
||||
*/
|
||||
long long djb2(char[]);
|
||||
|
||||
/*
|
||||
xor8: implements the xor8 hash-algorithm
|
||||
returns a whole number of type char.
|
||||
length: 8 bit
|
||||
*/
|
||||
char xor8(char[]);
|
||||
|
||||
/*
|
||||
adler_32: implements the adler-32 hash-algorithm
|
||||
returns a whole number of type int.
|
||||
length: 32 bit
|
||||
assumes: int has a length of 32 bits.
|
||||
*/
|
||||
int adler_32(char[]);
|
||||
|
||||
/*
|
||||
crc32: implements the crc-32 checksum-algorithm
|
||||
returns the crc-32 checksum
|
||||
*/
|
||||
int crc32(char[]);
|
||||
|
||||
#endif
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
author: Christian Bender
|
||||
This file contains a simple test program for each hash-function.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hash.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char s[] = "hello";
|
||||
|
||||
/* actual tests */
|
||||
printf("sdbm: %s --> %llX\n", s, sdbm(s));
|
||||
printf("djb2: %s --> %llX\n", s, djb2(s));
|
||||
printf("xor8: %s --> %X\n", s, xor8(s)); /* 8 bit */
|
||||
printf("adler_32: %s --> %X\n", s, adler_32(s)); /* 32 bit */
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user