| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "courgette/adjustment_method.h" | 5 #include "courgette/adjustment_method.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| 11 #include <set> | 11 #include <set> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include <iostream> | 15 #include <iostream> |
| 16 | 16 |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 #include "base/format_macros.h" |
| 18 #include "base/logging.h" | 19 #include "base/logging.h" |
| 19 #include "base/string_util.h" | 20 #include "base/string_util.h" |
| 20 | 21 |
| 21 #include "courgette/assembly_program.h" | 22 #include "courgette/assembly_program.h" |
| 22 #include "courgette/courgette.h" | 23 #include "courgette/courgette.h" |
| 23 #include "courgette/encoded_program.h" | 24 #include "courgette/encoded_program.h" |
| 24 #include "courgette/image_info.h" | 25 #include "courgette/image_info.h" |
| 25 | 26 |
| 26 /* | 27 /* |
| 27 | 28 |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 | 455 |
| 455 std::string ToString(const Shingle* instance) { | 456 std::string ToString(const Shingle* instance) { |
| 456 std::string s; | 457 std::string s; |
| 457 const char* sep = "<"; | 458 const char* sep = "<"; |
| 458 for (size_t i = 0; i < Shingle::kWidth; ++i) { | 459 for (size_t i = 0; i < Shingle::kWidth; ++i) { |
| 459 // StringAppendF(&s, "%s%x ", sep, instance.at(i)->label_->rva_); | 460 // StringAppendF(&s, "%s%x ", sep, instance.at(i)->label_->rva_); |
| 460 s += sep; | 461 s += sep; |
| 461 s += ToString(instance->at(i)); | 462 s += ToString(instance->at(i)); |
| 462 sep = ", "; | 463 sep = ", "; |
| 463 } | 464 } |
| 464 StringAppendF(&s, ">(%u)@{%d}", instance->exemplar_position_, | 465 StringAppendF(&s, ">(%" PRIuS ")@{%" PRIuS "}", instance->exemplar_position_, |
| 465 static_cast<int>(instance->position_count())); | 466 instance->position_count()); |
| 466 return s; | 467 return s; |
| 467 } | 468 } |
| 468 | 469 |
| 469 | 470 |
| 470 bool Shingle::InterningLess::operator()( | 471 bool Shingle::InterningLess::operator()( |
| 471 const Shingle& a, | 472 const Shingle& a, |
| 472 const Shingle& b) const { | 473 const Shingle& b) const { |
| 473 for (size_t i = 0; i < kWidth; ++i) { | 474 for (size_t i = 0; i < kWidth; ++i) { |
| 474 LabelInfo* info_a = a.at(i); | 475 LabelInfo* info_a = a.at(i); |
| 475 LabelInfo* info_b = b.at(i); | 476 LabelInfo* info_b = b.at(i); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 std::string s; | 572 std::string s; |
| 572 size_t histogram_size = histogram.size(); | 573 size_t histogram_size = histogram.size(); |
| 573 size_t snippet_size = 0; | 574 size_t snippet_size = 0; |
| 574 for (ShinglePattern::Histogram::const_iterator p = histogram.begin(); | 575 for (ShinglePattern::Histogram::const_iterator p = histogram.begin(); |
| 575 p != histogram.end(); | 576 p != histogram.end(); |
| 576 ++p) { | 577 ++p) { |
| 577 if (++snippet_size > snippet_max && snippet_size != histogram_size) { | 578 if (++snippet_size > snippet_max && snippet_size != histogram_size) { |
| 578 s += " ..."; | 579 s += " ..."; |
| 579 break; | 580 break; |
| 580 } | 581 } |
| 581 StringAppendF(&s, " %d", p->count()); | 582 StringAppendF(&s, " %" PRIuS, p->count()); |
| 582 } | 583 } |
| 583 return s; | 584 return s; |
| 584 } | 585 } |
| 585 | 586 |
| 586 std::string HistogramToStringFull(const ShinglePattern::Histogram& histogram, | 587 std::string HistogramToStringFull(const ShinglePattern::Histogram& histogram, |
| 587 const char* indent, | 588 const char* indent, |
| 588 size_t snippet_max) { | 589 size_t snippet_max) { |
| 589 std::string s; | 590 std::string s; |
| 590 | 591 |
| 591 size_t histogram_size = histogram.size(); | 592 size_t histogram_size = histogram.size(); |
| 592 size_t snippet_size = 0; | 593 size_t snippet_size = 0; |
| 593 for (ShinglePattern::Histogram::const_iterator p = histogram.begin(); | 594 for (ShinglePattern::Histogram::const_iterator p = histogram.begin(); |
| 594 p != histogram.end(); | 595 p != histogram.end(); |
| 595 ++p) { | 596 ++p) { |
| 596 s += indent; | 597 s += indent; |
| 597 if (++snippet_size > snippet_max && snippet_size != histogram_size) { | 598 if (++snippet_size > snippet_max && snippet_size != histogram_size) { |
| 598 s += "...\n"; | 599 s += "...\n"; |
| 599 break; | 600 break; |
| 600 } | 601 } |
| 601 StringAppendF(&s, "(%d) ", p->count()); | 602 StringAppendF(&s, "(%" PRIuS ") ", p->count()); |
| 602 s += ToString(&(*p->instance())); | 603 s += ToString(&(*p->instance())); |
| 603 s += "\n"; | 604 s += "\n"; |
| 604 } | 605 } |
| 605 return s; | 606 return s; |
| 606 } | 607 } |
| 607 | 608 |
| 608 std::string ToString(const ShinglePattern* pattern, size_t snippet_max = 3) { | 609 std::string ToString(const ShinglePattern* pattern, size_t snippet_max = 3) { |
| 609 std::string s; | 610 std::string s; |
| 610 if (pattern == NULL) { | 611 if (pattern == NULL) { |
| 611 s = "<null>"; | 612 s = "<null>"; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 626 return s; | 627 return s; |
| 627 } | 628 } |
| 628 | 629 |
| 629 std::string ShinglePatternToStringFull(const ShinglePattern* pattern, | 630 std::string ShinglePatternToStringFull(const ShinglePattern* pattern, |
| 630 size_t max) { | 631 size_t max) { |
| 631 std::string s; | 632 std::string s; |
| 632 s += ToString(pattern->index_); | 633 s += ToString(pattern->index_); |
| 633 s += "\n"; | 634 s += "\n"; |
| 634 size_t model_size = pattern->model_histogram_.size(); | 635 size_t model_size = pattern->model_histogram_.size(); |
| 635 size_t program_size = pattern->program_histogram_.size(); | 636 size_t program_size = pattern->program_histogram_.size(); |
| 636 StringAppendF(&s, " model shingles %u\n", model_size); | 637 StringAppendF(&s, " model shingles %" PRIuS "\n", model_size); |
| 637 s += HistogramToStringFull(pattern->model_histogram_, " ", max); | 638 s += HistogramToStringFull(pattern->model_histogram_, " ", max); |
| 638 StringAppendF(&s, " program shingles %u\n", program_size); | 639 StringAppendF(&s, " program shingles %" PRIuS "\n", program_size); |
| 639 s += HistogramToStringFull(pattern->program_histogram_, " ", max); | 640 s += HistogramToStringFull(pattern->program_histogram_, " ", max); |
| 640 return s; | 641 return s; |
| 641 } | 642 } |
| 642 | 643 |
| 643 struct ShinglePatternIndexLess { | 644 struct ShinglePatternIndexLess { |
| 644 bool operator()(const ShinglePattern::Index& a, | 645 bool operator()(const ShinglePattern::Index& a, |
| 645 const ShinglePattern::Index& b) const { | 646 const ShinglePattern::Index& b) const { |
| 646 if (a.hash_ < b.hash_) return true; | 647 if (a.hash_ < b.hash_) return true; |
| 647 if (a.hash_ > b.hash_) return false; | 648 if (a.hash_ > b.hash_) return false; |
| 648 | 649 |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1313 |
| 1313 //////////////////////////////////////////////////////////////////////////////// | 1314 //////////////////////////////////////////////////////////////////////////////// |
| 1314 | 1315 |
| 1315 } // namespace adjustment_method_2 | 1316 } // namespace adjustment_method_2 |
| 1316 | 1317 |
| 1317 AdjustmentMethod* AdjustmentMethod::MakeShingleAdjustmentMethod() { | 1318 AdjustmentMethod* AdjustmentMethod::MakeShingleAdjustmentMethod() { |
| 1318 return new adjustment_method_2::Adjuster(); | 1319 return new adjustment_method_2::Adjuster(); |
| 1319 } | 1320 } |
| 1320 | 1321 |
| 1321 } // namespace courgette | 1322 } // namespace courgette |
| OLD | NEW |