diff options
author | Julian T <julian@jtle.dk> | 2020-10-12 16:26:42 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-10-12 16:54:48 +0200 |
commit | 4e05a55e373bd315e721d534a1711fec4c0054c5 (patch) | |
tree | 4fc0141760c2730ed79aaa4c7aa60ea45cc66cc0 /sem3/osc/mm11 | |
parent | b7f9cf43c8a9ab3400cbb30d5e1cadb0c6c2cf23 (diff) |
Moved to linux kernel inspired clang-format
Diffstat (limited to 'sem3/osc/mm11')
-rw-r--r-- | sem3/osc/mm11/regn/symtab.c | 63 | ||||
-rw-r--r-- | sem3/osc/mm11/regn/symtab.h | 14 |
2 files changed, 38 insertions, 39 deletions
diff --git a/sem3/osc/mm11/regn/symtab.c b/sem3/osc/mm11/regn/symtab.c index 35799a5..9edcf72 100644 --- a/sem3/osc/mm11/regn/symtab.c +++ b/sem3/osc/mm11/regn/symtab.c @@ -4,50 +4,49 @@ unsigned int hash(char *s) { - uint32_t hv = 0; - for ( int i = 0; s[i] != '\0'; i++ ) { - // take MSB 6 bits of hv and xors with LSB of s[i] - uint32_t v = ( hv >> 26 ) ^ (s[i] & 0x3f); - - // Push those back on hv - hv = (hv << 4) | v; - } - // Return appropriate size - return hv % HASHSIZE; + uint32_t hv = 0; + for (int i = 0; s[i] != '\0'; i++) { + // take MSB 6 bits of hv and xors with LSB of s[i] + uint32_t v = (hv >> 26) ^ (s[i] & 0x3f); + + // Push those back on hv + hv = (hv << 4) | v; + } + // Return appropriate size + return hv % HASHSIZE; } - symnode_t *sym_insert(char *var) { - unsigned int index = hash(var); + unsigned int index = hash(var); - // Save old value - symnode_t *oldSym = symbolarray[index]; + // Save old value + symnode_t *oldSym = symbolarray[index]; - // Make new - symbolarray[index] = malloc(sizeof(symnode_t)); - if ( symbolarray[index] == NULL ) { - // If malloc failed - symbolarray[index] = oldSym; - return NULL; - } + // Make new + symbolarray[index] = malloc(sizeof(symnode_t)); + if (symbolarray[index] == NULL) { + // If malloc failed + symbolarray[index] = oldSym; + return NULL; + } - // Link old one - symbolarray[index]->next = oldSym; - symbolarray[index]->name = var; + // Link old one + symbolarray[index]->next = oldSym; + symbolarray[index]->name = var; - return symbolarray[index]; + return symbolarray[index]; } symnode_t *sym_lookup(char *var) { - unsigned int index = hash(var); - symnode_t *n = symbolarray[index]; + unsigned int index = hash(var); + symnode_t *n = symbolarray[index]; - // Look trough list - while (n != NULL && strcmp(n->name, var) != 0) { - n = n->next; - } + // Look trough list + while (n != NULL && strcmp(n->name, var) != 0) { + n = n->next; + } - return n; + return n; } diff --git a/sem3/osc/mm11/regn/symtab.h b/sem3/osc/mm11/regn/symtab.h index c61f3a8..b7b93ec 100644 --- a/sem3/osc/mm11/regn/symtab.h +++ b/sem3/osc/mm11/regn/symtab.h @@ -2,19 +2,19 @@ #define HASHSIZE 100 typedef struct symnode_struct { - char *name; - struct symnode_struct *next; - double value; + char *name; + struct symnode_struct *next; + double value; } symnode_t; symnode_t *sym_insert(char *var); symnode_t *sym_lookup(char *var); struct symnode { - struct symnode *next; - char *name; - int type; - double value; + struct symnode *next; + char *name; + int type; + double value; }; symnode_t *symbolarray[HASHSIZE]; |