summaryrefslogtreecommitdiff
path: root/klm/util/ersatz_progress.cc
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-10-18 23:24:01 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-10-18 23:24:01 +0000
commitde379496ee411993dff94e52f393f6e19437a204 (patch)
treea3fdb3b299100384e0a82dd2bc424fd52177d411 /klm/util/ersatz_progress.cc
parent08ff0e0332b562dd9c1f36fce24439db81287c68 (diff)
kenneth's LM preliminary integration
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@681 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'klm/util/ersatz_progress.cc')
-rw-r--r--klm/util/ersatz_progress.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/klm/util/ersatz_progress.cc b/klm/util/ersatz_progress.cc
new file mode 100644
index 00000000..09e3a106
--- /dev/null
+++ b/klm/util/ersatz_progress.cc
@@ -0,0 +1,47 @@
+#include "util/ersatz_progress.hh"
+
+#include <algorithm>
+#include <ostream>
+#include <limits>
+#include <string>
+
+namespace util {
+
+namespace { const unsigned char kWidth = 100; }
+
+ErsatzProgress::ErsatzProgress() : current_(0), next_(std::numeric_limits<std::size_t>::max()), complete_(next_), out_(NULL) {}
+
+ErsatzProgress::~ErsatzProgress() {
+ if (!out_) return;
+ for (; stones_written_ < kWidth; ++stones_written_) {
+ (*out_) << '*';
+ }
+ *out_ << '\n';
+}
+
+ErsatzProgress::ErsatzProgress(std::ostream *to, const std::string &message, std::size_t complete)
+ : current_(0), next_(complete / kWidth), complete_(complete), stones_written_(0), out_(to) {
+ if (!out_) {
+ next_ = std::numeric_limits<std::size_t>::max();
+ return;
+ }
+ *out_ << message << "\n----5---10---15---20---25---30---35---40---45---50---55---60---65---70---75---80---85---90---95--100\n";
+}
+
+void ErsatzProgress::Milestone() {
+ if (!out_) { current_ = 0; return; }
+ if (!complete_) return;
+ unsigned char stone = std::min(static_cast<std::size_t>(kWidth), (current_ * kWidth) / complete_);
+
+ for (; stones_written_ < stone; ++stones_written_) {
+ (*out_) << '*';
+ }
+
+ if (current_ >= complete_) {
+ next_ = std::numeric_limits<std::size_t>::max();
+ } else {
+ next_ = std::max(next_, (stone * complete_) / kWidth);
+ }
+}
+
+} // namespace util