14 static std::string EncodeKey(
int k) {
19 static int DecodeKey(
const Slice& k) {
20 assert(k.size() == 4);
23 static void* EncodeValue(uintptr_t v) {
return reinterpret_cast<void*
>(v); }
24 static int DecodeValue(
void* v) {
return reinterpret_cast<uintptr_t
>(v); }
50 const int r = (handle == NULL) ? -1 : DecodeValue(cache_->
Value(handle));
63 cache_->
Erase(EncodeKey(key));
113 ASSERT_EQ(101, DecodeValue(cache_->Value(h1)));
117 ASSERT_EQ(102, DecodeValue(cache_->Value(h2)));
140 for (
int i = 0; i < kCacheSize + 100; i++) {
141 Insert(1000+i, 2000+i);
153 const int kLight = 1;
154 const int kHeavy = 10;
157 while (added < 2*kCacheSize) {
158 const int weight = (index & 1) ? kLight : kHeavy;
159 Insert(index, 1000+index, weight);
164 int cached_weight = 0;
165 for (
int i = 0; i < index; i++) {
166 const int weight = (i & 1 ? kLight : kHeavy);
169 cached_weight += weight;
173 ASSERT_LE(cached_weight, kCacheSize + kCacheSize/10);
184 int main(
int argc,
char** argv) {
static CacheTest * current_
void PutFixed32(std::string *dst, uint32_t value)
static const int kCacheSize
virtual void * Value(Handle *handle)=0
virtual void Release(Handle *handle)=0
virtual void Erase(const Slice &key)=0
virtual Handle * Insert(const Slice &key, void *value, size_t charge, void(*deleter)(const Slice &key, void *value))=0
uint32_t DecodeFixed32(const char *ptr)
void Insert(int key, int value, int charge=1)
virtual Handle * Lookup(const Slice &key)=0
std::vector< int > deleted_values_
unsigned long long uint64_t
TEST(CorruptionTest, Recovery)
static void Deleter(const Slice &key, void *v)
Cache * NewLRUCache(size_t capacity)
int main(int argc, char **argv)
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
std::vector< int > deleted_keys_