diff options
Diffstat (limited to 'utils/array2d.h')
| -rw-r--r-- | utils/array2d.h | 46 | 
1 files changed, 23 insertions, 23 deletions
| diff --git a/utils/array2d.h b/utils/array2d.h index ee2600d2..1a8e4157 100644 --- a/utils/array2d.h +++ b/utils/array2d.h @@ -15,12 +15,12 @@ class Array2D {    typedef typename std::vector<T>::iterator iterator;    typedef typename std::vector<T>::const_iterator const_iterator;    Array2D() : width_(0), height_(0) {} -  Array2D(int w, int h, const T& d = T()) : +  Array2D(unsigned w, unsigned h, const T& d = T()) :      width_(w), height_(h), data_(w*h, d) {}    Array2D(const Array2D& rhs) :      width_(rhs.width_), height_(rhs.height_), data_(rhs.data_) {}    bool empty() const { return data_.empty(); } -  void resize(int w, int h, const T& d = T()) { +  void resize(unsigned w, unsigned h, const T& d = T()) {      data_.resize(w * h, d);      width_ = w;      height_ = h; @@ -32,25 +32,25 @@ class Array2D {      return *this;    }    void fill(const T& v) { data_.assign(data_.size(), v); } -  int width() const { return width_; } -  int height() const { return height_; } -  reference operator()(int i, int j) { +  unsigned width() const { return width_; } +  unsigned height() const { return height_; } +  reference operator()(unsigned i, unsigned j) {      return data_[offset(i, j)];    }    void clear() { data_.clear(); width_=0; height_=0; } -  const_reference operator()(int i, int j) const { +  const_reference operator()(unsigned i, unsigned j) const {      return data_[offset(i, j)];    } -  iterator begin_col(int j) { +  iterator begin_col(unsigned j) {      return data_.begin() + offset(0,j);    } -  const_iterator begin_col(int j) const { +  const_iterator begin_col(unsigned j) const {      return data_.begin() + offset(0,j);    } -  iterator end_col(int j) { +  iterator end_col(unsigned j) {      return data_.begin() + offset(0,j) + width_;    } -  const_iterator end_col(int j) const { +  const_iterator end_col(unsigned j) const {      return data_.begin() + offset(0,j) + width_;    }    iterator end() { return data_.end(); } @@ -71,14 +71,14 @@ class Array2D {    }   private: -  inline int offset(int i, int j) const { +  inline unsigned offset(unsigned i, unsigned j) const {      assert(i<width_);      assert(j<height_);      return i + j * width_;    } -  int width_; -  int height_; +  unsigned width_; +  unsigned height_;    std::vector<T> data_;  }; @@ -120,8 +120,8 @@ Array2D<T> operator-(const Array2D<T>& l, const Array2D<T>& r) {  template <typename T>  inline std::ostream& operator<<(std::ostream& os, const Array2D<T>& m) { -  for (int i=0; i<m.width(); ++i) { -    for (int j=0; j<m.height(); ++j) +  for (unsigned i=0; i<m.width(); ++i) { +    for (unsigned j=0; j<m.height(); ++j)        os << '\t' << m(i,j);      os << '\n';    } @@ -130,17 +130,17 @@ inline std::ostream& operator<<(std::ostream& os, const Array2D<T>& m) {  inline std::ostream& operator<<(std::ostream& os, const Array2D<bool>& m) {    os << ' '; -  for (int j=0; j<m.height(); ++j) +  for (unsigned j=0; j<m.height(); ++j)      os << (j%10);    os << "\n"; -  for (int i=0; i<m.width(); ++i) { +  for (unsigned i=0; i<m.width(); ++i) {      os << (i%10); -    for (int j=0; j<m.height(); ++j) +    for (unsigned j=0; j<m.height(); ++j)        os << (m(i,j) ? '*' : '.');      os << (i%10) << "\n";    }    os << ' '; -  for (int j=0; j<m.height(); ++j) +  for (unsigned j=0; j<m.height(); ++j)      os << (j%10);    os << "\n";    return os; @@ -148,12 +148,12 @@ inline std::ostream& operator<<(std::ostream& os, const Array2D<bool>& m) {  inline std::ostream& operator<<(std::ostream& os, const Array2D<std::vector<bool> >& m) {    os << ' '; -  for (int j=0; j<m.height(); ++j) +  for (unsigned j=0; j<m.height(); ++j)      os << (j%10) << "\t";    os << "\n"; -  for (int i=0; i<m.width(); ++i) { +  for (unsigned i=0; i<m.width(); ++i) {      os << (i%10); -    for (int j=0; j<m.height(); ++j) { +    for (unsigned j=0; j<m.height(); ++j) {        const std::vector<bool>& ar = m(i,j);        for (unsigned k=0; k<ar.size(); ++k)          os << (ar[k] ? '*' : '.'); @@ -162,7 +162,7 @@ inline std::ostream& operator<<(std::ostream& os, const Array2D<std::vector<bool      os << (i%10) << "\n";    }    os << ' '; -  for (int j=0; j<m.height(); ++j) +  for (unsigned j=0; j<m.height(); ++j)      os << (j%10) << "\t";    os << "\n";    return os; | 
