ℹ️ New Book: Build Your Own Database
redis/13/common.h
#pragma once
#include <stdint.h>
#include <stddef.h>
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type, member) );})
inline uint64_t str_hash(const uint8_t *data, size_t len) {
uint32_t h = 0x811C9DC5;
for (size_t i = 0; i < len; i++) {
h = (h + data[i]) * 0x01000193;
}
return h;
}
enum {
SER_NIL = 0,
SER_ERR = 1,
SER_STR = 2,
SER_INT = 3,
SER_DBL = 4,
SER_ARR = 5,
};
See also:
codecrafters.io offers “Build Your Own X” courses in many programming languages.
Including Redis, Git, SQLite, Docker, and more.
Check it out
codecrafters.io offers “Build Your Own X” courses in many programming languages.
Including Redis, Git, SQLite, Docker, and more.