aboutsummaryrefslogtreecommitdiff
path: root/sem3/osc/mm11/regn/symtab.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-15 20:28:59 +0100
committerJulian T <julian@jtle.dk>2020-02-15 20:28:59 +0100
commit8076d839bf69e619f2e504122ec2ceb790a0b978 (patch)
treefa6cb7c649939c3a002676ce142105360d3d2fd6 /sem3/osc/mm11/regn/symtab.c
parentf17e8e195bd1ee3f911ae311dce8e8f7df4f8457 (diff)
Changed to a more consistent codestyle
Diffstat (limited to 'sem3/osc/mm11/regn/symtab.c')
-rw-r--r--sem3/osc/mm11/regn/symtab.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/sem3/osc/mm11/regn/symtab.c b/sem3/osc/mm11/regn/symtab.c
index 8103203..35799a5 100644
--- a/sem3/osc/mm11/regn/symtab.c
+++ b/sem3/osc/mm11/regn/symtab.c
@@ -2,9 +2,10 @@
#include <stdlib.h>
#include <string.h>
-unsigned int hash(char *s) {
+unsigned int hash(char *s)
+{
uint32_t hv = 0;
- for( int i = 0; s[i] != '\0'; i++ ) {
+ 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);
@@ -16,7 +17,8 @@ unsigned int hash(char *s) {
}
-symnode_t *sym_insert(char *var) {
+symnode_t *sym_insert(char *var)
+{
unsigned int index = hash(var);
// Save old value
@@ -24,7 +26,7 @@ symnode_t *sym_insert(char *var) {
// Make new
symbolarray[index] = malloc(sizeof(symnode_t));
- if( symbolarray[index] == NULL ) {
+ if ( symbolarray[index] == NULL ) {
// If malloc failed
symbolarray[index] = oldSym;
return NULL;
@@ -37,12 +39,13 @@ symnode_t *sym_insert(char *var) {
return symbolarray[index];
}
-symnode_t *sym_lookup(char *var) {
+symnode_t *sym_lookup(char *var)
+{
unsigned int index = hash(var);
symnode_t *n = symbolarray[index];
// Look trough list
- while(n != NULL && strcmp(n->name, var) != 0) {
+ while (n != NULL && strcmp(n->name, var) != 0) {
n = n->next;
}