libBf 0.1
|
00001 #ifndef CORE_H 00002 #define CORE_H 00003 00004 #include "hash.h" 00005 #include "partition.h" 00006 #include "store.h" 00007 #include "detail/core.h" 00008 00009 namespace bf { 00010 00016 template < 00017 typename Store = fixed_width<unsigned char, std::allocator<unsigned char>> 00018 , typename Hash = default_hashing<> 00019 , typename Partition = no_partitioning 00020 > 00021 struct core 00022 { 00023 typedef Store store_type; 00024 typedef Hash hash_type; 00025 typedef Partition part_type; 00026 typedef core<store_type, hash_type, part_type> core_type; 00027 00033 core(typename Store::size_type cells, unsigned k, unsigned width = 1, 00034 unsigned parts = 1, 00035 typename std::enable_if< 00036 std::is_same< 00037 store_type 00038 , fixed_width< 00039 typename store_type::block_type 00040 , typename store_type::allocator_type 00041 > 00042 >::value 00043 >* dummy = 0) 00044 : store(cells, width) 00045 , hash(k) 00046 , part(parts) 00047 { 00048 if (parts == 0) 00049 throw std::invalid_argument("zero parts"); 00050 00051 if (cells % parts) 00052 throw std::invalid_argument("parts do not divide cells"); 00053 } 00054 00055 // template <typename S, typename H, typename P> 00056 void swap(core_type& c) // no throw 00057 { 00058 std::swap(store, c.store); 00059 std::swap(hash, c.hash); 00060 std::swap(part, c.part); 00061 } 00062 00068 template <typename T> 00069 std::vector<typename store_type::size_type> positions(const T& x) const 00070 { 00071 return detail::core::positions(x, *this); 00072 } 00073 00074 store_type store; 00075 hash_type hash; 00076 part_type part; 00077 }; 00078 00079 } // namespace bf 00080 00081 #endif