diff options
author | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-04-30 08:05:11 +0300 |
---|---|---|
committer | Jeroen Vermeulen <jtv@precisiontranslationtools.com> | 2015-04-30 08:05:11 +0300 |
commit | eca582410006443d0b101a9ae188e302f34f8a03 (patch) | |
tree | 35212762fbe666330205e2a9ef09d16a918d077c /util | |
parent | 85acdc62b1548863a6db18bebb538406cfcfa038 (diff) |
Remove trailing whitespace in C++ files.
Diffstat (limited to 'util')
42 files changed, 231 insertions, 231 deletions
diff --git a/util/bit_packing.cc b/util/bit_packing.cc index d3f998d46..cffd9cf62 100644 --- a/util/bit_packing.cc +++ b/util/bit_packing.cc @@ -9,7 +9,7 @@ namespace { template <bool> struct StaticCheck {}; template <> struct StaticCheck<true> { typedef bool StaticAssertionPassed; }; -// If your float isn't 4 bytes, we're hosed. +// If your float isn't 4 bytes, we're hosed. typedef StaticCheck<sizeof(float) == 4>::StaticAssertionPassed FloatSize; } // namespace @@ -34,7 +34,7 @@ void BitPackingSanity() { if (test57 != ReadInt57(mem, b, 57, (1ULL << 57) - 1)) UTIL_THROW(Exception, "The bit packing routines are failing for your architecture. Please send a bug report with your architecture, operating system, and compiler."); } - // TODO: more checks. + // TODO: more checks. } } // namespace util diff --git a/util/bit_packing.hh b/util/bit_packing.hh index 3cf3cd4a1..b24fd9c1f 100644 --- a/util/bit_packing.hh +++ b/util/bit_packing.hh @@ -1,7 +1,7 @@ #ifndef UTIL_BIT_PACKING_H #define UTIL_BIT_PACKING_H -/* Bit-level packing routines +/* Bit-level packing routines * * WARNING WARNING WARNING: * The write functions assume that memory is zero initially. This makes them @@ -9,10 +9,10 @@ * These routines assume that unaligned access to uint64_t is fast. This is * the case on x86_64. I'm not sure how fast unaligned 64-bit access is on * x86 but my target audience is large language models for which 64-bit is - * necessary. + * necessary. * * Call the BitPackingSanity function to sanity check. Calling once suffices, - * but it may be called multiple times when that's inconvenient. + * but it may be called multiple times when that's inconvenient. * * ARM and MinGW ports contributed by Hideo Okuma and Tomoyuki Yoshimura at * NICT. @@ -25,14 +25,14 @@ #include <endian.h> #elif !defined(_WIN32) && !defined(_WIN64) #include <arpa/nameser_compat.h> -#endif +#endif #include <stdint.h> #include <cstring> namespace util { -// Fun fact: __BYTE_ORDER is wrong on Solaris Sparc, but the version without __ is correct. +// Fun fact: __BYTE_ORDER is wrong on Solaris Sparc, but the version without __ is correct. #if BYTE_ORDER == LITTLE_ENDIAN inline uint8_t BitPackShift(uint8_t bit, uint8_t /*length*/) { return bit; @@ -56,15 +56,15 @@ inline uint64_t ReadOff(const void *base, uint64_t bit_off) { #endif } -/* Pack integers up to 57 bits using their least significant digits. +/* Pack integers up to 57 bits using their least significant digits. * The length is specified using mask: - * Assumes mask == (1 << length) - 1 where length <= 57. + * Assumes mask == (1 << length) - 1 where length <= 57. */ inline uint64_t ReadInt57(const void *base, uint64_t bit_off, uint8_t length, uint64_t mask) { return (ReadOff(base, bit_off) >> BitPackShift(bit_off & 7, length)) & mask; } /* Assumes value < (1 << length) and length <= 57. - * Assumes the memory is zero initially. + * Assumes the memory is zero initially. */ inline void WriteInt57(void *base, uint64_t bit_off, uint8_t length, uint64_t value) { #if defined(__arm) || defined(__arm__) @@ -74,7 +74,7 @@ inline void WriteInt57(void *base, uint64_t bit_off, uint8_t length, uint64_t va value64 |= (value << BitPackShift(bit_off & 7, length)); memcpy(base_off, &value64, sizeof(value64)); #else - *reinterpret_cast<uint64_t*>(reinterpret_cast<uint8_t*>(base) + (bit_off >> 3)) |= + *reinterpret_cast<uint64_t*>(reinterpret_cast<uint8_t*>(base) + (bit_off >> 3)) |= (value << BitPackShift(bit_off & 7, length)); #endif } @@ -99,7 +99,7 @@ inline void WriteInt25(void *base, uint64_t bit_off, uint8_t length, uint32_t va value32 |= (value << BitPackShift(bit_off & 7, length)); memcpy(base_off, &value32, sizeof(value32)); #else - *reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(base) + (bit_off >> 3)) |= + *reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(base) + (bit_off >> 3)) |= (value << BitPackShift(bit_off & 7, length)); #endif } @@ -136,7 +136,7 @@ inline void UnsetSign(float &to) { inline float ReadNonPositiveFloat31(const void *base, uint64_t bit_off) { FloatEnc encoded; encoded.i = ReadOff(base, bit_off) >> BitPackShift(bit_off & 7, 31); - // Sign bit set means negative. + // Sign bit set means negative. encoded.i |= kSignBit; return encoded.f; } @@ -150,7 +150,7 @@ inline void WriteNonPositiveFloat31(void *base, uint64_t bit_off, float value) { void BitPackingSanity(); // Return bits required to store integers upto max_value. Not the most -// efficient implementation, but this is only called a few times to size tries. +// efficient implementation, but this is only called a few times to size tries. uint8_t RequiredBits(uint64_t max_value); struct BitsMask { diff --git a/util/cat_compressed_main.cc b/util/cat_compressed_main.cc index 9ec8e81f7..0c7cda936 100644 --- a/util/cat_compressed_main.cc +++ b/util/cat_compressed_main.cc @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) { char *arg = argv[i]; if (!strcmp(arg, "--")) break; if (!strcmp(arg, "-h") || !strcmp(arg, "--help")) { - std::cerr << + std::cerr << "A cat implementation that interprets compressed files.\n" "Usage: " << argv[0] << " [file1] [file2] ...\n" "If no file is provided, then stdin is read.\n"; diff --git a/util/ersatz_progress.cc b/util/ersatz_progress.cc index 498ab5c58..55c82e7af 100644 --- a/util/ersatz_progress.cc +++ b/util/ersatz_progress.cc @@ -17,7 +17,7 @@ ErsatzProgress::~ErsatzProgress() { if (out_) Finished(); } -ErsatzProgress::ErsatzProgress(uint64_t complete, std::ostream *to, const std::string &message) +ErsatzProgress::ErsatzProgress(uint64_t complete, std::ostream *to, const std::string &message) : current_(0), next_(complete / kWidth), complete_(complete), stones_written_(0), out_(to) { if (!out_) { next_ = std::numeric_limits<uint64_t>::max(); diff --git a/util/ersatz_progress.hh b/util/ersatz_progress.hh index b3bef7fa6..b47aded7d 100644 --- a/util/ersatz_progress.hh +++ b/util/ersatz_progress.hh @@ -6,7 +6,7 @@ #include <stdint.h> // Ersatz version of boost::progress so core language model doesn't depend on -// boost. Also adds option to print nothing. +// boost. Also adds option to print nothing. namespace util { @@ -14,10 +14,10 @@ extern const char kProgressBanner[]; class ErsatzProgress { public: - // No output. + // No output. ErsatzProgress(); - // Null means no output. The null value is useful for passing along the ostream pointer from another caller. + // Null means no output. The null value is useful for passing along the ostream pointer from another caller. explicit ErsatzProgress(uint64_t complete, std::ostream *to = &std::cerr, const std::string &message = ""); ~ErsatzProgress(); diff --git a/util/exception.cc b/util/exception.cc index 32d48516a..588f5eae5 100644 --- a/util/exception.cc +++ b/util/exception.cc @@ -30,7 +30,7 @@ void Exception::SetLocation(const char *file, unsigned int line, const char *fun /* The child class might have set some text, but we want this to come first. * Another option would be passing this information to the constructor, but * then child classes would have to accept constructor arguments and pass - * them down. + * them down. */ text_ = stream_.str(); stream_.str(""); diff --git a/util/exception.hh b/util/exception.hh index 2b503e50e..7a0e7c44a 100644 --- a/util/exception.hh +++ b/util/exception.hh @@ -19,10 +19,10 @@ class Exception : public std::exception { Exception(const Exception &from); Exception &operator=(const Exception &from); - // Not threadsafe, but probably doesn't matter. FWIW, Boost's exception guidance implies that what() isn't threadsafe. + // Not threadsafe, but probably doesn't matter. FWIW, Boost's exception guidance implies that what() isn't threadsafe. const char *what() const throw(); - // For use by the UTIL_THROW macros. + // For use by the UTIL_THROW macros. void SetLocation( const char *file, unsigned int line, @@ -33,7 +33,7 @@ class Exception : public std::exception { private: template <class Except, class Data> friend typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data); - // This helps restrict operator<< defined below. + // This helps restrict operator<< defined below. template <class T> struct ExceptionTag { typedef T Identity; }; @@ -42,9 +42,9 @@ class Exception : public std::exception { mutable std::string text_; }; -/* This implements the normal operator<< for Exception and all its children. +/* This implements the normal operator<< for Exception and all its children. * SFINAE means it only applies to Exception. Think of this as an ersatz - * boost::enable_if. + * boost::enable_if. */ template <class Except, class Data> typename Except::template ExceptionTag<Except&>::Identity operator<<(Except &e, const Data &data) { e.stream_ << data; @@ -63,10 +63,10 @@ template <class Except, class Data> typename Except::template ExceptionTag<Excep /* Create an instance of Exception, add the message Modify, and throw it. * Modify is appended to the what() message and can contain << for ostream - * operations. + * operations. * * do .. while kludge to swallow trailing ; character - * http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html . + * http://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html . * Arg can be a constructor argument to the exception. */ #define UTIL_THROW_BACKEND(Condition, Exception, Arg, Modify) do { \ @@ -123,7 +123,7 @@ class FileOpenException : public Exception { ~FileOpenException() throw() {} }; -// Utilities for overflow checking. +// Utilities for overflow checking. class OverflowException : public Exception { public: OverflowException() throw(); diff --git a/util/file.hh b/util/file.hh index ca52dbfba..bd5873cbc 100644 --- a/util/file.hh +++ b/util/file.hh @@ -73,12 +73,12 @@ class EndOfFileException : public Exception { ~EndOfFileException() throw(); }; -// Open for read only. +// Open for read only. int OpenReadOrThrow(const char *name); -// Create file if it doesn't exist, truncate if it does. Opened for write. +// Create file if it doesn't exist, truncate if it does. Opened for write. int CreateOrThrow(const char *name); -// Return value for SizeFile when it can't size properly. +// Return value for SizeFile when it can't size properly. const uint64_t kBadSize = (uint64_t)-1; uint64_t SizeFile(int fd); uint64_t SizeOrThrow(int fd); diff --git a/util/file_piece.cc b/util/file_piece.cc index 37e492672..c808e7d90 100644 --- a/util/file_piece.cc +++ b/util/file_piece.cc @@ -26,10 +26,10 @@ ParseNumberException::ParseNumberException(StringPiece value) throw() { *this << "Could not parse \"" << value << "\" into a number"; } -// Sigh this is the only way I could come up with to do a _const_ bool. It has ' ', '\f', '\n', '\r', '\t', and '\v' (same as isspace on C locale). +// Sigh this is the only way I could come up with to do a _const_ bool. It has ' ', '\f', '\n', '\r', '\t', and '\v' (same as isspace on C locale). const bool kSpaces[256] = {0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -FilePiece::FilePiece(const char *name, std::ostream *show_progress, std::size_t min_buffer) : +FilePiece::FilePiece(const char *name, std::ostream *show_progress, std::size_t min_buffer) : file_(OpenReadOrThrow(name)), total_size_(SizeFile(file_.get())), page_(SizePage()), progress_(total_size_, total_size_ == kBadSize ? NULL : show_progress, std::string("Reading ") + name) { Initialize(name, show_progress, min_buffer); @@ -42,7 +42,7 @@ std::string NamePossiblyFind(int fd, const char *name) { } } // namespace -FilePiece::FilePiece(int fd, const char *name, std::ostream *show_progress, std::size_t min_buffer) : +FilePiece::FilePiece(int fd, const char *name, std::ostream *show_progress, std::size_t min_buffer) : file_(fd), total_size_(SizeFile(file_.get())), page_(SizePage()), progress_(total_size_, total_size_ == kBadSize ? NULL : show_progress, std::string("Reading ") + NamePossiblyFind(fd, name)) { Initialize(NamePossiblyFind(fd, name).c_str(), show_progress, min_buffer); @@ -56,7 +56,7 @@ FilePiece::FilePiece(std::istream &stream, const char *name, std::size_t min_buf data_.reset(MallocOrThrow(default_map_size_), default_map_size_, scoped_memory::MALLOC_ALLOCATED); position_ = data_.begin(); position_end_ = position_; - + fell_back_.Reset(stream); } @@ -118,9 +118,9 @@ void FilePiece::Initialize(const char *name, std::ostream *show_progress, std::s InitializeNoRead(name, min_buffer); if (total_size_ == kBadSize) { - // So the assertion passes. + // So the assertion passes. fallback_to_read_ = false; - if (show_progress) + if (show_progress) *show_progress << "File " << name << " isn't normal. Using slower read() instead of mmap(). No progress bar." << std::endl; TransitionToRead(); } else { @@ -214,7 +214,7 @@ void FilePiece::Shift() { uint64_t desired_begin = position_ - data_.begin() + mapped_offset_; if (!fallback_to_read_) MMapShift(desired_begin); - // Notice an mmap failure might set the fallback. + // Notice an mmap failure might set the fallback. if (fallback_to_read_) ReadShift(); for (last_space_ = position_end_ - 1; last_space_ >= position_; --last_space_) { @@ -223,13 +223,13 @@ void FilePiece::Shift() { } void FilePiece::MMapShift(uint64_t desired_begin) { - // Use mmap. + // Use mmap. uint64_t ignore = desired_begin % page_; - // Duplicate request for Shift means give more data. + // Duplicate request for Shift means give more data. if (position_ == data_.begin() + ignore && position_) { default_map_size_ *= 2; } - // Local version so that in case of failure it doesn't overwrite the class variable. + // Local version so that in case of failure it doesn't overwrite the class variable. uint64_t mapped_offset = desired_begin - ignore; uint64_t mapped_size; @@ -240,7 +240,7 @@ void FilePiece::MMapShift(uint64_t desired_begin) { mapped_size = default_map_size_; } - // Forcibly clear the existing mmap first. + // Forcibly clear the existing mmap first. data_.reset(); try { MapRead(POPULATE_OR_LAZY, *file_, mapped_offset, mapped_size, data_); @@ -248,7 +248,7 @@ void FilePiece::MMapShift(uint64_t desired_begin) { if (desired_begin) { SeekOrThrow(*file_, desired_begin); } - // The mmap was scheduled to end the file, but now we're going to read it. + // The mmap was scheduled to end the file, but now we're going to read it. at_end_ = false; TransitionToRead(); return; @@ -278,10 +278,10 @@ void FilePiece::TransitionToRead() { void FilePiece::ReadShift() { assert(fallback_to_read_); - // Bytes [data_.begin(), position_) have been consumed. - // Bytes [position_, position_end_) have been read into the buffer. + // Bytes [data_.begin(), position_) have been consumed. + // Bytes [position_, position_end_) have been read into the buffer. - // Start at the beginning of the buffer if there's nothing useful in it. + // Start at the beginning of the buffer if there's nothing useful in it. if (position_ == position_end_) { mapped_offset_ += (position_end_ - data_.begin()); position_ = data_.begin(); @@ -292,7 +292,7 @@ void FilePiece::ReadShift() { if (already_read == default_map_size_) { if (position_ == data_.begin()) { - // Buffer too small. + // Buffer too small. std::size_t valid_length = position_end_ - position_; default_map_size_ *= 2; data_.call_realloc(default_map_size_); diff --git a/util/fixed_array.hh b/util/fixed_array.hh index e2aa8ae7d..610cbdf12 100644 --- a/util/fixed_array.hh +++ b/util/fixed_array.hh @@ -23,22 +23,22 @@ template <class T> class FixedArray { Init(limit); } - /** + /** * Constructs an instance, but does not initialize it. * * Any objects constructed in this manner must be subsequently @ref FixedArray::Init() "initialized" prior to use. * * @see FixedArray::Init() */ - FixedArray() - : newed_end_(NULL) + FixedArray() + : newed_end_(NULL) #ifndef NDEBUG - , allocated_end_(NULL) + , allocated_end_(NULL) #endif {} - /** - * Initialize with a given size bound but do not construct the objects. + /** + * Initialize with a given size bound but do not construct the objects. * * This method is responsible for allocating memory. * Objects stored in this array will be constructed in a location within this allocated memory. @@ -73,37 +73,37 @@ template <class T> class FixedArray { /** Gets a pointer to the first object currently stored in this data structure. */ T *begin() { return static_cast<T*>(block_.get()); } - + /** Gets a const pointer to the last object currently stored in this data structure. */ const T *begin() const { return static_cast<const T*>(block_.get()); } - + /** Gets a pointer to the last object currently stored in this data structure. */ T *end() { return newed_end_; } - + /** Gets a const pointer to the last object currently stored in this data structure. */ const T *end() const { return newed_end_; } /** Gets a reference to the last object currently stored in this data structure. */ T &back() { return *(end() - 1); } - + /** Gets a const reference to the last object currently stored in this data structure. */ const T &back() const { return *(end() - 1); } /** Gets the number of objects currently stored in this data structure. */ std::size_t size() const { return end() - begin(); } - + /** Returns true if there are no objects currently stored in this data structure. */ bool empty() const { return begin() == end(); } - /** - * Gets a reference to the object with index i currently stored in this data structure. + /** + * Gets a reference to the object with index i currently stored in this data structure. * * @param i Index of the object to reference */ T &operator[](std::size_t i) { return begin()[i]; } - - /** - * Gets a const reference to the object with index i currently stored in this data structure. + + /** + * Gets a const reference to the object with index i currently stored in this data structure. * * @param i Index of the object to reference */ diff --git a/util/getopt.c b/util/getopt.c index 992c96b0c..50eef42cc 100644 --- a/util/getopt.c +++ b/util/getopt.c @@ -3,7 +3,7 @@ POSIX getopt for Windows AT&T Public License -Code given out at the 1985 UNIFORUM conference in Dallas. +Code given out at the 1985 UNIFORUM conference in Dallas. */ #ifndef __GNUC__ diff --git a/util/getopt.hh b/util/getopt.hh index 50eab56f4..9b0792b04 100644 --- a/util/getopt.hh +++ b/util/getopt.hh @@ -3,7 +3,7 @@ POSIX getopt for Windows AT&T Public License -Code given out at the 1985 UNIFORUM conference in Dallas. +Code given out at the 1985 UNIFORUM conference in Dallas. */ #ifdef __GNUC__ diff --git a/util/mmap.cc b/util/mmap.cc index b91f181f4..7dcb57ba3 100644 --- a/util/mmap.cc +++ b/util/mmap.cc @@ -56,7 +56,7 @@ void UnmapOrThrow(void *start, size_t length) { scoped_mmap::~scoped_mmap() { if (data_ != (void*)-1) { try { - // Thanks Denis Filimonov for pointing out NFS likes msync first. + // Thanks Denis Filimonov for pointing out NFS likes msync first. SyncOrThrow(data_, size_); UnmapOrThrow(data_, size_); } catch (const util::ErrnoException &e) { diff --git a/util/mmap.hh b/util/mmap.hh index 37feb5bee..9ac604975 100644 --- a/util/mmap.hh +++ b/util/mmap.hh @@ -1,6 +1,6 @@ #ifndef UTIL_MMAP_H #define UTIL_MMAP_H -// Utilities for mmaped files. +// Utilities for mmaped files. #include <cstddef> #include <limits> @@ -14,7 +14,7 @@ class scoped_fd; long SizePage(); -// (void*)-1 is MAP_FAILED; this is done to avoid including the mmap header here. +// (void*)-1 is MAP_FAILED; this is done to avoid including the mmap header here. class scoped_mmap { public: scoped_mmap() : data_((void*)-1), size_(0) {} @@ -47,13 +47,13 @@ class scoped_mmap { /* For when the memory might come from mmap, new char[], or malloc. Uses NULL * and 0 for blanks even though mmap signals errors with (void*)-1). The reset - * function checks that blank for mmap. + * function checks that blank for mmap. */ class scoped_memory { public: typedef enum {MMAP_ALLOCATED, ARRAY_ALLOCATED, MALLOC_ALLOCATED, NONE_ALLOCATED} Alloc; - scoped_memory(void *data, std::size_t size, Alloc source) + scoped_memory(void *data, std::size_t size, Alloc source) : data_(data), size_(size), source_(source) {} scoped_memory() : data_(NULL), size_(0), source_(NONE_ALLOCATED) {} @@ -90,9 +90,9 @@ typedef enum { LAZY, // On linux, pass MAP_POPULATE to mmap. POPULATE_OR_LAZY, - // Populate on Linux. malloc and read on non-Linux. + // Populate on Linux. malloc and read on non-Linux. POPULATE_OR_READ, - // malloc and read. + // malloc and read. READ, // malloc and read in parallel (recommended for Lustre) PARALLEL_READ, @@ -110,18 +110,18 @@ void MapRead(LoadMethod method, int fd, uint64_t offset, std::size_t size, scope void MapAnonymous(std::size_t size, scoped_memory &to); -// Open file name with mmap of size bytes, all of which are initially zero. +// Open file name with mmap of size bytes, all of which are initially zero. void *MapZeroedWrite(int fd, std::size_t size); void *MapZeroedWrite(const char *name, std::size_t size, scoped_fd &file); -// msync wrapper +// msync wrapper void SyncOrThrow(void *start, size_t length); // Forward rolling memory map with no overlap. class Rolling { public: Rolling() {} - + explicit Rolling(void *data) { Init(data); } Rolling(const Rolling ©_from, uint64_t increase = 0); @@ -163,7 +163,7 @@ class Rolling { } return ptr_; } - + // Returns indexed pointer. void *CheckedIndex(uint64_t index) { return static_cast<uint8_t*>(CheckedBase(index)) + index; @@ -178,7 +178,7 @@ class Rolling { void *ptr_; uint64_t current_begin_; uint64_t current_end_; - + scoped_memory mem_; int fd_; diff --git a/util/multi_intersection.hh b/util/multi_intersection.hh index 2955acc72..73954608e 100644 --- a/util/multi_intersection.hh +++ b/util/multi_intersection.hh @@ -22,7 +22,7 @@ template <class Range> struct RangeLessBySize : public std::binary_function<cons * order. sets is changed to truncate the beginning of each sequence to the * location of the match or an empty set. Precondition: sets is not empty * since the intersection over null is the universe and this function does not - * know the universe. + * know the universe. */ template <class Iterator, class Less> boost::optional<typename std::iterator_traits<Iterator>::value_type> FirstIntersectionSorted(std::vector<boost::iterator_range<Iterator> > &sets, const Less &less = std::less<typename std::iterator_traits<Iterator>::value_type>()) { typedef std::vector<boost::iterator_range<Iterator> > Sets; @@ -31,7 +31,7 @@ template <class Iterator, class Less> boost::optional<typename std::iterator_tra assert(!sets.empty()); if (sets.front().empty()) return boost::optional<Value>(); - // Possibly suboptimal to copy for general Value; makes unsigned int go slightly faster. + // Possibly suboptimal to copy for general Value; makes unsigned int go slightly faster. Value highest(sets.front().front()); for (typename Sets::iterator i(sets.begin()); i != sets.end(); ) { i->advance_begin(std::lower_bound(i->begin(), i->end(), highest, less) - i->begin()); diff --git a/util/multi_intersection_test.cc b/util/multi_intersection_test.cc index 970afc171..ee5af7d61 100644 --- a/util/multi_intersection_test.cc +++ b/util/multi_intersection_test.cc @@ -8,7 +8,7 @@ namespace { BOOST_AUTO_TEST_CASE(Empty) { std::vector<boost::iterator_range<const unsigned int*> > sets; - + sets.push_back(boost::iterator_range<const unsigned int*>(static_cast<const unsigned int*>(NULL), static_cast<const unsigned int*>(NULL))); BOOST_CHECK(!FirstIntersection(sets)); } diff --git a/util/murmur_hash.cc b/util/murmur_hash.cc index d04e6ecd0..bf3249869 100644 --- a/util/murmur_hash.cc +++ b/util/murmur_hash.cc @@ -2,8 +2,8 @@ * code is released to the public domain. For business purposes, Murmurhash is * under the MIT license." * This is modified from the original: - * ULL tag on 0xc6a4a7935bd1e995 so this will compile on 32-bit. - * length changed to unsigned int. + * ULL tag on 0xc6a4a7935bd1e995 so this will compile on 32-bit. + * length changed to unsigned int. * placed in namespace util * add MurmurHashNative * default option = 0 for seed @@ -18,7 +18,7 @@ namespace util { //----------------------------------------------------------------------------- // MurmurHash2, 64-bit versions, by Austin Appleby -// The same caveats as 32-bit MurmurHash2 apply here - beware of alignment +// The same caveats as 32-bit MurmurHash2 apply here - beware of alignment // and endian-ness issues if used across multiple platforms. // 64-bit hash for 64-bit platforms @@ -49,12 +49,12 @@ uint64_t MurmurHash64A ( const void * key, std::size_t len, uint64_t seed ) uint64_t k = *data++; #endif - k *= m; - k ^= k >> r; - k *= m; - + k *= m; + k ^= k >> r; + k *= m; + h ^= k; - h *= m; + h *= m; } const unsigned char * data2 = (const unsigned char*)data; @@ -70,13 +70,13 @@ uint64_t MurmurHash64A ( const void * key, std::size_t len, uint64_t seed ) case 1: h ^= uint64_t(data2[0]); h *= m; }; - + h ^= h >> r; h *= m; h ^= h >> r; return h; -} +} // 64-bit hash for 32-bit platforms @@ -151,7 +151,7 @@ uint64_t MurmurHash64B ( const void * key, std::size_t len, uint64_t seed ) return h; } -// Trick to test for 64-bit architecture at compile time. +// Trick to test for 64-bit architecture at compile time. namespace { #ifdef __clang__ #pragma clang diagnostic push diff --git a/util/pcqueue.hh b/util/pcqueue.hh index f74ef18e8..05c868fba 100644 --- a/util/pcqueue.hh +++ b/util/pcqueue.hh @@ -74,10 +74,10 @@ inline void WaitSemaphore (Semaphore &on) { /** * Producer consumer queue safe for multiple producers and multiple consumers. - * T must be default constructable and have operator=. + * T must be default constructable and have operator=. * The value is copied twice for Consume(T &out) or three times for Consume(), * so larger objects should be passed via pointer. - * Strong exception guarantee if operator= throws. Undefined if semaphores throw. + * Strong exception guarantee if operator= throws. Undefined if semaphores throw. */ template <class T> class PCQueue : boost::noncopyable { public: @@ -130,7 +130,7 @@ template <class T> class PCQueue : boost::noncopyable { Consume(ret); return ret; } - + private: // Number of empty spaces in storage_. Semaphore empty_; diff --git a/util/pool.hh b/util/pool.hh index fd55572cd..511b6d995 100644 --- a/util/pool.hh +++ b/util/pool.hh @@ -1,5 +1,5 @@ // Very simple pool. It can only allocate memory. And all of the memory it -// allocates must be freed at the same time. +// allocates must be freed at the same time. #ifndef UTIL_POOL_H #define UTIL_POOL_H @@ -37,7 +37,7 @@ class Pool { // no copying Pool(const Pool &); Pool &operator=(const Pool &); -}; +}; } // namespace util diff --git a/util/probing_hash_table.hh b/util/probing_hash_table.hh index 83fd0ec12..245340ddb 100644 --- a/util/probing_hash_table.hh +++ b/util/probing_hash_table.hh @@ -34,7 +34,7 @@ template <class EntryT, class HashT, class EqualT> class AutoProbing; * Memory management and initialization is externalized to make it easier to * serialize these to disk and load them quickly. * Uses linear probing to find value. - * Only insert and lookup operations. + * Only insert and lookup operations. */ template <class EntryT, class HashT, class EqualT = std::equal_to<typename EntryT::Key> > class ProbingHashTable { public: @@ -50,7 +50,7 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry return buckets * sizeof(Entry); } - // Must be assigned to later. + // Must be assigned to later. ProbingHashTable() : entries_(0) #ifdef DEBUG , initialized_(false) @@ -98,12 +98,12 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry return false; } if (++i == end_) i = begin_; - } + } } void FinishedInserting() {} - // Don't change anything related to GetKey, + // Don't change anything related to GetKey, template <class Key> bool UnsafeMutableFind(const Key key, MutableIterator &out) { #ifdef DEBUG assert(initialized_); @@ -136,7 +136,7 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry if (equal_(got, key)) { out = i; return true; } if (equal_(got, invalid_)) return false; if (++i == end_) i = begin_; - } + } } // Like Find but we're sure it must be there. @@ -253,7 +253,7 @@ template <class EntryT, class HashT, class EqualT = std::equal_to<typename Entry #endif }; -// Resizable linear probing hash table. This owns the memory. +// Resizable linear probing hash table. This owns the memory. template <class EntryT, class HashT, class EqualT = std::equal_to<typename EntryT::Key> > class AutoProbing { private: typedef ProbingHashTable<EntryT, HashT, EqualT> Backend; diff --git a/util/read_compressed.cc b/util/read_compressed.cc index 7f240dd7e..504c579c5 100644 --- a/util/read_compressed.cc +++ b/util/read_compressed.cc @@ -60,7 +60,7 @@ namespace { ReadBase *ReadFactory(int fd, uint64_t &raw_amount, const void *already_data, std::size_t already_size, bool require_compressed); -// Completed file that other classes can thunk to. +// Completed file that other classes can thunk to. class Complete : public ReadBase { public: std::size_t Read(void *, std::size_t, ReadCompressed &) { @@ -121,7 +121,7 @@ template <class Compression> class StreamCompressed : public ReadBase { : file_(fd), in_buffer_(MallocOrThrow(kInputBuffer)), back_(memcpy(in_buffer_.get(), already_data, already_size), already_size) {} - + std::size_t Read(void *to, std::size_t amount, ReadCompressed &thunk) { if (amount == 0) return 0; back_.SetOutput(to, amount); @@ -162,8 +162,8 @@ class GZip { stream_.zfree = Z_NULL; stream_.opaque = Z_NULL; stream_.msg = NULL; - // 32 for zlib and gzip decoding with automatic header detection. - // 15 for maximum window size. + // 32 for zlib and gzip decoding with automatic header detection. + // 15 for maximum window size. UTIL_THROW_IF(Z_OK != inflateInit2(&stream_, 32 + 15), GZException, "Failed to initialize zlib."); } diff --git a/util/read_compressed.hh b/util/read_compressed.hh index 9b36f641c..935a49579 100644 --- a/util/read_compressed.hh +++ b/util/read_compressed.hh @@ -38,10 +38,10 @@ class ReadBase; class ReadCompressed { public: static const std::size_t kMagicSize = 6; - // Must have at least kMagicSize bytes. + // Must have at least kMagicSize bytes. static bool DetectCompressedMagic(const void *from); - // Takes ownership of fd. + // Takes ownership of fd. explicit ReadCompressed(int fd); // Try to avoid using this. Use the fd instead. @@ -53,7 +53,7 @@ class ReadCompressed { ~ReadCompressed(); - // Takes ownership of fd. + // Takes ownership of fd. void Reset(int fd); // Same advice as the constructor. @@ -74,7 +74,7 @@ class ReadCompressed { uint64_t raw_amount_; - // No copying. + // No copying. ReadCompressed(const ReadCompressed &); void operator=(const ReadCompressed &); }; diff --git a/util/scoped.hh b/util/scoped.hh index 60c36c36a..c347a43cc 100644 --- a/util/scoped.hh +++ b/util/scoped.hh @@ -86,7 +86,7 @@ class scoped_malloc : public scoped_c<void, std::free> { struct scoped_delete_array_forward { template <class T> static void Close(T *p) { delete [] p; } }; -// Hat tip to boost. +// Hat tip to boost. template <class T> class scoped_array : public scoped<T, scoped_delete_array_forward> { public: explicit scoped_array(T *p = NULL) : scoped<T, scoped_delete_array_forward>(p) {} diff --git a/util/sorted_uniform.hh b/util/sorted_uniform.hh index 3673a8b5d..ddd2b3f2a 100644 --- a/util/sorted_uniform.hh +++ b/util/sorted_uniform.hh @@ -22,7 +22,7 @@ struct Pivot64 { } }; -// Use when off * width is <2^64. This is guaranteed when each of them is actually a 32-bit value. +// Use when off * width is <2^64. This is guaranteed when each of them is actually a 32-bit value. struct Pivot32 { static inline std::size_t Calc(uint64_t off, uint64_t range, uint64_t width) { return static_cast<std::size_t>((off * width) / (range + 1)); @@ -56,7 +56,7 @@ template <class Iterator, class Accessor> bool BinaryFind( return false; } -// Search the range [before_it + 1, after_it - 1] for key. +// Search the range [before_it + 1, after_it - 1] for key. // Preconditions: // before_v <= key <= after_v // before_v <= all values in the range [before_it + 1, after_it - 1] <= after_v @@ -90,7 +90,7 @@ template <class Iterator, class Accessor, class Pivot> bool SortedUniformFind(co if (key == below) { out = begin; return true; } return false; } - // Make the range [begin, end]. + // Make the range [begin, end]. --end; typename Accessor::Key above(accessor(end)); if (key >= above) { diff --git a/util/sorted_uniform_test.cc b/util/sorted_uniform_test.cc index d9f6fad1e..39f05e57e 100644 --- a/util/sorted_uniform_test.cc +++ b/util/sorted_uniform_test.cc @@ -87,7 +87,7 @@ template <class Key> void RandomTest(Key upper, size_t entries, size_t queries) } std::sort(backing.begin(), backing.end()); - // Random queries. + // Random queries. for (size_t i = 0; i < queries; ++i) { const Key key = gen_key(); Check<Key, unsigned char>(&*backing.begin(), &*backing.end(), reference, key); diff --git a/util/stream/block.hh b/util/stream/block.hh index aa7e28bb1..6a70dba3e 100644 --- a/util/stream/block.hh +++ b/util/stream/block.hh @@ -12,13 +12,13 @@ namespace stream { */ class Block { public: - - /** - * Constructs an empty block. + + /** + * Constructs an empty block. */ Block() : mem_(NULL), valid_size_(0) {} - /** + /** * Constructs a block that encapsulates a segment of memory. * * @param[in] mem The segment of memory to encapsulate @@ -33,9 +33,9 @@ class Block { */ void SetValidSize(std::size_t to) { valid_size_ = to; } - /** + /** * Gets the number of bytes in this block that should be interpreted as valid. - * This is important because read might fill in less than Allocated at EOF. + * This is important because read might fill in less than Allocated at EOF. */ std::size_t ValidSize() const { return valid_size_; } @@ -45,34 +45,34 @@ class Block { /** Gets a const void pointer to the memory underlying this block. */ const void *Get() const { return mem_; } - + /** * Gets a const void pointer to the end of the valid section of memory * encapsulated by this block. */ - const void *ValidEnd() const { + const void *ValidEnd() const { return reinterpret_cast<const uint8_t*>(mem_) + valid_size_; } /** * Returns true if this block encapsulates a valid (non-NULL) block of memory. - * + * * This method is a user-defined implicit conversion function to boolean; - * among other things, this method enables bare instances of this class + * among other things, this method enables bare instances of this class * to be used as the condition of an if statement. */ operator bool() const { return mem_ != NULL; } - + /** * Returns true if this block is empty. - * + * * In other words, if Get()==NULL, this method will return true. */ bool operator!() const { return mem_ == NULL; } - + private: friend class Link; - + /** * Points this block's memory at NULL. * diff --git a/util/stream/chain.cc b/util/stream/chain.cc index 7b68400a8..39f2f3fbb 100644 --- a/util/stream/chain.cc +++ b/util/stream/chain.cc @@ -37,7 +37,7 @@ Chain::Chain(const ChainConfig &config) : config_(config), complete_called_(fals UTIL_THROW_IF(!config.entry_size, ChainConfigException, "zero-size entries."); UTIL_THROW_IF(!config.block_count, ChainConfigException, "block count zero"); UTIL_THROW_IF(config.total_memory < config.entry_size * config.block_count, ChainConfigException, config.total_memory << " total memory, too small for " << config.block_count << " blocks of containing entries of size " << config.entry_size); - // Round down block size to a multiple of entry size. + // Round down block size to a multiple of entry size. block_size_ = config.total_memory / (config.block_count * config.entry_size) * config.entry_size; } @@ -65,7 +65,7 @@ Chain &Chain::operator>>(const PWriteAndRecycle &writer) { void Chain::Wait(bool release_memory) { if (queues_.empty()) { assert(threads_.empty()); - return; // Nothing to wait for. + return; // Nothing to wait for. } if (!complete_called_) CompleteLoop(); threads_.clear(); @@ -84,15 +84,15 @@ void Chain::Wait(bool release_memory) { void Chain::Start() { Wait(false); if (!memory_.get()) { - // Allocate memory. + // Allocate memory. assert(threads_.empty()); assert(queues_.empty()); std::size_t malloc_size = block_size_ * config_.block_count; memory_.reset(MallocOrThrow(malloc_size)); } - // This queue can accomodate all blocks. + // This queue can accomodate all blocks. queues_.push_back(new PCQueue<Block>(config_.block_count)); - // Populate the lead queue with blocks. + // Populate the lead queue with blocks. uint8_t *base = static_cast<uint8_t*>(memory_.get()); for (std::size_t i = 0; i < config_.block_count; ++i) { queues_.front().Produce(Block(base, block_size_)); @@ -124,7 +124,7 @@ Link::Link(const ChainPosition &position) : in_(NULL) { Link::~Link() { if (current_) { - // Probably an exception unwinding. + // Probably an exception unwinding. std::cerr << "Last input should have been poison." << std::endl; // abort(); } else { diff --git a/util/stream/chain.hh b/util/stream/chain.hh index 28dc8060e..0cd8c2aae 100644 --- a/util/stream/chain.hh +++ b/util/stream/chain.hh @@ -23,10 +23,10 @@ class ChainConfigException : public Exception { }; class Chain; - + /** * Encapsulates a @ref PCQueue "producer queue" and a @ref PCQueue "consumer queue" within a @ref Chain "chain". - * + * * Specifies position in chain for Link constructor. */ class ChainPosition { @@ -35,7 +35,7 @@ class ChainPosition { private: friend class Chain; friend class Link; - ChainPosition(PCQueue<Block> &in, PCQueue<Block> &out, Chain *chain, MultiProgress &progress) + ChainPosition(PCQueue<Block> &in, PCQueue<Block> &out, Chain *chain, MultiProgress &progress) : in_(&in), out_(&out), chain_(chain), progress_(progress.Add()) {} PCQueue<Block> *in_, *out_; @@ -45,7 +45,7 @@ class ChainPosition { WorkerProgress progress_; }; - + /** * Encapsulates a worker thread processing data at a given position in the chain. * @@ -53,7 +53,7 @@ class ChainPosition { */ class Thread { public: - + /** * Constructs a new Thread in which the provided Worker is Run(). * @@ -102,7 +102,7 @@ class Recycler { extern const Recycler kRecycle; class WriteAndRecycle; class PWriteAndRecycle; - + /** * Represents a sequence of workers, through which @ref Block "blocks" can pass. */ @@ -113,10 +113,10 @@ class Chain { }; public: - - /** + + /** * Constructs a configured Chain. - * + * * @param config Specifies how to configure the Chain. */ explicit Chain(const ChainConfig &config); @@ -146,7 +146,7 @@ class Chain { std::size_t EntrySize() const { return config_.entry_size; } - + /** * Gets the inital @ref Block::ValidSize "valid size" for @ref Block "blocks" in this chain. * @@ -159,10 +159,10 @@ class Chain { /** Two ways to add to the chain: Add() or operator>>. */ ChainPosition Add(); - /** + /** * Adds a new worker to this chain, * and runs that worker in a new Thread owned by this chain. - * + * * The worker must have a Run method that accepts a position argument. * * @see Thread::operator()() @@ -173,10 +173,10 @@ class Chain { return *this; } - /** + /** * Adds a new worker to this chain (but avoids copying that worker), * and runs that worker in a new Thread owned by this chain. - * + * * The worker must have a Run method that accepts a position argument. * * @see Thread::operator()() @@ -187,14 +187,14 @@ class Chain { return *this; } - // Note that Link and Stream also define operator>> outside this class. + // Note that Link and Stream also define operator>> outside this class. - // To complete the loop, call CompleteLoop(), >> kRecycle, or the destructor. + // To complete the loop, call CompleteLoop(), >> kRecycle, or the destructor. void CompleteLoop() { threads_.push_back(new Thread(Complete(), kRecycle)); } - /** + /** * Adds a Recycler worker to this chain, * and runs that worker in a new Thread owned by this chain. */ @@ -203,17 +203,17 @@ class Chain { return *this; } - /** + /** * Adds a WriteAndRecycle worker to this chain, * and runs that worker in a new Thread owned by this chain. */ Chain &operator>>(const WriteAndRecycle &writer); Chain &operator>>(const PWriteAndRecycle &writer); - // Chains are reusable. Call Wait to wait for everything to finish and free memory. + // Chains are reusable. Call Wait to wait for everything to finish and free memory. void Wait(bool release_memory = true); - // Waits for the current chain to complete (if any) then starts again. + // Waits for the current chain to complete (if any) then starts again. void Start(); bool Running() const { return !queues_.empty(); } @@ -237,29 +237,29 @@ class Chain { }; // Create the link in the worker thread using the position token. -/** +/** * Represents a C++ style iterator over @ref Block "blocks". */ class Link { public: - + // Either default construct and Init or just construct all at once. - + /** * Constructs an @ref Init "initialized" link. * * @see Init */ explicit Link(const ChainPosition &position); - - /** - * Constructs a link that must subsequently be @ref Init "initialized". + + /** + * Constructs a link that must subsequently be @ref Init "initialized". * * @see Init */ Link(); - - /** + + /** * Initializes the link with the input @ref PCQueue "consumer queue" and output @ref PCQueue "producer queue" at a given @ref ChainPosition "position" in the @ref Chain "chain". * * @see Link() @@ -269,7 +269,7 @@ class Link { /** * Destructs the link object. * - * If necessary, this method will pass a poison block + * If necessary, this method will pass a poison block * to this link's output @ref PCQueue "producer queue". * * @see Block::SetToPoison() @@ -290,7 +290,7 @@ class Link { * Gets a pointer to the @ref Block "block" at this link. */ Block *operator->() { return ¤t_; } - + /** * Gets a const pointer to the @ref Block "block" at this link. */ @@ -303,25 +303,25 @@ class Link { /** * Returns true if the @ref Block "block" at this link encapsulates a valid (non-NULL) block of memory. - * + * * This method is a user-defined implicit conversion function to boolean; - * among other things, this method enables bare instances of this class + * among other things, this method enables bare instances of this class * to be used as the condition of an if statement. */ operator bool() const { return current_; } - /** + /** * @ref Block::SetToPoison() "Poisons" the @ref Block "block" at this link, * and passes this now-poisoned block to this link's output @ref PCQueue "producer queue". * * @see Block::SetToPoison() */ void Poison(); - + private: Block current_; PCQueue<Block> *in_, *out_; - + bool poisoned_; WorkerProgress progress_; diff --git a/util/stream/config.hh b/util/stream/config.hh index 6bad36bc5..e94cf3487 100644 --- a/util/stream/config.hh +++ b/util/stream/config.hh @@ -10,11 +10,11 @@ namespace util { namespace stream { * Represents how a chain should be configured. */ struct ChainConfig { - + /** Constructs an configuration with underspecified (or default) parameters. */ ChainConfig() {} - /** + /** * Constructs a chain configuration object. * * @param [in] in_entry_size Number of bytes in each record. @@ -29,26 +29,26 @@ struct ChainConfig { * Number of bytes in each record. */ std::size_t entry_size; - + /** * Number of blocks in the chain. */ std::size_t block_count; - - /** + + /** * Total number of bytes available to the chain. * This value will be divided amongst the blocks in the chain. - * Chain's constructor will make this a multiple of entry_size. + * Chain's constructor will make this a multiple of entry_size. */ std::size_t total_memory; }; - + /** * Represents how a sorter should be configured. */ struct SortConfig { - + /** Filename prefix where temporary files should be placed. */ std::string temp_prefix; diff --git a/util/stream/io.cc b/util/stream/io.cc index fa8467abd..c272d779c 100644 --- a/util/stream/io.cc +++ b/util/stream/io.cc @@ -16,7 +16,7 @@ void Read::Run(const ChainPosition &position) { const std::size_t entry_size = position.GetChain().EntrySize(); for (Link link(position); link; ++link) { std::size_t got = util::ReadOrEOF(file_, link->Get(), block_size); - UTIL_THROW_IF(got % entry_size, ReadSizeException, "File ended with " << got << " bytes, not a multiple of " << entry_size << "."); + UTIL_THROW_IF(got % entry_size, ReadSizeException, "File ended with " << got << " bytes, not a multiple of " << entry_size << "."); if (got == 0) { link.Poison(); return; diff --git a/util/stream/io.hh b/util/stream/io.hh index 8dae2cbff..c3b53bbfe 100644 --- a/util/stream/io.hh +++ b/util/stream/io.hh @@ -18,12 +18,12 @@ class ReadSizeException : public util::Exception { class Read { public: explicit Read(int fd) : file_(fd) {} - void Run(const ChainPosition &position); + void Run(const ChainPosition &position); private: int file_; }; -// Like read but uses pread so that the file can be accessed from multiple threads. +// Like read but uses pread so that the file can be accessed from multiple threads. class PRead { public: explicit PRead(int fd, bool take_own = false) : file_(fd), own_(take_own) {} @@ -60,7 +60,7 @@ class PWriteAndRecycle { }; -// Reuse the same file over and over again to buffer output. +// Reuse the same file over and over again to buffer output. class FileBuffer { public: explicit FileBuffer(int fd) : file_(fd) {} diff --git a/util/stream/line_input.cc b/util/stream/line_input.cc index dafa50207..0ad8800f6 100644 --- a/util/stream/line_input.cc +++ b/util/stream/line_input.cc @@ -14,7 +14,7 @@ void LineInput::Run(const ChainPosition &position) { ReadCompressed reader(fd_); // Holding area for beginning of line to be placed in next block. std::vector<char> carry; - + for (Link block(position); ; ++block) { char *to = static_cast<char*>(block->Get()); char *begin = to; @@ -39,7 +39,7 @@ void LineInput::Run(const ChainPosition &position) { UTIL_THROW_IF(newline < begin, Exception, "Did not find a newline in " << position.GetChain().BlockSize() << " bytes of input of " << NameFromFD(fd_) << ". Is this a text file?"); if (*newline == '\n') break; } - + // Copy everything after the last newline to the carry. carry.clear(); carry.resize(to - (newline + 1)); diff --git a/util/stream/multi_progress.cc b/util/stream/multi_progress.cc index 7d6a6a73a..59750f516 100644 --- a/util/stream/multi_progress.cc +++ b/util/stream/multi_progress.cc @@ -31,9 +31,9 @@ MultiProgress::~MultiProgress() { } void MultiProgress::Activate() { - active_ = + active_ = #if !defined(_WIN32) && !defined(_WIN64) - // Is stderr a terminal? + // Is stderr a terminal? (isatty(2) == 1) #else true diff --git a/util/stream/multi_progress.hh b/util/stream/multi_progress.hh index 41d40075a..f9e6423e3 100644 --- a/util/stream/multi_progress.hh +++ b/util/stream/multi_progress.hh @@ -38,7 +38,7 @@ class MultiProgress { boost::mutex mutex_; - // \0 at the end. + // \0 at the end. char display_[kWidth + 1]; std::size_t character_handout_; @@ -49,10 +49,10 @@ class MultiProgress { class WorkerProgress { public: - // Default contrutor must be initialized with operator= later. + // Default contrutor must be initialized with operator= later. WorkerProgress() : parent_(NULL) {} - // Not threadsafe for the same worker by default. + // Not threadsafe for the same worker by default. WorkerProgress &operator++() { if (++current_ >= next_) { parent_->Milestone(*this); @@ -70,17 +70,17 @@ class WorkerProgress { private: friend class MultiProgress; - WorkerProgress(uint64_t next, MultiProgress &parent, char character) + WorkerProgress(uint64_t next, MultiProgress &parent, char character) : current_(0), next_(next), parent_(&parent), stone_(0), character_(character) {} uint64_t current_, next_; MultiProgress *parent_; - // Previous milestone reached. + // Previous milestone reached. unsigned char stone_; - // Character to display in bar. + // Character to display in bar. char character_; }; diff --git a/util/stream/multi_stream.hh b/util/stream/multi_stream.hh index 2772a7081..b1461f964 100644 --- a/util/stream/multi_stream.hh +++ b/util/stream/multi_stream.hh @@ -50,7 +50,7 @@ class Chains : public util::FixedArray<util::stream::Chain> { } Chains &operator>>(const util::stream::Recycler &recycler) { - for (util::stream::Chain *i = begin(); i != end(); ++i) + for (util::stream::Chain *i = begin(); i != end(); ++i) *i >> recycler; return *this; } diff --git a/util/stream/sort.hh b/util/stream/sort.hh index 9082cfdde..a1e0a8539 100644 --- a/util/stream/sort.hh +++ b/util/stream/sort.hh @@ -3,16 +3,16 @@ * Chain(config) >> Read(file) >> sorter.Unsorted(); * Stream stream; * Chain chain(config) >> sorter.Sorted(internal_config, lazy_config) >> stream; - * - * Note that sorter must outlive any threads that use Unsorted or Sorted. + * + * Note that sorter must outlive any threads that use Unsorted or Sorted. * * Combiners take the form: * bool operator()(void *into, const void *option, const Compare &compare) const * which returns true iff a combination happened. The sorting algorithm - * guarantees compare(into, option). But it does not guarantee - * compare(option, into). + * guarantees compare(into, option). But it does not guarantee + * compare(option, into). * Currently, combining is only done in merge steps, not during on-the-fly - * sort. Use a hash table for that. + * sort. Use a hash table for that. */ #ifndef UTIL_STREAM_SORT_H @@ -37,12 +37,12 @@ namespace util { namespace stream { struct NeverCombine { - template <class Compare> bool operator()(const void *, const void *, const Compare &) const { + template <class Compare> bool operator()(const void *, const void *, const Compare &) const { return false; } }; -// Manage the offsets of sorted blocks in a file. +// Manage the offsets of sorted blocks in a file. class Offsets { public: explicit Offsets(int fd) : log_(fd) { @@ -150,7 +150,7 @@ template <class Compare> class MergeQueue { } private: - // Priority queue contains these entries. + // Priority queue contains these entries. class Entry { public: Entry() {} @@ -195,7 +195,7 @@ template <class Compare> class MergeQueue { uint64_t remaining_, offset_; }; - // Wrapper comparison function for queue entries. + // Wrapper comparison function for queue entries. class Greater : public std::binary_function<const Entry &, const Entry &, bool> { public: explicit Greater(const Compare &compare) : compare_(compare) {} @@ -217,10 +217,10 @@ template <class Compare> class MergeQueue { }; /* A worker object that merges. If the number of pieces to merge exceeds the - * arity, it outputs multiple sorted blocks, recording to out_offsets. + * arity, it outputs multiple sorted blocks, recording to out_offsets. * However, users will only every see a single sorted block out output because * Sort::Sorted insures the arity is higher than the number of pieces before - * returning this. + * returning this. */ template <class Compare, class Combine> class MergingReader { public: @@ -235,7 +235,7 @@ template <class Compare, class Combine> class MergingReader { } void Run(const ChainPosition &position, bool assert_one) { - // Special case: nothing to read. + // Special case: nothing to read. if (!in_offsets_->RemainingBlocks()) { Link l(position); l.Poison(); @@ -267,7 +267,7 @@ template <class Compare, class Combine> class MergingReader { // Populate queue. MergeQueue<Compare> queue(in_, per_buffer, entry_size, compare_); - for (uint8_t *buf = static_cast<uint8_t*>(buffer.get()); + for (uint8_t *buf = static_cast<uint8_t*>(buffer.get()); in_offsets_->RemainingBlocks() && (buf + std::min(per_buffer, in_offsets_->PeekSize()) <= buffer_end);) { uint64_t offset = in_offsets_->TotalOffset(); uint64_t size = in_offsets_->NextSize(); @@ -285,7 +285,7 @@ template <class Compare, class Combine> class MergingReader { } uint64_t written = 0; - // Merge including combiner support. + // Merge including combiner support. memcpy(str.Get(), queue.Top(), entry_size); for (queue.Pop(); !queue.Empty(); queue.Pop()) { if (!combine_(str.Get(), queue.Top(), compare_)) { @@ -300,9 +300,9 @@ template <class Compare, class Combine> class MergingReader { str.Poison(); } - private: + private: void ReadSingle(uint64_t offset, const uint64_t size, const ChainPosition &position) { - // Special case: only one to read. + // Special case: only one to read. const uint64_t end = offset + size; const uint64_t block_size = position.GetChain().BlockSize(); Link l(position); @@ -315,7 +315,7 @@ template <class Compare, class Combine> class MergingReader { (++l).Poison(); return; } - + Compare compare_; Combine combine_; @@ -326,17 +326,17 @@ template <class Compare, class Combine> class MergingReader { private: Offsets *out_offsets_; - + std::size_t buffer_size_; std::size_t total_memory_; }; -// The lazy step owns the remaining files. This keeps track of them. +// The lazy step owns the remaining files. This keeps track of them. template <class Compare, class Combine> class OwningMergingReader : public MergingReader<Compare, Combine> { private: typedef MergingReader<Compare, Combine> P; public: - OwningMergingReader(int data, const Offsets &offsets, std::size_t buffer, std::size_t lazy, const Compare &compare, const Combine &combine) + OwningMergingReader(int data, const Offsets &offsets, std::size_t buffer, std::size_t lazy, const Compare &compare, const Combine &combine) : P(data, NULL, NULL, buffer, lazy, compare, combine), data_(data), offsets_(offsets) {} @@ -353,7 +353,7 @@ template <class Compare, class Combine> class OwningMergingReader : public Mergi Offsets offsets_; }; -// Don't use this directly. Worker that sorts blocks. +// Don't use this directly. Worker that sorts blocks. template <class Compare> class BlockSorter { public: BlockSorter(Offsets &offsets, const Compare &compare) : @@ -362,7 +362,7 @@ template <class Compare> class BlockSorter { void Run(const ChainPosition &position) { const std::size_t entry_size = position.GetChain().EntrySize(); for (Link link(position); link; ++link) { - // Record the size of each block in a separate file. + // Record the size of each block in a separate file. offsets_->Append(link->ValidSize()); void *end = static_cast<uint8_t*>(link->Get()) + link->ValidSize(); #if defined(_WIN32) || defined(_WIN64) @@ -399,7 +399,7 @@ template <class Compare, class Combine = NeverCombine> class Sort { compare_(compare), combine_(combine), entry_size_(in.EntrySize()) { UTIL_THROW_IF(!entry_size_, BadSortConfig, "Sorting entries of size 0"); - // Make buffer_size a multiple of the entry_size. + // Make buffer_size a multiple of the entry_size. config_.buffer_size -= config_.buffer_size % entry_size_; UTIL_THROW_IF(!config_.buffer_size, BadSortConfig, "Sort buffer too small"); UTIL_THROW_IF(config_.total_memory < config_.buffer_size * 4, BadSortConfig, "Sorting memory " << config_.total_memory << " is too small for four buffers (two read and two write)."); @@ -429,7 +429,7 @@ template <class Compare, class Combine = NeverCombine> class Sort { Offsets offsets2(offsets2_file.get()); Offsets *offsets_in = &offsets_, *offsets_out = &offsets2; - // Double buffered writing. + // Double buffered writing. ChainConfig chain_config; chain_config.entry_size = entry_size_; chain_config.block_count = 2; @@ -472,7 +472,7 @@ template <class Compare, class Combine = NeverCombine> class Sort { } // Output to chain, using this amount of memory, maximum, for lazy merge - // sort. + // sort. void Output(Chain &out, std::size_t lazy_memory) { Merge(lazy_memory); out.SetProgressTarget(Size()); @@ -483,15 +483,15 @@ template <class Compare, class Combine = NeverCombine> class Sort { /* If a pipeline step is reading sorted input and writing to a different * sort order, then there's a trade-off between using RAM to read lazily - * (avoiding copying the file) and using RAM to increase block size and, + * (avoiding copying the file) and using RAM to increase block size and, * therefore, decrease the number of merge sort passes in the next - * iteration. - * + * iteration. + * * Merge sort takes log_{arity}(pieces) passes. Thus, each time the chain * block size is multiplied by arity, the number of output passes decreases * by one. Up to a constant, then, log_{arity}(chain) is the number of * passes saved. Chain simply divides the memory evenly over all blocks. - * + * * Lazy sort saves this many passes (up to a constant) * log_{arity}((memory-lazy)/block_count) + 1 * Non-lazy sort saves this many passes (up to the same constant): @@ -535,7 +535,7 @@ template <class Compare, class Combine = NeverCombine> class Sort { const std::size_t entry_size_; }; -// returns bytes to be read on demand. +// returns bytes to be read on demand. template <class Compare, class Combine> uint64_t BlockingSort(Chain &chain, const SortConfig &config, const Compare &compare = Compare(), const Combine &combine = NeverCombine()) { Sort<Compare, Combine> sorter(chain, config, compare, combine); chain.Wait(true); diff --git a/util/stream/sort_test.cc b/util/stream/sort_test.cc index fd7705cd9..fc97ffdbf 100644 --- a/util/stream/sort_test.cc +++ b/util/stream/sort_test.cc @@ -37,7 +37,7 @@ BOOST_AUTO_TEST_CASE(FromShuffled) { shuffled.push_back(i); } std::random_shuffle(shuffled.begin(), shuffled.end()); - + ChainConfig config; config.entry_size = 8; config.total_memory = 800; diff --git a/util/stream/stream.hh b/util/stream/stream.hh index 0e37f5d51..ee1e9fa83 100644 --- a/util/stream/stream.hh +++ b/util/stream/stream.hh @@ -37,7 +37,7 @@ class Stream : boost::noncopyable { ++block_it_; block_it_.Poison(); } - + Stream &operator++() { assert(*this); assert(current_ < end_); diff --git a/util/stream/timer.hh b/util/stream/timer.hh index 06488a17e..9e9573d15 100644 --- a/util/stream/timer.hh +++ b/util/stream/timer.hh @@ -10,7 +10,7 @@ #define UTIL_TIMER(str) boost::timer::auto_cpu_timer timer(std::cerr, 1, (str)) #else //#warning Using Boost older than 1.48. Timing information will not be available.*/ -#define UTIL_TIMER(str) +#define UTIL_TIMER(str) //#endif #endif // UTIL_STREAM_TIMER_H diff --git a/util/thread_pool.hh b/util/thread_pool.hh index d385b1a74..dce987c40 100644 --- a/util/thread_pool.hh +++ b/util/thread_pool.hh @@ -48,7 +48,7 @@ template <class HandlerT> class Worker : boost::noncopyable { PCQueue<Request> &in_; boost::optional<Handler> handler_; - + const Request poison_; boost::thread thread_; diff --git a/util/tokenize_piece.hh b/util/tokenize_piece.hh index 8621705e8..9da5fa3c8 100644 --- a/util/tokenize_piece.hh +++ b/util/tokenize_piece.hh @@ -127,7 +127,7 @@ template <class Find, bool SkipEmpty = false> class TokenIter : public boost::it } else { after_ = StringPiece(found.data() + found.size(), after_.data() - found.data() + after_.size() - found.size()); } - } while (SkipEmpty && current_.data() && current_.empty()); // Compiler should optimize this away if SkipEmpty is false. + } while (SkipEmpty && current_.data() && current_.empty()); // Compiler should optimize this away if SkipEmpty is false. } bool equal(const TokenIter<Find, SkipEmpty> &other) const { diff --git a/util/usage.cc b/util/usage.cc index bbb209306..f2b661014 100644 --- a/util/usage.cc +++ b/util/usage.cc @@ -12,7 +12,7 @@ #include <ctime> #if defined(_WIN32) || defined(_WIN64) // This code lifted from physmem.c in gnulib. See the copyright statement -// below. +// below. # define WIN32_LEAN_AND_MEAN # include <windows.h> /* MEMORYSTATUSEX is missing from older windows headers, so define @@ -256,14 +256,14 @@ template <class Num> uint64_t ParseNum(const std::string &arg) { std::string throwaway; UTIL_THROW_IF_ARG(stream >> throwaway, SizeParseError, (arg), "because there was more cruft " << throwaway << " after the number."); - // Silly sort, using kilobytes as your default unit. + // Silly sort, using kilobytes as your default unit. if (after.empty()) after = "K"; if (after == "%") { uint64_t mem = GuessPhysicalMemory(); UTIL_THROW_IF_ARG(!mem, SizeParseError, (arg), "because % was specified but the physical memory size could not be determined."); return static_cast<uint64_t>(static_cast<double>(value) * static_cast<double>(mem) / 100.0); } - + std::string units("bKMGTPEZY"); std::string::size_type index = units.find(after[0]); UTIL_THROW_IF_ARG(index == std::string::npos, SizeParseError, (arg), "the allowed suffixes are " << units << "%."); |