xorriso  1.5.4.pl02
About: GNU xorriso creates, loads, manipulates and writes ISO 9660 filesystem images with Rock Ridge extensions. It is suitable for incremental data backup and for production of bootable ISO 9660 images. GNU xorriso is a statical compilation of the libraries libburn, libisofs, libisoburn, and libjte.
  Fossies Dox: xorriso-1.5.4.pl02.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

util_htable.c File Reference
#include "util.h"
#include "libisofs.h"
#include <stdlib.h>
#include <string.h>
Include dependency graph for util_htable.c:

Go to the source code of this file.

Data Structures

struct  iso_hnode
 
struct  iso_htable
 

Functions

static struct iso_hnodeiso_hnode_new (void *key, void *data)
 
int iso_htable_add (IsoHTable *table, void *key, void *data)
 
int iso_htable_put (IsoHTable *table, void *key, void *data)
 
int iso_htable_get (IsoHTable *table, void *key, void **data)
 
int iso_htable_remove (IsoHTable *table, void *key, hfree_data_t free_data)
 
int iso_htable_remove_ptr (IsoHTable *table, void *key, hfree_data_t free_data)
 
unsigned int iso_str_hash (const void *key)
 
void iso_htable_destroy (IsoHTable *table, hfree_data_t free_data)
 
int iso_htable_create (size_t size, hash_funtion_t hash, compare_function_t compare, IsoHTable **table)
 

Function Documentation

◆ iso_hnode_new()

static struct iso_hnode* iso_hnode_new ( void *  key,
void *  data 
)
static

Definition at line 46 of file util_htable.c.

References iso_hnode::data, iso_hnode::key, and iso_hnode::next.

Referenced by iso_htable_add(), and iso_htable_put().

◆ iso_htable_add()

int iso_htable_add ( IsoHTable table,
void *  key,
void *  data 
)

Put an element in a Hash Table. The element will be identified by the given key, that you should use to retrieve the element again.

This function allow duplicates, i.e., two items with the same key. In those cases, the value returned by iso_htable_get() is undefined. If you don't want to allow duplicates, use iso_htable_put() instead;

Both the key and data pointers will be stored internally, so you should free the objects they point to. Use iso_htable_remove() to delete an element from the table.

Definition at line 70 of file util_htable.c.

References iso_htable::cap, iso_hnode::data, iso_htable::hash, iso_hnode_new(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, iso_hnode::key, iso_htable::size, and iso_htable::table.

Referenced by mangle_single_dir().

◆ iso_htable_create()

int iso_htable_create ( size_t  size,
hash_funtion_t  hash,
compare_function_t  compare,
IsoHTable **  table 
)

Create a new hash table.

Parameters
sizeNumber of slots in table.
hashFunction used to generate

Definition at line 321 of file util_htable.c.

References iso_htable::cap, iso_htable::compare, iso_htable::hash, ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, ISO_WRONG_ARG_VALUE, iso_htable::size, and iso_htable::table.

Referenced by mangle_single_dir().

◆ iso_htable_destroy()

void iso_htable_destroy ( IsoHTable table,
hfree_data_t  free_data 
)

Destroy the given hash table.

Note that you're responsible to actually destroy the elements by providing a valid free_data function. You can pass NULL if you only want to delete the hash structure.

Definition at line 290 of file util_htable.c.

References iso_htable::cap, iso_hnode::data, iso_hnode::key, iso_hnode::next, and iso_htable::table.

Referenced by mangle_single_dir().

◆ iso_htable_get()

int iso_htable_get ( IsoHTable table,
void *  key,
void **  data 
)

Retrieve an element from the given table.

Parameters
tableHash table
keyKey of the element that will be removed
dataWill be filled with the element found. Remains untouched if no element with the given key is found.
Returns
1 if found, 0 if not, < 0 on error

Definition at line 144 of file util_htable.c.

References iso_htable::cap, iso_htable::compare, iso_hnode::data, iso_htable::hash, ISO_NULL_POINTER, iso_hnode::key, iso_hnode::next, and iso_htable::table.

Referenced by mangle_single_dir().

◆ iso_htable_put()

int iso_htable_put ( IsoHTable table,
void *  key,
void *  data 
)

Like iso_htable_add(), but this doesn't allow dulpicates.

Returns
1 success, 0 if an item with the same key already exists, < 0 error

Definition at line 100 of file util_htable.c.

References iso_htable::cap, iso_htable::compare, iso_hnode::data, iso_htable::hash, iso_hnode_new(), ISO_NULL_POINTER, ISO_OUT_OF_MEM, ISO_SUCCESS, iso_hnode::key, iso_hnode::next, iso_htable::size, and iso_htable::table.

◆ iso_htable_remove()

int iso_htable_remove ( IsoHTable table,
void *  key,
hfree_data_t  free_data 
)

Remove an item with the given key from the table. In tables that allow duplicates, it is undefined the element that will be deleted.

Parameters
tableHash table
keyKey of the element that will be removed
free_dataFunction that will be called passing as parameters both the key and the element that will be deleted. The user can use it to free the element. You can pass NULL if you don't want to delete the item itself.
Returns
1 success, 0 no element exists with the given key, < 0 error

Definition at line 182 of file util_htable.c.

References iso_htable::cap, iso_htable::compare, iso_hnode::data, iso_htable::hash, ISO_NULL_POINTER, iso_hnode::key, iso_hnode::next, iso_htable::size, and iso_htable::table.

◆ iso_htable_remove_ptr()

int iso_htable_remove_ptr ( IsoHTable table,
void *  key,
hfree_data_t  free_data 
)

Like remove, but instead of checking for key equality using the compare function, it just compare the key pointers. If the table allows duplicates, and you provide different keys (i.e. different pointers) to elements with same key (i.e. same content), this function ensure the exact element is removed.

It has the problem that you must provide the same key pointer, and not just a key whose contents are equal. Moreover, if you use the same key (same pointer) to identify several objects, what of those are removed is undefined.

Parameters
tableHash table
keyKey of the element that will be removed
free_dataFunction that will be called passing as parameters both the key and the element that will be deleted. The user can use it to free the element. You can pass NULL if you don't want to delete the item itself.
Returns
1 success, 0 no element exists with the given key, < 0 error

Definition at line 236 of file util_htable.c.

References iso_htable::cap, iso_hnode::data, iso_htable::hash, ISO_NULL_POINTER, iso_hnode::key, iso_hnode::next, iso_htable::size, and iso_htable::table.

Referenced by mangle_single_dir().

◆ iso_str_hash()

unsigned int iso_str_hash ( const void *  key)

Hash function suitable for keys that are char strings.

Definition at line 270 of file util_htable.c.

References iso_hnode::key.

Referenced by mangle_single_dir().