From 8c6536c56c728213b9e1190f0c9f76f7b4948140 Mon Sep 17 00:00:00 2001 From: graehl Date: Fri, 23 Jul 2010 02:27:28 +0000 Subject: bottom-up FF from fsa FF - WordPenaltyFsa - needs debugging git-svn-id: https://ws10smt.googlecode.com/svn/trunk@373 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/value_array.h | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'decoder/value_array.h') diff --git a/decoder/value_array.h b/decoder/value_array.h index 042247a1..0cb5c3d6 100755 --- a/decoder/value_array.h +++ b/decoder/value_array.h @@ -1,12 +1,15 @@ #ifndef VALUE_ARRAY_H #define VALUE_ARRAY_H +//TODO: option for non-constructed version (type_traits pod?), option for small array optimization (if sz < N, store inline in union, see small_vector.h) + #include #include #include #include #include #include +#include #ifdef USE_BOOST_SERIALIZE # include # include @@ -17,7 +20,7 @@ template > class ValueArray : A // private inheritance so stateless allocator adds no size. { public: - const int SV_MAX=sizeof(T)/sizeof(T*)>1?sizeof(T)/sizeof(T*):1; + static const int SV_MAX=sizeof(T)/sizeof(T*)>1?sizeof(T)/sizeof(T*):1; //space optimization: SV_MAX T will fit inside what would otherwise be a pointer to heap data. todo in the far future if bored. typedef T value_type; typedef T& reference; @@ -51,11 +54,21 @@ public: ValueArray() : sz(0), array(NULL) {} explicit ValueArray(size_type s, const_reference t = T()) - : sz(s) - , array(A::allocate(s)) { + init(s,t); + } + +protected: + inline void init(size_type s, const_reference t = T()) { + sz=s; + array=A::allocate(s); for (size_type i = 0; i != sz; ++i) { A::construct(array + i,t); } } +public: + void resize(size_type s, const_reference t = T()) { + clear(); + init(s,t); + } template ValueArray(I itr, I end) @@ -65,7 +78,11 @@ public: copy_construct(itr,end,array); } - ~ValueArray() + ~ValueArray() { + clear(); + } + + void clear() { for (size_type i = sz; i != 0; --i) { A::destroy(array + (i - 1)); @@ -160,6 +177,10 @@ bool operator< (ValueArray const& v1, ValueArray const& v2) , v2.end() ); } +template +void memcpy(void *out,ValueArray const& v) { + std::memcpy(out,v.begin(),v.size()*sizeof(T)); +} #endif -- cgit v1.2.3