diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-21 03:07:42 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-08-21 03:07:42 +0000 |
commit | ca9c1f40cad1f99f00beb2871dc50bf7222d44d4 (patch) | |
tree | 183f19411904bb2a23cc5f916f1887a484c6574b /utils/value_array.h | |
parent | d8dbfdcc460754bd5f45182495ff14b39b94b24d (diff) |
agenda for fsa
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@612 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'utils/value_array.h')
-rwxr-xr-x | utils/value_array.h | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/utils/value_array.h b/utils/value_array.h index 82e66e8d..a10f754f 100755 --- a/utils/value_array.h +++ b/utils/value_array.h @@ -103,6 +103,12 @@ protected: } } + template <class C,class F> + inline void init_map(C const& c,F const& f) { + alloc(c.size()); + copy_construct_map(c.begin(),c.end(),array,f); + } + // warning: std::distance is likely slow on maps (anything other than random access containers. so container version using size will be better template <class I,class F> inline void init_range_map(I itr, I end,F const& f) { alloc(std::distance(itr,end)); @@ -123,11 +129,25 @@ public: { init(s,t); } - void resize(size_type s, const_reference t = T()) { + void reinit(size_type s, const_reference t = T()) { clear(); init(s,t); } + //copy any existing data like std::vector. not A::construct exception safe. try blah blah? + void resize(size_type s, const_reference t = T()) { + pointer na=A::allocate(s); + size_type nc=s<sz ? s : sz; + size_type i=0; + for (;i<nc;++i) + A::construct(na+i,array[i]); + for (;i<s;++i) + A::construct(na+i,t); + clear(); + array=na; + sz=s; + } + template <class I> void reinit(I itr, I end) { clear(); @@ -135,10 +155,16 @@ public: } template <class I,class F> - void reinit_map(I itr, I end,F const& map) { + void reinit_map(I itr,I end,F const& map) { clear(); init_range_map(itr,end,map); } + // warning: std::distance is likely slow on maps,lists (anything other than random access containers. so container version below using size() will be better + template <class C,class F> + void reinit_map(C const& c,F const& map) { + clear(); + init_map(c,map); + } template <class I> ValueArray(I itr, I end) |