# # # "linkedlist.h"typedef struct { int ; **; int ;} ; *(int ); *( *);void ( *);void ( *);void ( *, const void *, int );const void *( *, int );void ( *, int );int ( *, int );int (const char *);#
-------------------------------------------
# "hashtable.h"# "linkedlist.h"# "logger.h"# <.># <.># # "dmalloc.h"#typedef struct { int ; const void *;} ;static *(int , const void *); static void ( *);/* * FIXME: Needs to handle growing past initial capacity when table gets full. * Note that it will be a slow operation because all table elements * will have to be rehashed. * * FIXME: Currently uses chaining which isn't great. Probably would be better * to do double hashing or quadratic probing or something. If not, * it would be at least a good idea to maintain which elements get * accessed the most in any given chain and move them to the front. */ *(int ) { * = ; /* * Allocate space for the object and set all fields to zero. */ = (1, sizeof()); if ( == ) { return ; } /* * Allocate space for the table elements */ -> = (, sizeof( *)); if (-> == ) { return ; } /* * Initially set the capacity to the passed size */ -> = ; /* * FIXME: Do something with this. Make it a random number or something. */ -> = 1; /* * Return the HashTable object */ return ;}void ( *) { int = 0; if ( == ) { return; } /* * Free all the chains */ if (-> != ) { for ( = 0; < ->; ++) { if (->[] != ) { (->[]); ->[] = ; } } (->); -> = ; } ();} *( *) { /* * Fixme, write this function! */ return ;}void ( *) { /* * Fixme, write this function! */ }void ( *, const void *, int ) { * = ; * = ; int = -1; if ( == ) { return; } /* * Find out which chain the element should be appended to. */ = (, ); if ( == -1) { return; } /* * If there isn't a LinkedList object at the index * already then put one there */ if (->[] == ) { ->[] = (); if (->[] == ) { return; } } /* * Create a HashTableElement object to hold the given data and hash code */ = (, ); /* * If the element could not be created then bail */ if ( == ) { return; } /* * Create a linked list node with the given element */ = (); if ( == ) { return; } /* * Otherwise, add the node to the linked list */ (->[], );}const void *( *, int ) { * = ; * = ; const void * = ; int = -1; if ( == ) { return ; } /* * Which chain does the desired element reside on? */ = (, ); if ( == -1) { return ; } if (->[] == ) { return ; } /* * Start at the beginning of the chain. */ (->[]); /* * Traverse each node, and compare hash codes for a valid match */ while(( = (->[])) != ) { = ( *) (); if ( == ->) { = ->; break; } } if ( == ) { } return ;}int ( *, int ) { if ( == ) { return -1; } if ( < 0) { return -1; } if (-> == 0) { return -1; } /* * Is their a better hashing function? */ return (-> * ) % ->;}int (const char *) { const char * = ; int = -1, = 0; if ( == ) { return -1; } /* * Generate a reversed (least significant character is most significant * number) radix 128 evaluated polynomial of the input key */ for ( = ; [0] != 0; ++, ++) { int = 0, = 1; for ( = 0; < ; ++) { += 128; } += ([0] * ); } return ;}static *(int , const void *) { * = ; /* * Allocate space for the object and set all fields to zero. */ = (1, sizeof()); if ( == ) { return ; } -> = ; -> = ; return ;}static void ( *) { if ( == ) { return; } ();}