Global generation
This commit is contained in:
+9
-3
@@ -1,5 +1,7 @@
|
||||
#include "hashtable.h"
|
||||
|
||||
#include "lisp_string.h"
|
||||
|
||||
#define INITIAL_SIZE 32
|
||||
#define GROWTH_THRESHOLD 0.5
|
||||
#define GROWTH_FACTOR 2
|
||||
@@ -25,16 +27,20 @@ DEFUN(make_hash_table, "make-hash-table", (LispVal * hash_fn, LispVal *eq_fn),
|
||||
}
|
||||
|
||||
static uintptr_t hash_key_for_table(LispHashTable *ht, LispVal *key) {
|
||||
if (NILP(ht->hash_fn)) {
|
||||
if (NILP(ht->hash_fn) || ht->hash_fn == Qid) {
|
||||
return (uintptr_t) key;
|
||||
} else if (ht->hash_fn == Qhash_string) { // needed for initialization
|
||||
return XFIXNUM(Fhash_string(key));
|
||||
}
|
||||
// TODO change
|
||||
abort();
|
||||
}
|
||||
|
||||
static bool compare_keys(LispHashTable *ht, LispVal *key1, LispVal *key2) {
|
||||
if (NILP(ht->eq_fn)) {
|
||||
if (NILP(ht->eq_fn) || ht->eq_fn == Qeq) {
|
||||
return key1 == key2;
|
||||
} else if (ht->eq_fn == Qstrings_equal) { // needed for initialization
|
||||
return !NILP(Fstrings_equal(key1, key2));
|
||||
}
|
||||
// TODO change
|
||||
abort();
|
||||
@@ -70,7 +76,7 @@ static void rehash(LispHashTable *ht, size_t new_size) {
|
||||
}
|
||||
|
||||
static void maybe_rehash(LispHashTable *ht) {
|
||||
if (TABLE_LOAD(ht) > GROWTH_THRESHOLD) {
|
||||
if (TABLE_LOAD(ht) >= GROWTH_THRESHOLD) {
|
||||
rehash(ht, ht->size * GROWTH_FACTOR);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user