<commit_before>#include <truth/hashtable.h>
#include <truth/heap.h>
#include <truth/panic.h>
#include <truth/string.h>
#include <truth/types.h>

#define tombstone ((void *)0x1)
#define empty NULL

struct hashdata {
    void *key;
    void *value;
};

#define negative_golden_ratio 0x61C88647

// http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.40.1573&rep=rep1&type=pdf
// Performance and Practice of String Hashing Functions
size_t hash_str(void *str) {
    char *cstr = str;
    size_t hash = negative_golden_ratio;
    for (size_t i = 0; cstr[i] != '\0'; ++i) {
        hash ^= cstr[i] + (hash << 5) + (hash >> 2);
    }
    return hash;
}

enum partial hash_str_comp(void *key_a, void *key_b) {
    // Strings should not be longer than pages. That is nonsense.
    if (!strncmp(key_a, key_b, SMALL_PAGE)) {
        return Partial_Not_Equal;
    } else {
        return Partial_Equal;
    }
}

struct hashtable *hashtable_init(size_t size, hash_f hf, partial_comp_f hc) {
    struct hashtable *table = kmalloc(sizeof(struct hashtable));
    if (table == NULL) {
        return NULL;
    }
    table->comp = hc;
    table->hash = hf;
    table->size = size;
    table->used = 0;
    table->data = kmalloc(size * sizeof(struct hashdata));<commit_msg>Update hashtable to user newer version of strncmp<commit_after>#include <truth/hashtable.h>
#include <truth/heap.h>
#include <truth/panic.h>
#include <truth/string.h>
#include <truth/types.h>

#define tombstone ((void *)0x1)
#define empty NULL

struct hashdata {
    void *key;
    void *value;
};

#define negative_golden_ratio 0x61C88647

// http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.40.1573&rep=rep1&type=pdf
// Performance and Practice of String Hashing Functions
size_t hash_str(void *str) {
    char *cstr = str;
    size_t hash = negative_golden_ratio;
    for (size_t i = 0; cstr[i] != '\0'; ++i) {
        hash ^= cstr[i] + (hash << 5) + (hash >> 2);
    }
    return hash;
}

enum partial hash_str_comp(void *key_a, void *key_b) {
    // Strings should not be longer than pages. That is nonsense.
    if (strncmp(key_a, key_b, Page_Small) != Order_Equal) {
        return Partial_Not_Equal;
    } else {
        return Partial_Equal;
    }
}

struct hashtable *hashtable_init(size_t size, hash_f hf, partial_comp_f hc) {
    struct hashtable *table = kmalloc(sizeof(struct hashtable));
    if (table == NULL) {
        return NULL;
    }
    table->comp = hc;
    table->hash = hf;
    table->size = size;
    table->used = 0;
    table->data = kmalloc(size * sizeof(struct hashdata));
{'fraction_non_alphanumeric': 0.13735408560311285, 'fraction_numerical': 0.020233463035019456, 'mean_word_length': 3.270764119601329, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6851647', 'n_tokens_mistral': 982, 'n_tokens_neox': 937, 'n_words': 233}