Add a hash-index component for block

Summary:
this is the key component extracted from diff: https://reviews.facebook.net/D14271
I separate it to a dedicated patch to make the review easier.

Test Plan: added a unit test and passed it.

Reviewers: haobo, sdong, dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D16245
This commit is contained in:
kailiu
2014-02-18 14:58:55 -08:00
parent 6b9da48a03
commit 906f3dca72
8 changed files with 319 additions and 14 deletions

View File

@@ -39,12 +39,12 @@ class Arena {
// Returns an estimate of the total memory usage of data allocated
// by the arena (exclude the space allocated but not yet used for future
// allocations).
const size_t ApproximateMemoryUsage() {
size_t ApproximateMemoryUsage() const {
return blocks_memory_ + blocks_.capacity() * sizeof(char*) -
alloc_bytes_remaining_;
}
const size_t MemoryAllocatedBytes() { return blocks_memory_; }
size_t MemoryAllocatedBytes() const { return blocks_memory_; }
private:
// Number of bytes allocated in one block

View File

@@ -46,5 +46,4 @@ uint32_t Hash(const char* data, size_t n, uint32_t seed) {
return h;
}
} // namespace rocksdb

View File

@@ -11,6 +11,7 @@
*/
#pragma once
#include <stdint.h>
#include "rocksdb/slice.h"
#if defined(__x86_64__)
#define MURMUR_HASH MurmurHash64A
@@ -29,5 +30,13 @@ typedef unsigned int murmur_t;
unsigned int MurmurHashNeutral2 ( const void * key, int len, unsigned int seed );
#define MurmurHash MurmurHashNeutral2
typedef unsigned int murmur_t;
#endif
// Allow slice to be hashable by murmur hash.
namespace rocksdb {
struct murmur_hash {
size_t operator()(const Slice& slice) const {
return MurmurHash(slice.data(), slice.size(), 0);
}
};
} // rocksdb