Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Loads dictionary into memory. Returns true if successful else false.
- */
- bool load(const char* dictionary)
- {
- // initialize hashtable
- for(int i = 0; i < 19683; i++)
- hashtable[i] = NULL;
- // file pointer to dictionary
- FILE *fptr;
- // node pointer
- node *n;
- fptr = fopen("./dictionaries/large","r");
- for(int i = 0; i < 143091; i++)
- {
- node* new_node = malloc(sizeof(node));
- new_node->next = NULL;
- fscanf(fptr, "%s", new_node->word);
- double num = 0;
- for(int i = 0; i < 4; i++)
- {
- if(new_node->word[i] == '\0')
- break;
- else
- num += pow (27.0, (4.0 - i - 1))*(1 + new_node->word[i] - 'a');
- }
- int index = (int)num % 19683;
- if (hashtable[index] == NULL)
- {
- hashtable[index] = new_node;
- dic_num++;
- }
- else
- {
- // find end of linked list
- for(n = hashtable[index]; n != NULL; n = n-> next)
- {
- if(n -> next == NULL)
- {
- n->next = new_node;
- dic_num++;
- break;
- }
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement