#pragma once #include #include #include #include namespace gp { template class bloomfilter { constexpr static size_t phys_size = (1 << magnitude) / 32; gp::array< typename gp::either< threading, std::atomic_uint32_t, uint32_t >::type, phys_size > data{}; template static void set_bit(T* value, const int v_pos) { *value |= (1 << v_pos); } template static bool get_bit(T* value, const int v_pos) { return (*value >> v_pos) & 1; } public: void set_hash(hash_type v) { const size_t modulo = v & ((1 << magnitude)-1); const size_t p_pos = modulo / 32; const size_t v_pos = modulo % 32; set_bit(&data[p_pos], v_pos); } bool test_hash(hash_type v) { const size_t modulo = v & ((1 << magnitude)-1); const size_t p_pos = modulo / 32; const size_t v_pos = modulo % 32; return get_bit(&data[p_pos], v_pos); } }; }