diff options
author | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-14 09:00:47 +0400 |
---|---|---|
committer | Tetsuo Kiso <tetsuo-s@is.naist.jp> | 2011-11-14 09:00:47 +0400 |
commit | be1506e7595bd8602a3aec3469a2407c3453d0b2 (patch) | |
tree | 24b16fa17391e57839f5d7e0ac5dcfb2f3db6dcc /mert/FeatureStats.cpp | |
parent | 0c7a38d9d252861e7fa7c3973a4737eb6b915279 (diff) |
Use passing objects by const references not passing by their values.
Diffstat (limited to 'mert/FeatureStats.cpp')
-rw-r--r-- | mert/FeatureStats.cpp | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp index 7f6f66d14..86778e770 100644 --- a/mert/FeatureStats.cpp +++ b/mert/FeatureStats.cpp @@ -17,7 +17,7 @@ const int kAvailableSize = 8; SparseVector::name2id_t SparseVector::name2id_; SparseVector::id2name_t SparseVector::id2name_; -FeatureStatsType SparseVector::get(string name) const { +FeatureStatsType SparseVector::get(const string& name) const { name2id_t::const_iterator name2id_iter = name2id_.find(name); if (name2id_iter == name2id_.end()) return 0; size_t id = name2id_iter->second; @@ -30,7 +30,7 @@ FeatureStatsType SparseVector::get(size_t id) const { return fvector_iter->second; } -void SparseVector::set(string name, FeatureStatsType value) { +void SparseVector::set(const string& name, FeatureStatsType value) { name2id_t::const_iterator name2id_iter = name2id_.find(name); size_t id = 0; if (name2id_iter == name2id_.end()) { @@ -55,10 +55,6 @@ void SparseVector::clear() { fvector_.clear(); } -size_t SparseVector::size() const { - return fvector_.size(); -} - SparseVector& SparseVector::operator-=(const SparseVector& rhs) { //All the elements that have values in *this for (fvector_t::iterator i = fvector_.begin(); i != fvector_.end(); ++i) { @@ -142,7 +138,7 @@ void FeatureStats::add(FeatureStatsType v) array_[entries_++]=v; } -void FeatureStats::addSparse(string name, FeatureStatsType v) +void FeatureStats::addSparse(const string& name, FeatureStatsType v) { map_.set(name,v); } |