susumu.yata
null+****@clear*****
Wed Dec 19 20:29:26 JST 2012
susumu.yata 2012-12-19 20:29:26 +0900 (Wed, 19 Dec 2012) New Revision: 19b6e2638a1d155cd88befab3abf5c477dc3e29c https://github.com/groonga/grnxx/commit/19b6e2638a1d155cd88befab3abf5c477dc3e29c Log: Add comments. Modified files: lib/db/blob_vector.hpp lib/db/vector.hpp Modified: lib/db/blob_vector.hpp (+10 -0) =================================================================== --- lib/db/blob_vector.hpp 2012-12-17 15:10:46 +0900 (e60ee6f) +++ lib/db/blob_vector.hpp 2012-12-19 20:29:26 +0900 (737f122) @@ -458,6 +458,8 @@ inline StringBuilder &operator<<(StringBuilder &builder, class BlobVector { public: + // BLOB_VECTOR_CREATE is available as an instance of BlobVectorCreate. + // BLOB_VECTOR_OPEN is available as an instance of BlobVectorOpen. BlobVector() = default; BlobVector(const BlobVectorCreate &, io::Pool pool) : impl_(BlobVectorImpl::create(pool)) {} @@ -478,10 +480,14 @@ class BlobVector { *this = BlobVector(); } + // Access a value. Return a pseudo reference to a value. + // This operator may throw an exception on failure. + // See also Blob and BlobRef. BlobRef operator[](uint64_t id) { return BlobRef(this, id); } + // Get/set blob_vector[id]. Blob get_value(uint64_t id) { return impl_->get_value(id); } @@ -489,6 +495,7 @@ class BlobVector { impl_->set_value(id, value); } + // Append/prepend a value to blob_vector[id]. void append(uint64_t id, const Blob &value) { impl_->append(id, value); } @@ -496,10 +503,12 @@ class BlobVector { impl_->prepend(id, value); } + // Defrag a blob vector. void defrag() { impl_->defrag(); } + // The ID of the lead block. uint32_t block_id() const { return impl_->block_id(); } @@ -516,6 +525,7 @@ class BlobVector { return BLOB_VECTOR_MAX_ID; } + // Free blocks associated with a blob vector. static void unlink(io::Pool pool, uint32_t block_id) { BlobVectorImpl::unlink(pool, block_id); } Modified: lib/db/vector.hpp (+10 -0) =================================================================== --- lib/db/vector.hpp 2012-12-17 15:10:46 +0900 (c0210b1) +++ lib/db/vector.hpp 2012-12-19 20:29:26 +0900 (027acd1) @@ -214,6 +214,7 @@ template <typename T, uint64_t TABLE_SIZE = VECTOR_DEFAULT_TABLE_SIZE, uint64_t SECONDARY_TABLE_SIZE = VECTOR_DEFAULT_SECONDARY_TABLE_SIZE> class Vector { + // Static assertions to reject invalid template parameters. static_assert(PAGE_SIZE >= VECTOR_MIN_PAGE_SIZE, "too small PAGE_SIZE"); static_assert(PAGE_SIZE <= VECTOR_MAX_PAGE_SIZE, "too large PAGE_SIZE"); static_assert((PAGE_SIZE & (PAGE_SIZE - 1)) == 0, @@ -234,6 +235,8 @@ class Vector { public: typedef T Value; + // VECTOR_CREATE is available as an instance of VectorCreate. + // VECTOR_OPEN is available as an instance of VectorOpen. Vector() = default; Vector(const VectorCreate &, io::Pool pool) : impl_(VectorImpl::create(pool, nullptr, sizeof(Value), PAGE_SIZE, @@ -262,6 +265,8 @@ class Vector { return static_cast<bool>(impl_); } + // Access a value. Return a reference to a value. + // This operator may throw an exception on failure. Value &operator[](uint64_t id) { void * const page_address = impl_->get_page_address<PAGE_SIZE, TABLE_SIZE, @@ -269,6 +274,8 @@ class Vector { return static_cast<T *>(page_address)[id % PAGE_SIZE]; } + // Scan values in sequential order and call the given callback for each + // value. This function terminates if the callback returns false. // bool (*callback)(uint64_t id, Value *value); template <typename Callback> bool scan(Callback callback) { @@ -285,6 +292,7 @@ class Vector { }, &callback); } + // The ID of the lead block. uint32_t block_id() const { return impl_->block_id(); } @@ -313,6 +321,7 @@ class Vector { return (PAGE_SIZE * TABLE_SIZE * SECONDARY_TABLE_SIZE) - 1; } + // Free blocks associated with a vector. static void unlink(io::Pool pool, uint32_t block_id) { VectorImpl::unlink(pool, block_id, sizeof(Value), PAGE_SIZE, TABLE_SIZE, SECONDARY_TABLE_SIZE); @@ -321,6 +330,7 @@ class Vector { private: std::shared_ptr<VectorImpl> impl_; + // This function is used to fill a new page with default values. static void fill_page(void *page_address, const void *value) { Value *values = static_cast<Value *>(page_address); for (uint64_t i = 0; i < PAGE_SIZE; ++i) { -------------- next part -------------- HTML����������������������������...Download