c_cpp 哈希的新方法称为炉哈希
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 哈希的新方法称为炉哈希相关的知识,希望对你有一定的参考价值。
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
// Prototype for furnace hashing
#define FURNACE_INIT(furn, start) \
furn.value = start; \
furn.state = 0; \
furn.sections = (uint8_t*)(&(furn.value))
// Debug macro
#define FURNACE_PRINT(furn) printf("furnace value %u\nfurance sections: %u %u %u %u\n", furn.value, furn.sections[0], furn.sections[1], furn.sections[2], furn.sections[3])
// The melting operation XOR's a 8-bit input to a section of the base value, essentially melting it
#define FURNACE_MELT(furn, byte) \
furn.sections[furn.state] ^= byte; \
furn.state = (furn.state + 1) % 4
typedef struct
{
uint32_t value;
uint8_t* sections;
int state;
} furnace_t;
void furnace_run(void)
{
furnace_t foo;
FURNACE_INIT(foo, 5);
FURNACE_PRINT(foo);
FURNACE_MELT(foo, 0xfa);
FURNACE_PRINT(foo);
FURNACE_MELT(foo, 0xfa);
FURNACE_PRINT(foo);
}
void furnace_hash(const char* data)
{
const unsigned char* reader = (const unsigned char*)data;
furnace_t foo;
FURNACE_INIT(foo, 17);
while(*reader)
{
FURNACE_PRINT(foo);
FURNACE_MELT(foo, (*reader));
reader++;
}
FURNACE_PRINT(foo);
}
int main(void) {
furnace_hash("Hello! World leaders!!");
return 0;
}
以上是关于c_cpp 哈希的新方法称为炉哈希的主要内容,如果未能解决你的问题,请参考以下文章
c_cpp 使用exists方法实现哈希映射
c_cpp 为字符串实现哈希表和哈希函数
c_cpp 为字符串实现哈希表和哈希函数
c_cpp C中的哈希映射实现,带有djb2哈希函数
c_cpp 在C中进行djb2哈希测试,使控制台能够测试哈希值
c_cpp 16位哈希