triangular_arbitrage_bot/src/hash.h

35 lines
1.2 KiB
C

#ifndef FUSED_HASH_H
#define FUSED_HASH_H
#include <stdint.h>
#include "book.h"
#define SYMBOL_TABLE_INITIAL 1024
/* One entry in the symbol table mapping name -> numeric index */
typedef struct {
char name[SYMBOL_NAME_LEN]; /* symbol name e.g. "BTC-USDT" */
uint16_t index; /* assigned numeric index */
} symbol_entry_t;
/* Growable symbol table for mapping symbol names to dense indices */
typedef struct {
symbol_entry_t *entries; /* dynamic array of entries */
uint32_t count; /* number of entries currently stored */
uint32_t capacity; /* allocated capacity of the array */
} symbol_table_t;
/* Initialise an empty symbol table */
void symbol_table_init(symbol_table_t *table);
/* Add a symbol to the table; returns its index, or -1 on failure */
int symbol_table_add(symbol_table_t *table, const char *name);
/* Look up a symbol by name; returns its index or -1 if not found */
int16_t symbol_table_lookup(const symbol_table_t *table, const char *name);
/* Sort symbol table entries alphabetically by name */
void symbol_table_sort(symbol_table_t *table);
/* FNV-1a non-cryptographic hash for a byte string */
uint32_t fnv1a_hash(const char *str, uint32_t len);
#endif