/src/rocksdb/table/cuckoo/cuckoo_table_factory.h
Line | Count | Source |
1 | | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | | // This source code is licensed under both the GPLv2 (found in the |
3 | | // COPYING file in the root directory) and Apache 2.0 License |
4 | | // (found in the LICENSE.Apache file in the root directory). |
5 | | |
6 | | #pragma once |
7 | | |
8 | | #include <string> |
9 | | |
10 | | #include "rocksdb/options.h" |
11 | | #include "rocksdb/table.h" |
12 | | #include "util/murmurhash.h" |
13 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | |
16 | | const uint32_t kCuckooMurmurSeedMultiplier = 816922183; |
17 | | static inline uint64_t CuckooHash( |
18 | | const Slice& user_key, uint32_t hash_cnt, bool use_module_hash, |
19 | | uint64_t table_size_, bool identity_as_first_hash, |
20 | 0 | uint64_t (*get_slice_hash)(const Slice&, uint32_t, uint64_t)) { |
21 | | #if !defined NDEBUG || defined OS_WIN |
22 | | // This part is used only in unit tests but we have to keep it for Windows |
23 | | // build as we run test in both debug and release modes under Windows. |
24 | | if (get_slice_hash != nullptr) { |
25 | | return get_slice_hash(user_key, hash_cnt, table_size_); |
26 | | } |
27 | | #else |
28 | 0 | (void)get_slice_hash; |
29 | 0 | #endif |
30 | |
|
31 | 0 | uint64_t value = 0; |
32 | 0 | if (hash_cnt == 0 && identity_as_first_hash) { |
33 | 0 | value = (*reinterpret_cast<const int64_t*>(user_key.data())); |
34 | 0 | } else { |
35 | 0 | value = MurmurHash(user_key.data(), static_cast<int>(user_key.size()), |
36 | 0 | kCuckooMurmurSeedMultiplier * hash_cnt); |
37 | 0 | } |
38 | 0 | if (use_module_hash) { |
39 | 0 | return value % table_size_; |
40 | 0 | } else { |
41 | 0 | return value & (table_size_ - 1); |
42 | 0 | } |
43 | 0 | } Unexecuted instantiation: cuckoo_table_builder.cc:rocksdb::CuckooHash(rocksdb::Slice const&, unsigned int, bool, unsigned long, bool, unsigned long (*)(rocksdb::Slice const&, unsigned int, unsigned long)) Unexecuted instantiation: table_factory.cc:rocksdb::CuckooHash(rocksdb::Slice const&, unsigned int, bool, unsigned long, bool, unsigned long (*)(rocksdb::Slice const&, unsigned int, unsigned long)) Unexecuted instantiation: cuckoo_table_factory.cc:rocksdb::CuckooHash(rocksdb::Slice const&, unsigned int, bool, unsigned long, bool, unsigned long (*)(rocksdb::Slice const&, unsigned int, unsigned long)) Unexecuted instantiation: cuckoo_table_reader.cc:rocksdb::CuckooHash(rocksdb::Slice const&, unsigned int, bool, unsigned long, bool, unsigned long (*)(rocksdb::Slice const&, unsigned int, unsigned long)) |
44 | | |
45 | | // Cuckoo Table is designed for applications that require fast point lookups |
46 | | // but not fast range scans. |
47 | | // |
48 | | // Some assumptions: |
49 | | // - Key length and Value length are fixed. |
50 | | // - Does not support Snapshot. |
51 | | // - Does not support Merge operations. |
52 | | // - Does not support prefix bloom filters. |
53 | | class CuckooTableFactory : public TableFactory { |
54 | | public: |
55 | | explicit CuckooTableFactory( |
56 | | const CuckooTableOptions& table_option = CuckooTableOptions()); |
57 | 0 | ~CuckooTableFactory() {} |
58 | | |
59 | | // Method to allow CheckedCast to work for this class |
60 | 0 | static const char* kClassName() { return kCuckooTableName(); } |
61 | 0 | const char* Name() const override { return kCuckooTableName(); } |
62 | | |
63 | | using TableFactory::NewTableReader; |
64 | | Status NewTableReader( |
65 | | const ReadOptions& ro, const TableReaderOptions& table_reader_options, |
66 | | std::unique_ptr<RandomAccessFileReader>&& file, uint64_t file_size, |
67 | | std::unique_ptr<TableReader>* table, |
68 | | bool prefetch_index_and_filter_in_cache = true) const override; |
69 | | |
70 | | TableBuilder* NewTableBuilder( |
71 | | const TableBuilderOptions& table_builder_options, |
72 | | WritableFileWriter* file) const override; |
73 | | |
74 | | std::string GetPrintableOptions() const override; |
75 | | |
76 | 0 | std::unique_ptr<TableFactory> Clone() const override { |
77 | 0 | return std::make_unique<CuckooTableFactory>(*this); |
78 | 0 | } |
79 | | |
80 | | private: |
81 | | CuckooTableOptions table_options_; |
82 | | }; |
83 | | |
84 | | } // namespace ROCKSDB_NAMESPACE |