SRC/hash.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_hash
struct  s_hash_iterator

Functions

struct s_hash ** alloc_hash_table (void)
void free_hash_table (struct s_hash **hash_table)
struct s_hash_iterator start_hash_table_iterator (void)
struct s_hashget_next_hash (struct s_hash **hash_table, struct s_hash_iterator *hash_iterator)
struct s_hashinsert_in_hash_table (struct s_hash **hash_table, char *name, int next_free_index)
struct s_hashget_hash_entry (struct s_hash **hash_table, char *name)

Function Documentation

struct s_hash** alloc_hash_table ( void   )  [read]

Definition at line 13 of file hash.c.

00014 {
00015 
00016 /* Creates a hash table with HASHSIZE different locations (hash values).   */
00017 
00018     struct s_hash **hash_table;
00019 
00020     hash_table = (struct s_hash **)my_calloc(sizeof(struct s_hash *),
00021                                              HASHSIZE);
00022     return (hash_table);
00023 }

Here is the call graph for this function:

Here is the caller graph for this function:

void free_hash_table ( struct s_hash **  hash_table  ) 

Definition at line 27 of file hash.c.

00028 {
00029 
00030 /* Frees all the storage associated with a hash table. */
00031 
00032     int i;
00033     struct s_hash *h_ptr, *temp_ptr;
00034 
00035     for(i = 0; i < HASHSIZE; i++)
00036         {
00037             h_ptr = hash_table[i];
00038             while(h_ptr != NULL)
00039                 {
00040                     free(h_ptr->name);
00041                     temp_ptr = h_ptr->next;
00042                     free(h_ptr);
00043                     h_ptr = temp_ptr;
00044                 }
00045         }
00046 
00047     free(hash_table);
00048 }

Here is the caller graph for this function:

struct s_hash* get_hash_entry ( struct s_hash **  hash_table,
char *  name 
) [read]

Definition at line 147 of file hash.c.

00149 {
00150 
00151 /* Returns the hash entry with this name, or NULL if there is no            *
00152  * corresponding entry.                                                     */
00153 
00154     int i;
00155     struct s_hash *h_ptr;
00156 
00157     i = hash_value(name);
00158     h_ptr = hash_table[i];
00159 
00160     while(h_ptr != NULL)
00161         {
00162             if(strcmp(h_ptr->name, name) == 0)
00163                 return (h_ptr);
00164 
00165             h_ptr = h_ptr->next;
00166         }
00167 
00168     return (NULL);
00169 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct s_hash* get_next_hash ( struct s_hash **  hash_table,
struct s_hash_iterator hash_iterator 
) [read]

Definition at line 67 of file hash.c.

00069 {
00070 
00071 /* Returns the next occupied hash entry, and moves the iterator structure    *
00072  * forward so the next call gets the next entry.                             */
00073 
00074     int i;
00075     struct s_hash *h_ptr;
00076 
00077     i = hash_iterator->i;
00078     h_ptr = hash_iterator->h_ptr;
00079 
00080     while(h_ptr == NULL)
00081         {
00082             i++;
00083             if(i >= HASHSIZE)
00084                 return (NULL);  /* End of table */
00085 
00086             h_ptr = hash_table[i];
00087         }
00088 
00089     hash_iterator->h_ptr = h_ptr->next;
00090     hash_iterator->i = i;
00091     return (h_ptr);
00092 }

Here is the caller graph for this function:

struct s_hash* insert_in_hash_table ( struct s_hash **  hash_table,
char *  name,
int  next_free_index 
) [read]

Definition at line 96 of file hash.c.

00099 {
00100 
00101 /* Adds the string pointed to by name to the hash table, and returns the    *
00102  * hash structure created or updated.  If name is already in the hash table *
00103  * the count member of that hash element is incremented.  Otherwise a new   *
00104  * hash entry with a count of zero and an index of next_free_index is       *
00105  * created.                                                                 */
00106 
00107     int i;
00108     struct s_hash *h_ptr, *prev_ptr;
00109 
00110     i = hash_value(name);
00111     prev_ptr = NULL;
00112     h_ptr = hash_table[i];
00113 
00114     while(h_ptr != NULL)
00115         {
00116             if(strcmp(h_ptr->name, name) == 0)
00117                 {
00118                     h_ptr->count++;
00119                     return (h_ptr);
00120                 }
00121 
00122             prev_ptr = h_ptr;
00123             h_ptr = h_ptr->next;
00124         }
00125 
00126 /* Name string wasn't in the hash table.  Add it. */
00127 
00128     h_ptr = (struct s_hash *)my_malloc(sizeof(struct s_hash));
00129     if(prev_ptr == NULL)
00130         {
00131             hash_table[i] = h_ptr;
00132         }
00133     else
00134         {
00135             prev_ptr->next = h_ptr;
00136         }
00137     h_ptr->next = NULL;
00138     h_ptr->index = next_free_index;
00139     h_ptr->count = 1;
00140     h_ptr->name = (char *)my_malloc((strlen(name) + 1) * sizeof(char));
00141     strcpy(h_ptr->name, name);
00142     return (h_ptr);
00143 }

Here is the call graph for this function:

Here is the caller graph for this function:

struct s_hash_iterator start_hash_table_iterator ( void   )  [read]

Definition at line 52 of file hash.c.

00053 {
00054 
00055 /* Call this routine before you start going through all the elements in    *
00056  * a hash table.  It sets the internal indices to the start of the table.  */
00057 
00058     struct s_hash_iterator hash_iterator;
00059 
00060     hash_iterator.i = -1;
00061     hash_iterator.h_ptr = NULL;
00062     return (hash_iterator);
00063 }

Here is the caller graph for this function:


Generated on Tue Jan 5 15:25:46 2010 for VPR5.0 by  doxygen 1.6.1