|
Boost-Commit : |
From: arseny.kapoulkine_at_[hidden]
Date: 2007-08-07 05:26:27
Author: zeux
Date: 2007-08-07 05:26:26 EDT (Tue, 07 Aug 2007)
New Revision: 38492
URL: http://svn.boost.org/trac/boost/changeset/38492
Log:
push_back, pop_back, front, back added to storages, used in default implementation
Text files modified:
sandbox/SOC/2007/bigint/boost/bigint/bigint_default.hpp | 21 ++++++----------
sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_fixed.hpp | 50 +++++++++++++++++++++++++++++++++++----
sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_vector.hpp | 41 +++++++++++++++++++++++++++++++-
3 files changed, 91 insertions(+), 21 deletions(-)
Modified: sandbox/SOC/2007/bigint/boost/bigint/bigint_default.hpp
==============================================================================
--- sandbox/SOC/2007/bigint/boost/bigint/bigint_default.hpp (original)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint_default.hpp 2007-08-07 05:26:26 EDT (Tue, 07 Aug 2007)
@@ -101,11 +101,7 @@
carry = static_cast<limb_t>(result >> limb_bit_number);
}
- if (carry != 0)
- {
- data.resize(data.size() + 1);
- data[data.size()-1] = carry;
- }
+ if (carry != 0) data.push_back(carry);
}
template <typename Ch> void _assign_str(const Ch* str, int base)
@@ -221,7 +217,7 @@
}
else
{
- data.resize(data.size() - 1);
+ data.pop_back();
}
}
@@ -520,12 +516,12 @@
// Guess a value for q [Knuth, vol.2, section 4.3.1]
limb_t qd;
- if (xx.data[xx.data.size()-1] >= y.data[y.data.size()-1])
+ if (xx.data.back() >= y.data.back())
qd = limb_max();
else
qd = static_cast<limb_t>(
- ((static_cast<limb2_t>(limb_max()) + 1) * xx.data[xx.data.size()-1] + xx.data[xx.data.size()-2])
- / y.data[y.data.size()-1]
+ ((static_cast<limb2_t>(limb_max()) + 1) * xx.data.back() + xx.data[xx.data.size()-2])
+ / y.data.back()
);
bigint_default_implementation rs = y;
@@ -909,7 +905,7 @@
}
while (i != data.begin());
- if (*(data.end() - 1) == 0) data.resize(data.size() - 1);
+ if (data.back() == 0) data.pop_back();
return remainder;
}
@@ -1099,10 +1095,9 @@
for (limb_t* i = a.data.begin(); i != a.data.end(); ++i)
*i = 0;
- a.data[a.data.size() - 1] = lhs.data[lhs.data.size() - 1] / 2;
+ a.data.back() = lhs.data.back() / 2;
- if (a.data[a.data.size() - 1] == 0)
- a.data[a.data.size() - 1] = 1;
+ if (a.data.back() == 0) a.data.back() = 1;
// iterate
for (;;)
Modified: sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_fixed.hpp
==============================================================================
--- sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_fixed.hpp (original)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_fixed.hpp 2007-08-07 05:26:26 EDT (Tue, 07 Aug 2007)
@@ -20,14 +20,14 @@
T data[N / sizeof(T)];
size_t count;
- public:
- type(): count(0)
+ size_t _max_size()
{
+ return (N / sizeof(T));
}
- size_t _max_size()
+ public:
+ type(): count(0)
{
- return (N / sizeof(T));
}
void resize(size_t size)
@@ -69,12 +69,50 @@
const T& operator[](size_t index) const
{
- return begin()[index];
+ BOOST_ASSERT(index < count);
+ return data[index];
}
T& operator[](size_t index)
{
- return begin()[index];
+ BOOST_ASSERT(index < count);
+ return data[index];
+ }
+
+ void push_back(const T& value)
+ {
+ if (count >= _max_size()) throw std::bad_alloc();
+ data[count++] = value;
+ }
+
+ void pop_back()
+ {
+ BOOST_ASSERT(count != 0);
+ --count;
+ }
+
+ const T& front() const
+ {
+ BOOST_ASSERT(count != 0);
+ return data[0];
+ }
+
+ T& front()
+ {
+ BOOST_ASSERT(count != 0);
+ return data[0];
+ }
+
+ const T& back() const
+ {
+ BOOST_ASSERT(count != 0);
+ return data[count - 1];
+ }
+
+ T& back()
+ {
+ BOOST_ASSERT(count != 0);
+ return data[count - 1];
}
};
};
Modified: sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_vector.hpp
==============================================================================
--- sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_vector.hpp (original)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint_storage_vector.hpp 2007-08-07 05:26:26 EDT (Tue, 07 Aug 2007)
@@ -55,12 +55,49 @@
const T& operator[](size_t index) const
{
- return begin()[index];
+ BOOST_ASSERT(index < data.size());
+ return data[index];
}
T& operator[](size_t index)
{
- return begin()[index];
+ BOOST_ASSERT(index < data.size());
+ return data[index];
+ }
+
+ void push_back(const T& value)
+ {
+ data.push_back(value);
+ }
+
+ void pop_back()
+ {
+ BOOST_ASSERT(!data.empty());
+ data.pop_back();
+ }
+
+ const T& front() const
+ {
+ BOOST_ASSERT(!data.empty());
+ return data.front();
+ }
+
+ T& front()
+ {
+ BOOST_ASSERT(!data.empty());
+ return data.front();
+ }
+
+ const T& back() const
+ {
+ BOOST_ASSERT(!data.empty());
+ return data.back();
+ }
+
+ T& back()
+ {
+ BOOST_ASSERT(!data.empty());
+ return data.back();
}
};
} } // namespace boost::detail
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk