This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from helpers import create_lookup, profile_sequence | |
| from load import load_files | |
| # validate command line arguments | |
| if len(sys.argv) < 3: | |
| print("Usage: $ python dna.py [csv path] [dna path]") | |
| # load the files into memory | |
| database, sequence = load_files(sys.argv[1], sys.argv[2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| void free(void *ptr); // free dynamically allocated memory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Unloads dictionary from memory, returning true if successful, else false | |
| bool unload(void) | |
| { | |
| for (int i = 0; i < N; i++) // iterate through buckets | |
| { | |
| node *p = table[i]; // initalize pointer at head of current bucket | |
| while (p != NULL) // while there are nodes left in the bucket | |
| { | |
| node *tmp = p; // alias current node to temp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Returns true if word is in dictionary, else false | |
| bool check(const char *word) | |
| { | |
| int hash_value = hash(word); // get a hash for the word | |
| node *p = table[hash_value]; // point at the head of word's bucket | |
| while (p != NULL) // while there is more nodes to look at | |
| { | |
| if (strcasecmp(word, p->word) == 0) // case insensitive string comparison | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef struct node // Represents a node in a hash table | |
| { | |
| char word[LENGTH + 1]; | |
| struct node *next; | |
| } | |
| node; | |
| const unsigned int N = 26; // Number of buckets in hash table | |
| node *table[N]; // table of nodes, our Hash Table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef struct node // Represents a node in a hash table | |
| { | |
| char word[LENGTH + 1]; | |
| struct node *next; | |
| } | |
| node; | |
| const unsigned int N = 1; // Number of buckets in hash table | |
| node *table[N]; // table of nodes, our Hash Table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Returns number of words in dictionary if loaded, else 0 if not yet loaded | |
| unsigned int size(void) | |
| { | |
| if (dict_size > 0) // if a dictionary is loaded | |
| { | |
| return dict_size // return its size | |
| } | |
| return 0; // default return if no dict is loaded | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Hashes word to a number | |
| unsigned int hash(const char *word) | |
| { | |
| /* djb2 by Dan Bernstring - adapted to be case insensitive */ | |
| unsigned long hash = 5381; | |
| int c; | |
| while ((c = tolower(*word++))) // convert chars to lowercase | |
| { | |
| hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Loads dictionary into memory, returning true if successful, else false | |
| bool load(const char *dictionary) | |
| { | |
| FILE *dict = fopen(dictionary, "r"); // initalize a pointer to our stream | |
| if (dict == NULL) // check for errors | |
| { | |
| return false; // fail fast and return false; // fail fast and return false | |
| } | |
| char word[LENGTH + 1]; // create a buffer to hold our word |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "Express Controller async Function": { | |
| "prefix": "ctrla", | |
| "body": [ | |
| "exports.$1 = async (req, res, next) => {\n\ttry {\n\t\t$0\n\t} catch(err) {\n\t\tnext(err)\n\t}\n}" | |
| ], | |
| "description": "Creates a skeleton for an asynchronous Express controller function" | |
| } | |
| } |