Note that there are some explanatory texts on larger screens.

plurals
  1. POC bucket of strings
    primarykey
    data
    text
    <p>I have an assignment to complete . It says I have to read a file which contains 3 millions of strings.<br> I have to read the file and build a structure to hold the strings. This system must be able to answer the question "is this new string present?" </p> <p>I AM also expected to break the <strong>list down into "buckets" of strings so the 'string to match' is able to chose the correct bucket to search in (quickly) and that bucket should contain no more than total/hashMask strings or so (ie 3,000,000 / 0xFFF == 732 objects per bucket).</strong> </p> <p>Now I have created a structure of hash table, list and function to read a file , add and delete function. But I have no clue about the text typed in bold. Do I need to imp-lement something (requested in bold) in Hash function?</p> <p>Below is my sample code</p> <pre><code> #define MAX_NAME 100 /* Linked list structure */ typedef struct list { char *string; int index; struct list *next } list_t ; /* hash table structure*/ typedef struct hashTable { int size; // size of the table list_t **table; // the table element } hash_table_t; HashListType *createHashTable( size_t size) { // allocate hash table ..I know how to do it } unsigned int hash(HashListType *hashTable, void *str ) { uint64_t hashVal; hashVal = 0; while( *str != '\0') { hashVal = *str + (hashVal &lt;&lt; 5 ) - hashVal; str++; } return (hashVal % hashTable-&gt;size); } void addToHashList( HashListType *list, void *obj, uint64_t hash) { // add item of new list to table --&gt; have an idea how to do it } void removeFromHashList(HashListType *list, void *criterion, uint64_t hash ) { // got an idea how to do it } /* this function will read the file (assume one string per line) and create the list of lists (list of buckets), adding one object per string. */ HashList *loadDataSet(char *filename, int hashMask) { // to read a file char readString[ MAX_NAME]; File *fp ; if( (fp = fopen(filename, "r") )== NULL) { printf(" failed to open the file\n"); exit(0); } while( fgets ( readString,MAX_NAME -1, fp ) != NULL) { //need to break the list down into "buckets" of strings so the 'string to match' // is able to chose the correct bucket to search in (quickly) //and that bucket should contain no more than total/hashMask strings or so (ie 3,000,000 / 0xFFF == 732 objects per bucket). } fclose(fp); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload