From a448faf30fa46c006b1d38c6aee64a7aad29ac5e Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Wed, 16 May 2012 07:09:16 -0400 Subject: clean up --- utils/array2d.h | 2 +- utils/fast_sparse_vector.h | 4 +++- utils/fdict.h | 2 ++ utils/hash.h | 6 ++++-- utils/perfect_hash.h | 13 ++++++++----- utils/phmt.cc | 2 ++ utils/small_vector.h | 28 ++++++++++++++-------------- utils/sparse_vector.cc | 2 +- 8 files changed, 35 insertions(+), 24 deletions(-) (limited to 'utils') diff --git a/utils/array2d.h b/utils/array2d.h index e63eda0d..ee2600d2 100644 --- a/utils/array2d.h +++ b/utils/array2d.h @@ -155,7 +155,7 @@ inline std::ostream& operator<<(std::ostream& os, const Array2D& ar = m(i,j); - for (int k=0; k #include +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #include #if HAVE_BOOST_ARCHIVE_TEXT_OARCHIVE_HPP @@ -323,7 +325,7 @@ class FastSparseVector { std::memcpy(&data_, t, sizeof(data_)); } private: - static inline T& extend_vector(std::vector &v,int i) { + static inline T& extend_vector(std::vector &v,size_t i) { if (i>=v.size()) v.resize(i+1); return v[i]; diff --git a/utils/fdict.h b/utils/fdict.h index 0a2a9456..71547d2e 100644 --- a/utils/fdict.h +++ b/utils/fdict.h @@ -1,7 +1,9 @@ #ifndef _FDICT_H_ #define _FDICT_H_ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #include #include diff --git a/utils/hash.h b/utils/hash.h index 2290bc34..31457430 100644 --- a/utils/hash.h +++ b/utils/hash.h @@ -5,7 +5,10 @@ #include "murmur_hash.h" +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + #ifdef HAVE_SPARSEHASH # include # include @@ -130,8 +133,7 @@ bool maybe_add(H &ht,K const& k,typename H::mapped_type const& v) { // ht[k] must not exist (yet) template void add(H &ht,K const& k,typename H::mapped_type const& v) { - bool fresh=maybe_add(ht,k,v); - assert(fresh); + maybe_add(ht,k,v); } diff --git a/utils/perfect_hash.h b/utils/perfect_hash.h index 8ac11f18..29ea48a9 100644 --- a/utils/perfect_hash.h +++ b/utils/perfect_hash.h @@ -1,15 +1,16 @@ #ifndef _PERFECT_HASH_MAP_H_ #define _PERFECT_HASH_MAP_H_ -#include "config.h" +#include +#include -#ifndef HAVE_CMPH -#error libcmph is required to use PerfectHashFunction +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include -#include +#ifdef HAVE_CMPH #include "cmph.h" +#endif class PerfectHashFunction : boost::noncopyable { public: @@ -18,7 +19,9 @@ class PerfectHashFunction : boost::noncopyable { size_t operator()(const std::string& key) const; size_t number_of_keys() const; private: +#ifdef HAVE_CMPH cmph_t *mphf_; +#endif }; #endif diff --git a/utils/phmt.cc b/utils/phmt.cc index 48d9f093..b17febf6 100644 --- a/utils/phmt.cc +++ b/utils/phmt.cc @@ -1,4 +1,6 @@ +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #ifndef HAVE_CMPH int main() { diff --git a/utils/small_vector.h b/utils/small_vector.h index b65c3b38..d04d1352 100644 --- a/utils/small_vector.h +++ b/utils/small_vector.h @@ -50,16 +50,16 @@ class SmallVector { explicit SmallVector(size_t s) { Alloc(s); if (s <= SV_MAX) { - for (int i = 0; i < s; ++i) new(&data_.vals[i]) T(); + for (unsigned i = 0; i < s; ++i) new(&data_.vals[i]) T(); } //TODO: if alloc were raw space, construct here. } SmallVector(size_t s, T const& v) { Alloc(s); if (s <= SV_MAX) { - for (int i = 0; i < s; ++i) data_.vals[i] = v; + for (unsigned i = 0; i < s; ++i) data_.vals[i] = v; } else { - for (int i = 0; i < size_; ++i) data_.ptr[i] = v; + for (unsigned i = 0; i < size_; ++i) data_.ptr[i] = v; } } @@ -69,9 +69,9 @@ class SmallVector { int s=end-begin; Alloc(s); if (s <= SV_MAX) { - for (int i = 0; i < s; ++i,++begin) data_.vals[i] = *begin; + for (unsigned i = 0; i < s; ++i,++begin) data_.vals[i] = *begin; } else - for (int i = 0; i < s; ++i,++begin) data_.ptr[i] = *begin; + for (unsigned i = 0; i < s; ++i,++begin) data_.ptr[i] = *begin; } SmallVector(const Self& o) : size_(o.size_) { @@ -106,7 +106,7 @@ class SmallVector { if (size_ <= SV_MAX) { if (o.size_ <= SV_MAX) { size_ = o.size_; - for (int i = 0; i < SV_MAX; ++i) data_.vals[i] = o.data_.vals[i]; + for (unsigned i = 0; i < SV_MAX; ++i) data_.vals[i] = o.data_.vals[i]; } else { capacity_ = size_ = o.size_; data_.ptr = new T[capacity_]; @@ -116,7 +116,7 @@ class SmallVector { if (o.size_ <= SV_MAX) { delete[] data_.ptr; size_ = o.size_; - for (int i = 0; i < size_; ++i) data_.vals[i] = o.data_.vals[i]; + for (unsigned i = 0; i < size_; ++i) data_.vals[i] = o.data_.vals[i]; } else { if (capacity_ < o.size_) { delete[] data_.ptr; @@ -124,7 +124,7 @@ class SmallVector { data_.ptr = new T[capacity_]; } size_ = o.size_; - for (int i = 0; i < size_; ++i) + for (unsigned i = 0; i < size_; ++i) data_.ptr[i] = o.data_.ptr[i]; } } @@ -135,7 +135,7 @@ class SmallVector { if (size_ <= SV_MAX) { // skip if pod? yes, we required pod anyway. no need to destruct #if !SMALL_VECTOR_POD - for (int i=0;i SV_MAX) { T *tmp=data_.ptr; - for (int i = 0; i < s; ++i) data_.vals[i] = tmp[i]; + for (unsigned i = 0; i < s; ++i) data_.vals[i] = tmp[i]; delete[] tmp; size_ = s; return; @@ -233,7 +233,7 @@ public: size_ = s; return; } else { - for (int i = size_; i < s; ++i) + for (unsigned i = size_; i < s; ++i) data_.vals[i] = v; size_ = s; return; @@ -244,7 +244,7 @@ public: if (s > capacity_) ensure_capacity(s); if (s > size_) { - for (int i = size_; i < s; ++i) + for (unsigned i = size_; i < s; ++i) data_.ptr[i] = v; } size_ = s; diff --git a/utils/sparse_vector.cc b/utils/sparse_vector.cc index 24da5f39..27bb88dd 100644 --- a/utils/sparse_vector.cc +++ b/utils/sparse_vector.cc @@ -23,7 +23,7 @@ void Encode(double objective, const SparseVector& v, ostream* out) { for (const_iterator it = v.begin(); it != v.end(); ++it) tot_size += FD::Convert(it->first).size(); // feature names; tot_size += sizeof(double) * num_feats; // gradient - const size_t off_magic = tot_size; + const size_t off_magic = tot_size; (void) off_magic; tot_size += 4; // magic // size_t b64_size = tot_size * 4 / 3; -- cgit v1.2.3