作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.9 KiB

Release 1.18 Changes are: * Update version number to 1.18 * Replace the basic fprintf call with a call to fwrite in order to work around the apparent compiler optimization/rewrite failure that we are seeing with the new toolchain/iOS SDKs provided with Xcode6 and iOS8. * Fix ALL the header guards. * Createed a README.md with the LevelDB project description. * A new CONTRIBUTING file. * Don't implicitly convert uint64_t to size_t or int. Either preserve it as uint64_t, or explicitly cast. This fixes MSVC warnings about possible value truncation when compiling this code in Chromium. * Added a DumpFile() library function that encapsulates the guts of the "leveldbutil dump" command. This will allow clients to dump data to their log files instead of stdout. It will also allow clients to supply their own environment. * leveldb: Remove unused function 'ConsumeChar'. * leveldbutil: Remove unused member variables from WriteBatchItemPrinter. * OpenBSD, NetBSD and DragonflyBSD have _LITTLE_ENDIAN, so define PLATFORM_IS_LITTLE_ENDIAN like on FreeBSD. This fixes: * issue #143 * issue #198 * issue #249 * Switch from <cstdatomic> to <atomic>. The former never made it into the standard and doesn't exist in modern gcc versions at all. The later contains everything that leveldb was using from the former. This problem was noticed when porting to Portable Native Client where no memory barrier is defined. The fact that <cstdatomic> is missing normally goes unnoticed since memory barriers are defined for most architectures. * Make Hash() treat its input as unsigned. Before this change LevelDB files from platforms with different signedness of char were not compatible. This change fixes: issue #243 * Verify checksums of index/meta/filter blocks when paranoid_checks set. * Invoke all tools for iOS with xcrun. (This was causing problems with the new XCode 5.1.1 image on pulse.) * include <sys/stat.h> only once, and fix the following linter warning: "Found C system header after C++ system header" * When encountering a corrupted table file, return Status::Corruption instead of Status::InvalidArgument. * Support cygwin as build platform, patch is from https://code.google.com/p/leveldb/issues/detail?id=188 * Fix typo, merge patch from https://code.google.com/p/leveldb/issues/detail?id=159 * Fix typos and comments, and address the following two issues: * issue #166 * issue #241 * Add missing db synchronize after "fillseq" in the benchmark. * Removed unused variable in SeekRandom: value (issue #201)
преди 10 години
  1. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  4. //
  5. // An iterator yields a sequence of key/value pairs from a source.
  6. // The following class defines the interface. Multiple implementations
  7. // are provided by this library. In particular, iterators are provided
  8. // to access the contents of a Table or a DB.
  9. //
  10. // Multiple threads can invoke const methods on an Iterator without
  11. // external synchronization, but if any of the threads may call a
  12. // non-const method, all threads accessing the same Iterator must use
  13. // external synchronization.
  14. #ifndef STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
  15. #define STORAGE_LEVELDB_INCLUDE_ITERATOR_H_
  16. #include "leveldb/export.h"
  17. #include "leveldb/slice.h"
  18. #include "leveldb/status.h"
  19. namespace leveldb {
  20. class LEVELDB_EXPORT Iterator {
  21. public:
  22. Iterator();
  23. Iterator(const Iterator&) = delete;
  24. Iterator& operator=(const Iterator&) = delete;
  25. virtual ~Iterator();
  26. // An iterator is either positioned at a key/value pair, or
  27. // not valid. This method returns true iff the iterator is valid.
  28. virtual bool Valid() const = 0;
  29. // Position at the first key in the source. The iterator is Valid()
  30. // after this call iff the source is not empty.
  31. virtual void SeekToFirst() = 0;
  32. // Position at the last key in the source. The iterator is
  33. // Valid() after this call iff the source is not empty.
  34. virtual void SeekToLast() = 0;
  35. // Position at the first key in the source that is at or past target.
  36. // The iterator is Valid() after this call iff the source contains
  37. // an entry that comes at or past target.
  38. virtual void Seek(const Slice& target) = 0;
  39. // Moves to the next entry in the source. After this call, Valid() is
  40. // true iff the iterator was not positioned at the last entry in the source.
  41. // REQUIRES: Valid()
  42. virtual void Next() = 0;
  43. // Moves to the previous entry in the source. After this call, Valid() is
  44. // true iff the iterator was not positioned at the first entry in source.
  45. // REQUIRES: Valid()
  46. virtual void Prev() = 0;
  47. // Return the key for the current entry. The underlying storage for
  48. // the returned slice is valid only until the next modification of
  49. // the iterator.
  50. // REQUIRES: Valid()
  51. virtual Slice key() const = 0;
  52. // Return the value for the current entry. The underlying storage for
  53. // the returned slice is valid only until the next modification of
  54. // the iterator.
  55. // REQUIRES: Valid()
  56. virtual Slice value() const = 0;
  57. // If an error has occurred, return it. Else return an ok status.
  58. virtual Status status() const = 0;
  59. // Clients are allowed to register function/arg1/arg2 triples that
  60. // will be invoked when this iterator is destroyed.
  61. //
  62. // Note that unlike all of the preceding methods, this method is
  63. // not abstract and therefore clients should not override it.
  64. using CleanupFunction = void (*)(void* arg1, void* arg2);
  65. void RegisterCleanup(CleanupFunction function, void* arg1, void* arg2);
  66. private:
  67. // Cleanup functions are stored in a single-linked list.
  68. // The list's head node is inlined in the iterator.
  69. struct CleanupNode {
  70. // The head node is used if the function pointer is not null.
  71. CleanupFunction function;
  72. void* arg1;
  73. void* arg2;
  74. CleanupNode* next;
  75. // True if the node is not used. Only head nodes might be unused.
  76. bool IsEmpty() const { return function == nullptr; }
  77. // Invokes the cleanup function.
  78. void Run() { assert(function != nullptr); (*function)(arg1, arg2); }
  79. };
  80. CleanupNode cleanup_head_;
  81. };
  82. // Return an empty iterator (yields nothing).
  83. LEVELDB_EXPORT Iterator* NewEmptyIterator();
  84. // Return an empty iterator with the specified status.
  85. LEVELDB_EXPORT Iterator* NewErrorIterator(const Status& status);
  86. } // namespace leveldb
  87. #endif // STORAGE_LEVELDB_INCLUDE_ITERATOR_H_