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 | |
parent | 0c7a38d9d252861e7fa7c3973a4737eb6b915279 (diff) |
Use passing objects by const references not passing by their values.
Diffstat (limited to 'mert')
-rw-r--r-- | mert/Data.cpp | 6 | ||||
-rw-r--r-- | mert/Data.h | 2 | ||||
-rw-r--r-- | mert/FeatureArray.h | 12 | ||||
-rw-r--r-- | mert/FeatureData.cpp | 13 | ||||
-rw-r--r-- | mert/FeatureData.h | 6 | ||||
-rw-r--r-- | mert/FeatureStats.cpp | 10 | ||||
-rw-r--r-- | mert/FeatureStats.h | 10 | ||||
-rw-r--r-- | mert/Optimizer.h | 3 | ||||
-rw-r--r-- | mert/ScoreData.h | 4 | ||||
-rw-r--r-- | mert/Util.cpp | 18 |
10 files changed, 40 insertions, 44 deletions
diff --git a/mert/Data.cpp b/mert/Data.cpp index 2cca6a4bf..2d3318753 100644 --- a/mert/Data.cpp +++ b/mert/Data.cpp @@ -267,16 +267,16 @@ void Data::outputSample( ostream &out, const FeatureStats &f1, const FeatureStat void Data::createShards(size_t shard_count, float shard_size, const string& scorerconfig, - std::vector<Data>& shards) + std::vector<Data>& shards) { assert(shard_count); - assert(shard_size >=0); + assert(shard_size >= 0); assert(shard_size <= 1); size_t data_size = scoredata->size(); assert(data_size == featdata->size()); - shard_size *= data_size; + shard_size *= data_size; for (size_t shard_id = 0; shard_id < shard_count; ++shard_id) { vector<size_t> shard_contents; diff --git a/mert/Data.h b/mert/Data.h index b1d559535..50f7ca311 100644 --- a/mert/Data.h +++ b/mert/Data.h @@ -65,7 +65,7 @@ public: inline std::string Features() const { return featdata->Features(); } - inline void Features(const std::string f) { + inline void Features(const std::string &f) { featdata->Features(f); } diff --git a/mert/FeatureArray.h b/mert/FeatureArray.h index eaedf893a..c1c12fc47 100644 --- a/mert/FeatureArray.h +++ b/mert/FeatureArray.h @@ -47,17 +47,17 @@ public: inline std::string getIndex() const { return idx; } - inline void setIndex(const std::string & value) { - idx=value; + inline void setIndex(const std::string& value) { + idx = value; } - inline FeatureStats& get(size_t i) { + inline FeatureStats& get(size_t i) { return array_.at(i); } - inline const FeatureStats& get(size_t i)const { + inline const FeatureStats& get(size_t i)const { return array_.at(i); } - void add(FeatureStats e) { + void add(FeatureStats& e) { array_.push_back(e); } @@ -75,7 +75,7 @@ public: inline std::string Features() const { return features; } - inline void Features(const std::string f) { + inline void Features(const std::string& f) { features = f; } diff --git a/mert/FeatureData.cpp b/mert/FeatureData.cpp index b72dc5b04..07bfa6a02 100644 --- a/mert/FeatureData.cpp +++ b/mert/FeatureData.cpp @@ -91,7 +91,7 @@ void FeatureData::add(FeatureArray& e) } } -void FeatureData::add(FeatureStats& e, const std::string & sent_idx) +void FeatureData::add(FeatureStats& e, const std::string& sent_idx) { if (exists(sent_idx)) { // array at position e.getIndex() already exists //enlarge array at position e.getIndex() @@ -130,19 +130,18 @@ void FeatureData::setIndex() } } -void FeatureData::setFeatureMap(const std::string feat) +void FeatureData::setFeatureMap(const std::string& feat) { number_of_features = 0; - features=feat; + features = feat; std::string substring, stringBuf; - stringBuf=features; + stringBuf = features; while (!stringBuf.empty()) { getNextPound(stringBuf, substring); - featname2idx_[substring]=idx2featname_.size(); - idx2featname_[idx2featname_.size()]=substring; + featname2idx_[substring] = idx2featname_.size(); + idx2featname_[idx2featname_.size()] = substring; number_of_features++; } } - diff --git a/mert/FeatureData.h b/mert/FeatureData.h index cc474ce71..3a96e74f1 100644 --- a/mert/FeatureData.h +++ b/mert/FeatureData.h @@ -54,7 +54,7 @@ public: return array_.at(idx); } - inline bool exists(const std::string & sent_idx) { + inline bool exists(const std::string& sent_idx) { return exists(getIndex(sent_idx)); } inline bool exists(int sent_idx) { @@ -83,7 +83,7 @@ public: inline std::string Features() const { return features; } - inline void Features(const std::string f) { + inline void Features(const std::string& f) { features = f; } @@ -136,7 +136,7 @@ public: return it->second; } - void setFeatureMap(const std::string feat); + void setFeatureMap(const std::string& feat); }; #endif // FEATURE_DATA_H 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); } diff --git a/mert/FeatureStats.h b/mert/FeatureStats.h index 6b1f475b5..fb7d46350 100644 --- a/mert/FeatureStats.h +++ b/mert/FeatureStats.h @@ -24,11 +24,13 @@ public: typedef std::map<std::string, size_t> name2id_t; typedef std::vector<std::string> id2name_t; - FeatureStatsType get(std::string name) const; + FeatureStatsType get(const std::string& name) const; FeatureStatsType get(size_t id) const; - void set(std::string name, FeatureStatsType value); + void set(const std::string& name, FeatureStatsType value); void clear(); - size_t size() const; + size_t size() const { + return fvector_.size(); + } void write(std::ostream& out, const std::string& sep = " ") const; @@ -70,7 +72,7 @@ public: } void expand(); void add(FeatureStatsType v); - void addSparse(string name, FeatureStatsType v); + void addSparse(const string& name, FeatureStatsType v); void clear() { memset((void*)array_, 0, GetArraySizeWithBytes()); diff --git a/mert/Optimizer.h b/mert/Optimizer.h index 68219a629..8ca804926 100644 --- a/mert/Optimizer.h +++ b/mert/Optimizer.h @@ -118,7 +118,8 @@ private: enum OptType { POWELL = 0, RANDOM_DIRECTION = 1, - RANDOM,NOPTIMIZER + RANDOM, + NOPTIMIZER }; static OptType GetOType(string); diff --git a/mert/ScoreData.h b/mert/ScoreData.h index febc78549..295344ed0 100644 --- a/mert/ScoreData.h +++ b/mert/ScoreData.h @@ -53,7 +53,7 @@ public: return array_.at(idx); } - inline bool exists(const std::string & sent_idx) const { + inline bool exists(const std::string& sent_idx) const { return exists(getIndex(sent_idx)); } inline bool exists(int sent_idx) const { @@ -71,7 +71,7 @@ public: return score_type; } - inline std::string name(std::string &sctype) { + inline std::string name(const std::string &sctype) { return score_type = sctype; } diff --git a/mert/Util.cpp b/mert/Util.cpp index dc4824559..a5d68713e 100644 --- a/mert/Util.cpp +++ b/mert/Util.cpp @@ -16,7 +16,7 @@ using namespace std; // global variables Timer g_timer; -int verbose=0; +int verbose = 0; namespace { @@ -34,7 +34,7 @@ int verboselevel() int setverboselevel(int v) { - verbose=v; + verbose = v; return verbose; } @@ -74,18 +74,16 @@ void Tokenize(const char *str, const char delim, } } - - int swapbytes(char *p, int sz, int n) { char c, *l, *h; - if((n<1) || (sz<2)) return 0; - for (; n--; p+=sz) { - for(h=(l=p)+sz; --h>l; l++) { - c=*h; - *h=*l; - *l=c; + if((n < 1) || (sz < 2)) return 0; + for (; n--; p += sz) { + for (h = (l = p) + sz; --h > l; l++) { + c = *h; + *h = *l; + *l = c; } } return 0; |