language

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 2c48260242a07ebd4c89c82218ce0ce8f8e9a27d
parent 1c7c967f10ea047471e4c2812716e0ef539f541b
Author: Paul Longtine <paullongtine@gmail.com>
Date:   Fri Dec 18 11:41:47 2015

Outlined hashtable implemenataion

Diffstat:
 src/vm/inc/ht.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 src/vm/inc/ns.h |  6 +++---
 src/vm/src/ht.c |  3 +++
 3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/src/vm/inc/ht.h b/src/vm/inc/ht.h @@ -0,0 +1,44 @@ +/* `ht` Hashtable implementation + */ + +#ifndef HT_H +#define HT_H + +#include <stdlib.h> + +#include "types.h" + +typedef struct ht_entry { + char* key; + var_cont* value; + struct ht_entry *next; +} ht_entry; + +typedef struct ht_t { + int size; + ht_entry** table; +} ht_t; + +/* Creates hashtable of size + */ +ht_t* ht_create(int); + +/* Set a key-value pair + */ +void ht_set(ht_t*, char*, var_cont*); + +/* Get a value + */ +var_cont* ht_get(ht_t*, char*); + +/* Make a new key-value pair + */ +ht_entry* ht_newpair(char*, var_cont*); + +/* Hash a string + */ +int ht_hash(ht_t*, char*); + + + +#endif // HT_H diff --git a/src/vm/inc/ns.h b/src/vm/inc/ns.h @@ -3,9 +3,9 @@ * Each variable that exists and accessed will be via a level on a namespace * instance. For example, at the root of a program, a namespace is initialized * and variables declared at this level are accessable everywhere. When a func - * is called, a new namespace level is initialized and variables declared on that - * level will be destroyed/inaccessable when the function returns and the new - * level is 'popped', going up a level. + * is called, a new namespace level is initialized and variables declared on + * that level will be destroyed/inaccessable when the function returns and the + * new level is 'popped', going up a level. * * When a variable is queued, it will search through all the levels of the * namespace to retreive the proper value. diff --git a/src/vm/src/ht.c b/src/vm/src/ht.c @@ -0,0 +1,3 @@ +#include <stdlib.h> + +#include "ht.h"