RNAlib-2.4.14
|
|
Various implementations of hash table functions. More...
Various implementations of hash table functions.
Hash tables are common data structures that allow for fast random access to the data that is stored within.
Here, we provide an abstract implementation of a hash table interface and a concrete implementation for pairs of secondary structure and corresponding free energy value.
Files | |
file | hash_tables.h |
Implementations of hash table functions. | |
Data Structures | |
struct | vrna_ht_entry_db_t |
Default hash table entry. More... | |
Abstract interface | |
typedef struct vrna_hash_table_s * | vrna_hash_table_t |
A hash table object. More... | |
typedef int( | vrna_callback_ht_compare_entries) (void *x, void *y) |
Callback function to compare two hash table entries. More... | |
typedef unsigned int( | vrna_callback_ht_hash_function) (void *x, unsigned long hashtable_size) |
Callback function to generate a hash key, i.e. hash function. More... | |
typedef int( | vrna_callback_ht_free_entry) (void *x) |
Callback function to free a hash table entry. More... | |
vrna_hash_table_t | vrna_ht_init (unsigned int b, vrna_callback_ht_compare_entries *compare_function, vrna_callback_ht_hash_function *hash_function, vrna_callback_ht_free_entry *free_hash_entry) |
Get an initialized hash table. More... | |
unsigned long | vrna_ht_size (vrna_hash_table_t ht) |
Get the size of the hash table. More... | |
unsigned long | vrna_ht_collisions (struct vrna_hash_table_s *ht) |
Get the number of collisions in the hash table. More... | |
void * | vrna_ht_get (vrna_hash_table_t ht, void *x) |
Get an element from the hash table. More... | |
int | vrna_ht_insert (vrna_hash_table_t ht, void *x) |
Insert an object into a hash table. More... | |
void | vrna_ht_remove (vrna_hash_table_t ht, void *x) |
Remove an object from the hash table. More... | |
void | vrna_ht_clear (vrna_hash_table_t ht) |
Clear the hash table. More... | |
void | vrna_ht_free (vrna_hash_table_t ht) |
Free all memory occupied by the hash table. More... | |
Dot-Bracket / Free Energy entries | |
int | vrna_ht_db_comp (void *x, void *y) |
Default hash table entry comparison. More... | |
unsigned int | vrna_ht_db_hash_func (void *x, unsigned long hashtable_size) |
Default hash function. More... | |
int | vrna_ht_db_free_entry (void *hash_entry) |
Default function to free memory occupied by a hash entry. More... | |
struct vrna_ht_entry_db_t |
typedef struct vrna_hash_table_s* vrna_hash_table_t |
#include <ViennaRNA/datastructures/hash_tables.h>
A hash table object.
typedef int( vrna_callback_ht_compare_entries) (void *x, void *y) |
#include <ViennaRNA/datastructures/hash_tables.h>
Callback function to compare two hash table entries.
x | A hash table entry |
y | A hash table entry |
typedef unsigned int( vrna_callback_ht_hash_function) (void *x, unsigned long hashtable_size) |
#include <ViennaRNA/datastructures/hash_tables.h>
Callback function to generate a hash key, i.e. hash function.
x | A hash table entry |
hashtable_size | The size of the hash table |
x
typedef int( vrna_callback_ht_free_entry) (void *x) |
#include <ViennaRNA/datastructures/hash_tables.h>
Callback function to free a hash table entry.
x | A hash table entry |
vrna_hash_table_t vrna_ht_init | ( | unsigned int | b, |
vrna_callback_ht_compare_entries * | compare_function, | ||
vrna_callback_ht_hash_function * | hash_function, | ||
vrna_callback_ht_free_entry * | free_hash_entry | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Get an initialized hash table.
This function returns a ready-to-use hash table with pre-allocated memory for a particular number of entries.
If all function pointers are NULL
, this function initializes the hash table with default functions, i.e.
compare_function
,hash_function
, andfree_hash_entry
arguments.
hash_bits
is larger than 27 you have to compile it with the flag gcc -mcmodel=large.b | Number of bits for the hash table. This determines the size ( ![]() |
compare_function | A function pointer to compare any two entries in the hash table (may be NULL ) |
hash_function | A function pointer to retrieve the hash value of any entry (may be NULL ) |
free_hash_entry | A function pointer to free the memory occupied by any entry (may be NULL ) |
NULL
on any error unsigned long vrna_ht_size | ( | vrna_hash_table_t | ht | ) |
#include <ViennaRNA/datastructures/hash_tables.h>
Get the size of the hash table.
ht | The hash table |
unsigned long vrna_ht_collisions | ( | struct vrna_hash_table_s * | ht | ) |
#include <ViennaRNA/datastructures/hash_tables.h>
Get the number of collisions in the hash table.
ht | The hash table |
void* vrna_ht_get | ( | vrna_hash_table_t | ht, |
void * | x | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Get an element from the hash table.
This function takes an object x
and performs a look-up whether the object is stored within the hash table ht
. If the object is already stored in ht
, the function simply returns the entry, otherwise it returns NULL
.
ht | The hash table |
x | The hash entry to look-up |
x
if it is stored in ht
, NULL
otherwise int vrna_ht_insert | ( | vrna_hash_table_t | ht, |
void * | x | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Insert an object into a hash table.
Writes the pointer to your hash entry into the table.
ht | The hash table |
x | The hash entry |
void vrna_ht_remove | ( | vrna_hash_table_t | ht, |
void * | x | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Remove an object from the hash table.
Deletes the pointer to your hash entry from the table.
ht | The hash table |
x | The hash entry |
void vrna_ht_clear | ( | vrna_hash_table_t | ht | ) |
#include <ViennaRNA/datastructures/hash_tables.h>
Clear the hash table.
This function removes all entries from the hash table and automatically free's the memory occupied by each entry using the bound () function.
ht | The hash table |
void vrna_ht_free | ( | vrna_hash_table_t | ht | ) |
#include <ViennaRNA/datastructures/hash_tables.h>
Free all memory occupied by the hash table.
This function removes all entries from the hash table by calling the vrna_callback_ht_free_entry() function for each entry. Finally, the memory occupied by the hash table itself is free'd as well.
ht | The hash table |
int vrna_ht_db_comp | ( | void * | x, |
void * | y | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Default hash table entry comparison.
This is the default comparison function for hash table entries. It assumes the both entries x
and y
are of type vrna_ht_entry_db_t and compares the structure
attribute of both entries
x | A hash table entry of type vrna_ht_entry_db_t |
y | A hash table entry of type vrna_ht_entry_db_t |
unsigned int vrna_ht_db_hash_func | ( | void * | x, |
unsigned long | hashtable_size | ||
) |
#include <ViennaRNA/datastructures/hash_tables.h>
Default hash function.
This is the default hash function for hash table insertion/lookup. It assumes that entries are of type vrna_ht_entry_db_t and uses the Bob Jenkins 1996 mix function to create a hash key from the structure
attribute of the hash entry.
x | A hash table entry to compute the key for |
hashtable_size | The size of the hash table |
x
int vrna_ht_db_free_entry | ( | void * | hash_entry | ) |
#include <ViennaRNA/datastructures/hash_tables.h>
Default function to free memory occupied by a hash entry.
This function assumes that hash entries are of type vrna_ht_entry_db_t and free's the memory occupied by that entry.
hash_entry | The hash entry to remove from memory |