Shadow Network Framework  0.0.2-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
hashtable.h File Reference

This file Defines the HashTable functions and macros The HashTable uses lookup3.c 's hashing functions. More...

Go to the source code of this file.

Data Structures

struct  SNF_ht_item_t
 Defines the structure of each element of the HashTable. More...
 
struct  SNF_ht_t
 Defines the structure of the hashTable. More...
 

Typedefs

typedef struct SNF_ht_item_t SNF_ht_item
 Shortened definiton of struct SNF_ht_item_t .
 
typedef struct SNF_ht_t SNF_ht
 Shortened definiton of struct SNF_ht_t .
 

Functions

SNF_htsnf_hashtable_inis (int MaxItems)
 Initializes the HashTime and allocates the needed amount.
 
int snf_hashtable_insert (SNF_ht *HashTable, const char *Key, void *Content)
 Inserts a new Item into a HashTable.
 
SNF_ht_itemsnf_hashtable_lookup (SNF_ht *HashTable, const char *key)
 Fetches (looks up) an Item from a HashTable.
 
SNF_ht_itemsnf_hashtable_delete (SNF_ht *HashTable, const char *key)
 Removed an Item from a HashTable.
 

Detailed Description

This file Defines the HashTable functions and macros The HashTable uses lookup3.c 's hashing functions.

Typedef Documentation

◆ SNF_ht_item

typedef struct SNF_ht_item_t SNF_ht_item

Shortened definiton of struct SNF_ht_item_t .

◆ SNF_ht

typedef struct SNF_ht_t SNF_ht

Shortened definiton of struct SNF_ht_t .

Function Documentation

◆ snf_hashtable_inis()

SNF_ht * snf_hashtable_inis ( int MaxItems)
extern

Initializes the HashTime and allocates the needed amount.

Parameters
MaxItemsThe amount used to calculate the length (See note)
Returns
The results:
  • NULL Upon failure
  • SNF_ht* (The HashTable's pointer)
Note
MaxItems is used to count the smallest power of 2 that could fit MaxItems, the latter would be used as the actual size of the HashTable

Example : if MaxItems == 5 , then the smallest power of 2 is 3, and the actual size of the has table is 8 (2 to the power of 3)

  • this is due to the HashTable where it is recommended the HashTable's lenghth is a power of two for best performance.

◆ snf_hashtable_insert()

int snf_hashtable_insert ( SNF_ht * HashTable,
const char * Key,
void * Content )
extern

Inserts a new Item into a HashTable.

Parameters
HashTableThe Hash tbale to be inserted to.
KeyItem's key
ContentItem's Content
Returns
The results:
  • -1 Upon failure
  • 0 Upon Success

◆ snf_hashtable_lookup()

SNF_ht_item * snf_hashtable_lookup ( SNF_ht * HashTable,
const char * key )
extern

Fetches (looks up) an Item from a HashTable.

Parameters
HashTableThe HashTable to search on.
keyThe Item's Key
Returns
The result of the search:
  • NULL if item was not found or given paramters are invalid
  • SNF_ht_item (HashTable Item's pointer)
Warning
Do not Free the resulting pointer! if you want the item and be able to free it afterwards, use snf_hashtable_delete instead

◆ snf_hashtable_delete()

SNF_ht_item * snf_hashtable_delete ( SNF_ht * HashTable,
const char * key )
extern

Removed an Item from a HashTable.

Parameters
HashTableThe HashTable to search on.
keyThe Item's Key
Returns
The result of the deletion:
  • NULL if item was not found or given paramters are invalid
  • SNF_ht_item (Deleted HashTable Item's pointer)
Note
make sure to free the returned item or else you'd get a memory leak.