Conflicts: include/leveldb/options.h include/leveldb/statistics.h util/options.ccmain
commit
711a30cb30
@ -0,0 +1,102 @@ |
||||
#ifndef STORAGE_LEVELDB_DB_SKIPLISTREP_H_ |
||||
#define STORAGE_LEVELDB_DB_SKIPLISTREP_H_ |
||||
|
||||
#include "leveldb/memtablerep.h" |
||||
#include "db/memtable.h" |
||||
#include "db/skiplist.h" |
||||
|
||||
namespace leveldb { |
||||
|
||||
class Arena; |
||||
|
||||
class SkipListRep : public MemTableRep { |
||||
SkipList<const char*, MemTableRep::KeyComparator&> skip_list_; |
||||
public: |
||||
explicit SkipListRep(MemTableRep::KeyComparator& compare, Arena* arena) |
||||
: skip_list_(compare, arena) { |
||||
} |
||||
|
||||
// Insert key into the list.
|
||||
// REQUIRES: nothing that compares equal to key is currently in the list.
|
||||
virtual void Insert(const char* key) { |
||||
skip_list_.Insert(key); |
||||
} |
||||
|
||||
// Returns true iff an entry that compares equal to key is in the list.
|
||||
virtual bool Contains(const char* key) const { |
||||
return skip_list_.Contains(key); |
||||
} |
||||
|
||||
virtual ~SkipListRep() { } |
||||
|
||||
// Iteration over the contents of a skip list
|
||||
class Iterator : public MemTableRep::Iterator { |
||||
SkipList<const char*, MemTableRep::KeyComparator&>::Iterator iter_; |
||||
public: |
||||
// Initialize an iterator over the specified list.
|
||||
// The returned iterator is not valid.
|
||||
explicit Iterator( |
||||
const SkipList<const char*, MemTableRep::KeyComparator&>* list |
||||
) : iter_(list) { } |
||||
|
||||
virtual ~Iterator() { } |
||||
|
||||
// Returns true iff the iterator is positioned at a valid node.
|
||||
virtual bool Valid() const { |
||||
return iter_.Valid(); |
||||
} |
||||
|
||||
// Returns the key at the current position.
|
||||
// REQUIRES: Valid()
|
||||
virtual const char* key() const { |
||||
return iter_.key(); |
||||
} |
||||
|
||||
// Advances to the next position.
|
||||
// REQUIRES: Valid()
|
||||
virtual void Next() { |
||||
iter_.Next(); |
||||
} |
||||
|
||||
// Advances to the previous position.
|
||||
// REQUIRES: Valid()
|
||||
virtual void Prev() { |
||||
iter_.Prev(); |
||||
} |
||||
|
||||
// Advance to the first entry with a key >= target
|
||||
virtual void Seek(const char* target) { |
||||
iter_.Seek(target); |
||||
} |
||||
|
||||
// Position at the first entry in list.
|
||||
// Final state of iterator is Valid() iff list is not empty.
|
||||
virtual void SeekToFirst() { |
||||
iter_.SeekToFirst(); |
||||
} |
||||
|
||||
// Position at the last entry in list.
|
||||
// Final state of iterator is Valid() iff list is not empty.
|
||||
virtual void SeekToLast() { |
||||
iter_.SeekToLast(); |
||||
} |
||||
}; |
||||
|
||||
virtual std::shared_ptr<MemTableRep::Iterator> GetIterator() { |
||||
return std::shared_ptr<MemTableRep::Iterator>( |
||||
new SkipListRep::Iterator(&skip_list_) |
||||
); |
||||
} |
||||
}; |
||||
|
||||
class SkipListFactory : public MemTableRepFactory { |
||||
public: |
||||
virtual std::shared_ptr<MemTableRep> CreateMemTableRep ( |
||||
MemTableRep::KeyComparator& compare, Arena* arena) { |
||||
return std::shared_ptr<MemTableRep>(new SkipListRep(compare, arena)); |
||||
} |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // STORAGE_LEVELDB_DB_SKIPLISTREP_H_
|
@ -0,0 +1,38 @@ |
||||
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||||
//
|
||||
// Arena class defines memory allocation methods. It's used by memtable and
|
||||
// skiplist.
|
||||
|
||||
#ifndef STORAGE_LEVELDB_INCLUDE_ARENA_H_ |
||||
#define STORAGE_LEVELDB_INCLUDE_ARENA_H_ |
||||
|
||||
namespace leveldb { |
||||
|
||||
class Arena { |
||||
public: |
||||
Arena() {}; |
||||
virtual ~Arena() {}; |
||||
|
||||
// Return a pointer to a newly allocated memory block of "bytes" bytes.
|
||||
virtual char* Allocate(size_t bytes) = 0; |
||||
|
||||
// Allocate memory with the normal alignment guarantees provided by malloc.
|
||||
virtual char* AllocateAligned(size_t bytes) = 0; |
||||
|
||||
// Returns an estimate of the total memory used by arena.
|
||||
virtual const size_t ApproximateMemoryUsage() = 0; |
||||
|
||||
// Returns the total number of bytes in all blocks allocated so far.
|
||||
virtual const size_t MemoryAllocatedBytes() = 0; |
||||
|
||||
private: |
||||
// No copying allowed
|
||||
Arena(const Arena&); |
||||
void operator=(const Arena&); |
||||
}; |
||||
|
||||
} // namespace leveldb
|
||||
|
||||
#endif // STORAGE_LEVELDB_INCLUDE_ARENA_H_
|
@ -0,0 +1,88 @@ |
||||
// This file contains the interface that must be implemented by any collection
|
||||
// to be used as the backing store for a MemTable. Such a collection must
|
||||
// satisfy the following properties:
|
||||
// (1) It does not store duplicate items.
|
||||
// (2) It uses MemTableRep::KeyComparator to compare items for iteration and
|
||||
// equality.
|
||||
// (3) It can be accessed concurrently by multiple readers but need not support
|
||||
// concurrent writes.
|
||||
// (4) Items are never deleted.
|
||||
// The liberal use of assertions is encouraged to enforce (1).
|
||||
|
||||
#ifndef STORAGE_LEVELDB_DB_TABLE_H_ |
||||
#define STORAGE_LEVELDB_DB_TABLE_H_ |
||||
|
||||
#include <memory> |
||||
#include "leveldb/arena.h" |
||||
|
||||
namespace leveldb { |
||||
|
||||
class MemTableRep { |
||||
public: |
||||
// KeyComparator(a, b) returns a negative value if a is less than b, 0 if they
|
||||
// are equal, and a positive value if b is greater than a
|
||||
class KeyComparator { |
||||
public: |
||||
virtual int operator()(const char* a, const char* b) const = 0; |
||||
virtual ~KeyComparator() { } |
||||
}; |
||||
|
||||
// Insert key into the collection. (The caller will pack key and value into a
|
||||
// single buffer and pass that in as the parameter to Insert)
|
||||
// REQUIRES: nothing that compares equal to key is currently in the
|
||||
// collection.
|
||||
virtual void Insert(const char* key) = 0; |
||||
|
||||
// Returns true iff an entry that compares equal to key is in the collection.
|
||||
virtual bool Contains(const char* key) const = 0; |
||||
|
||||
virtual ~MemTableRep() { } |
||||
|
||||
// Iteration over the contents of a skip collection
|
||||
class Iterator { |
||||
public: |
||||
// Initialize an iterator over the specified collection.
|
||||
// The returned iterator is not valid.
|
||||
// explicit Iterator(const MemTableRep* collection);
|
||||
virtual ~Iterator() { }; |
||||
|
||||
// Returns true iff the iterator is positioned at a valid node.
|
||||
virtual bool Valid() const = 0; |
||||
|
||||
// Returns the key at the current position.
|
||||
// REQUIRES: Valid()
|
||||
virtual const char* key() const = 0; |
||||
|
||||
// Advances to the next position.
|
||||
// REQUIRES: Valid()
|
||||
virtual void Next() = 0; |
||||
|
||||
// Advances to the previous position.
|
||||
// REQUIRES: Valid()
|
||||
virtual void Prev() = 0; |
||||
|
||||
// Advance to the first entry with a key >= target
|
||||
virtual void Seek(const char* target) = 0; |
||||
|
||||
// Position at the first entry in collection.
|
||||
// Final state of iterator is Valid() iff collection is not empty.
|
||||
virtual void SeekToFirst() = 0; |
||||
|
||||
// Position at the last entry in collection.
|
||||
// Final state of iterator is Valid() iff collection is not empty.
|
||||
virtual void SeekToLast() = 0; |
||||
}; |
||||
|
||||
virtual std::shared_ptr<Iterator> GetIterator() = 0; |
||||
}; |
||||
|
||||
class MemTableRepFactory { |
||||
public: |
||||
virtual ~MemTableRepFactory() { }; |
||||
virtual std::shared_ptr<MemTableRep> CreateMemTableRep( |
||||
MemTableRep::KeyComparator&, Arena* arena) = 0; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // STORAGE_LEVELDB_DB_TABLE_H_
|
Loading…
Reference in new issue