#include <stdio.h>

static unsigned int bitfield = 0;

static void bloom_set_bit(unsigned char bit) {
	bitfield |= (2 << bit);
}

static unsigned char bloom_get_bit(unsigned char bit) {
	return (unsigned char)((bitfield & (2 << bit)) >> (bit + 1));
}

static unsigned char bloom_hash_1(const char* s) {
	const char* cur;
	unsigned int result = 0;
	for (cur = s; *cur != '\0'; cur++) result += *cur;
	return (unsigned char)(result % (sizeof(bitfield)*8));
}

void bloom_add(const char* s) {
	unsigned char bit1 = bloom_hash_1(s);
	bloom_set_bit(bit1);
}

int bloom_query(const char* s) {
	unsigned char bit1 = bloom_hash_1(s);
	return bloom_get_bit(bit1);
}

static void _query(const char* s) {
	if (bloom_query(s)) {
		printf("%s: maybe\n", s);
	}
	else {
		printf("%s: no\n", s);
	}
}

int main(int argc, char** argv) {
	bloom_add("jimmy");
	bloom_add("john");
	bloom_add("edgar");
	_query("jimmy");
	_query("john");
	_query("jim");
	_query("edgar");
	_query("ernie");
	_query("timothy");
	_query("stanley");
	_query("geoff");
	_query("bob");
	_query("steven");
	_query("stephen");
	return 0;
}

