#include <stdio.h>

#include "GeneralHashFunctions.h"
#include "bitset.h"

void bloom_add(char *s)
{
    bitset_set_bit(DJBHash(s, 36) % BITSET_SIZE);
    bitset_set_bit(DEKHash(s, 36) % BITSET_SIZE);
}

int bloom_has(char *s)
{
    return bitset_has(DJBHash(s, 36) % BITSET_SIZE) && 
            bitset_has(DEKHash(s, 36) % BITSET_SIZE);
}

void bloom_reset()
{
    bitset_clear_all();
}

void test(char *key)
{
    printf("%d\n", bloom_has(key));
    bloom_add(key);
    printf("%d\n", bloom_has(key)); 
}

int main(int argc, char *argv[])
{
    printf("When booting up the program my bloom filter is using %zu bytes\n", bitset_size());

    char *key1 = "blah";
    char *key2 = "some random string";
    char *key3 = "something really long but it doesn't matter because it gets hashed anyway";

    printf("DJB Hash: %u\n", DJBHash(key1, 36));
    printf("DEK Hash: %u\n", DEKHash(key1, 36));

    test(key1);
    test(key2);
    test(key3);

    printf("With 3 keys set my bloom filter is using %zu bytes\n", bitset_size());

    bloom_reset();

    printf("Next 3 lines should all be 0:\n");
    printf("%d\n", bloom_has(key1));
    printf("%d\n", bloom_has(key2));
    printf("%d\n", bloom_has(key3));

    printf("After reset my bloom filter still uses %zu bytes\n", bitset_size());
}

