summaryrefslogtreecommitdiff
path: root/utils/value_array.h
diff options
context:
space:
mode:
authorgraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-21 03:07:42 +0000
committergraehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-08-21 03:07:42 +0000
commitca9c1f40cad1f99f00beb2871dc50bf7222d44d4 (patch)
tree183f19411904bb2a23cc5f916f1887a484c6574b /utils/value_array.h
parentd8dbfdcc460754bd5f45182495ff14b39b94b24d (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-xutils/value_array.h30
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)