diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2012-05-16 07:09:16 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2012-05-16 07:09:16 -0400 |
commit | 4067927d57318d0863d3c1eada787393cf5df5b2 (patch) | |
tree | 9a8712e8fba3acdbb215073bb92872df01c2bc95 /utils | |
parent | 824c96f038b0447ce83ae92cad112a5be49e3330 (diff) |
clean up
Diffstat (limited to 'utils')
-rw-r--r-- | utils/array2d.h | 2 | ||||
-rw-r--r-- | utils/fast_sparse_vector.h | 4 | ||||
-rw-r--r-- | utils/fdict.h | 2 | ||||
-rw-r--r-- | utils/hash.h | 6 | ||||
-rw-r--r-- | utils/perfect_hash.h | 13 | ||||
-rw-r--r-- | utils/phmt.cc | 2 | ||||
-rw-r--r-- | utils/small_vector.h | 28 | ||||
-rw-r--r-- | utils/sparse_vector.cc | 2 |
8 files changed, 35 insertions, 24 deletions
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<std::vector<bool os << (i%10); for (int j=0; j<m.height(); ++j) { const std::vector<bool>& ar = m(i,j); - for (int k=0; k<ar.size(); ++k) + for (unsigned k=0; k<ar.size(); ++k) os << (ar[k] ? '*' : '.'); } os << "\t"; diff --git a/utils/fast_sparse_vector.h b/utils/fast_sparse_vector.h index 68caa704..3cc48f8e 100644 --- a/utils/fast_sparse_vector.h +++ b/utils/fast_sparse_vector.h @@ -14,7 +14,9 @@ #include <cassert> #include <vector> +#ifdef HAVE_CONFIG_H #include "config.h" +#endif #include <boost/static_assert.hpp> #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<T> &v,int i) { + static inline T& extend_vector(std::vector<T> &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 <iostream> #include <string> 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 <google/dense_hash_map> # include <google/dense_hash_set> @@ -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 <class H,class K> 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 <vector> +#include <boost/utility.hpp> -#ifndef HAVE_CMPH -#error libcmph is required to use PerfectHashFunction +#ifdef HAVE_CONFIG_H +#include "config.h" #endif -#include <vector> -#include <boost/utility.hpp> +#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<size_;++i) data_.vals[i].~T(); + for (unsigned i=0;i<size_;++i) data_.vals[i].~T(); #endif } else delete[] data_.ptr; @@ -166,13 +166,13 @@ private: inline void copy_vals_to_ptr() { capacity_ = SV_MAX * 2; T* tmp = new T[capacity_]; - for (int i = 0; i < SV_MAX; ++i) tmp[i] = data_.vals[i]; + for (unsigned i = 0; i < SV_MAX; ++i) tmp[i] = data_.vals[i]; data_.ptr = tmp; } inline void ptr_to_small() { assert(size_<=SV_MAX); int *tmp=data_.ptr; - for (int i=0;i<size_;++i) + for (unsigned i=0;i<size_;++i) data_.vals[i]=tmp[i]; delete[] tmp; } @@ -224,7 +224,7 @@ public: if (s <= SV_MAX) { if (size_ > 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<double>& 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; |