<commit_before>#include <stdlib.h>

#include "ht.h"
#include "util/macros.h"

struct ht*
ht_init(
    struct ht* ht,
    size_t n
) {
    if (ht) {
        ht->buckets = calloc(CONSTPOW_TWO(n), sizeof(*ht->buckets));
        ht->sizeexp = n;
    }

    return ht;
}

void
ht_destroy(
    struct ht* ht,
    struct r_set_cfg const* cfg
) {
    if (ht) {
        size_t i = ht_nbuckets(ht);
        while (i--) {
            // TODO: add cfg
            avl_destroy(&ht->buckets[i].avl, NULL);
        }
        free(ht->buckets);
    }
}

int
ht_del(
    struct ht* ht,
    rs_hash hash,
    void const* cmp,
    struct r_set_cfg const* cfg
) {
    size_t i = hash >> (sizeof(rs_hash) - ht->sizeexp);
    return avl_del(&ht->buckets[i].avl, hash, cmp, cfg);
}

void*
ht_find(
    struct ht const* ht,
    rs_hash hash,
    void const* cmp,
    struct r_set_cfg const* cfg
) {
    size_t i = hash >> (sizeof(hash) - ht->sizeexp);
    return avl_find(&ht->buckets[i].avl, hash, cmp, cfg);
}
<commit_msg>Added implementation for ht_ndel()<commit_after>#include <stdlib.h>

#include "ht.h"
#include "util/macros.h"

struct ht*
ht_init(
    struct ht* ht,
    size_t n
) {
    if (ht) {
        ht->buckets = calloc(CONSTPOW_TWO(n), sizeof(*ht->buckets));
        ht->sizeexp = n;
    }

    return ht;
}

void
ht_destroy(
    struct ht* ht,
    struct r_set_cfg const* cfg
) {
    if (ht) {
        size_t i = ht_nbuckets(ht);
        while (i--) {
            // TODO: add cfg
            avl_destroy(&ht->buckets[i].avl, NULL);
        }
        free(ht->buckets);
    }
}

int
ht_del(
    struct ht* ht,
    rs_hash hash,
    void const* cmp,
    struct r_set_cfg const* cfg
) {
    size_t i = hash >> (sizeof(rs_hash) - ht->sizeexp);
    return avl_del(&ht->buckets[i].avl, hash, cmp, cfg);
}

void*
ht_find(
    struct ht const* ht,
    rs_hash hash,
    void const* cmp,
    struct r_set_cfg const* cfg
) {
    size_t i = hash >> (sizeof(hash) - ht->sizeexp);
    return avl_find(&ht->buckets[i].avl, hash, cmp, cfg);
}

unsigned int
ht_ndel(
    struct ht* ht,
    r_predf pred,
    void* etc,
    struct r_set_cfg* cfg
) {
    size_t i;
    unsigned int sum = 0;

    for (i = 0; i < ht_nbuckets(ht); i++) {
        sum += avl_ndel(&ht->buckets[i].avl, pred, etc, cfg);
    }

    return sum;
}

{'fraction_non_alphanumeric': 0.15056570931244562, 'fraction_numerical': 0.0008703220191470844, 'mean_word_length': 2.2563739376770537, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2924515', 'n_tokens_mistral': 981, 'n_tokens_neox': 957, 'n_words': 223}