Baseer 0.2.0
Baseer is an advanced binary analysis tool designed to provide deep insights into any file.
Loading...
Searching...
No Matches
b_hashmap.c File Reference

Simple string-keyed hashmap implementation. More...

#include "b_hashmap.h"

Functions

unsigned int hash (const char *key)
 Compute hash value of a string key.
hashmap_tcreate_map (void)
 Allocate and initialize a new hashmap.
void insert (hashmap_t *map, const char *name, void *bht_node_p)
 Insert a key-value pair into the hashmap.
void * get (hashmap_t *map, const char *name)
 Retrieve a value from the hashmap by key.
void free_map (hashmap_t *map)
 Free all memory used by the hashmap.

Detailed Description

Simple string-keyed hashmap implementation.

This file provides a basic hash table implementation that maps string keys to generic pointer values (void*). It uses separate chaining (linked lists) for collision handling.

Function Documentation

◆ create_map()

hashmap_t * create_map ( void )

Allocate and initialize a new hashmap.

Creates a hashmap with all buckets initialized to NULL.

Returns
hashmap_t* Pointer to newly allocated hashmap.

◆ free_map()

void free_map ( hashmap_t * map)

Free all memory used by the hashmap.

Releases all keys, nodes, and the hashmap structure itself. The caller is responsible for freeing values stored inside if they were dynamically allocated.

Parameters
mapPointer to hashmap.

◆ get()

void * get ( hashmap_t * map,
const char * name )

Retrieve a value from the hashmap by key.

Performs a lookup in the hashmap and returns the pointer associated with the key, if found.

Parameters
mapPointer to hashmap.
nameNull-terminated string key.
Returns
void* Pointer to stored value, or NULL if not found.

◆ hash()

unsigned int hash ( const char * key)

Compute hash value of a string key.

Uses the djb2 algorithm by Dan Bernstein to generate an unsigned integer hash for the given key.

Parameters
keyNull-terminated string key.
Returns
unsigned int Hash value within the range [0, TABLE_SIZE).

◆ insert()

void insert ( hashmap_t * map,
const char * name,
void * bht_node_p )

Insert a key-value pair into the hashmap.

The key is duplicated internally, so the caller does not need to maintain the lifetime of the original string.

Parameters
mapPointer to hashmap.
nameNull-terminated string key.
bht_node_pPointer to the value to store.