Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ds.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,29 @@ typedef struct DataItem
{
char *key;
char *value;
unsigned int hit_count; // Hit count for caching
unsigned int last_accessed; // Timestamp of last access
uint64_t hit_count; // Hit count for caching (use 64-bit to prevent overflow)
uint64_t last_accessed; // Timestamp of last access (use 64-bit to prevent overflow)
struct DataItem *next; // For chaining in hash table
} DataItem;

typedef struct
{
unsigned int size;
size_t size; // Use size_t for better portability and larger capacity
DataItem **table;
} HashTable;

// --- Hash Table Function Declarations ---
// Returns NULL on allocation failure - caller MUST check return value
HashTable *create_hash_table(unsigned int size);
void free_hash_table(HashTable *ht);
unsigned int hash_function(const char *key, unsigned int size);
void hash_table_insert(HashTable *ht, const char *key, const char *value);
// Returns NULL if key not found - caller MUST check return value
DataItem *hash_table_search(HashTable *ht, const char *key);
void hash_table_remove(HashTable *ht, const char *key);

// --- Helper Function Declarations ---
// Returns NULL on allocation failure - caller MUST check return value
char *my_strdup(const char *s);
void free_data_item_contents(DataItem *item);
void free_data_list(DataItem **list, size_t *size, size_t *capacity);
Expand Down