* mln/value/interval.hh,
* tests/value/interval.cc: Rename nelements() to nvalues().
---
milena/ChangeLog | 7 +++++++
milena/mln/value/interval.hh | 14 ++++++++------
milena/tests/value/interval.cc | 4 ++--
3 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 9392818..0e6b384 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Rename interval::nelements() to interval::nvalues().
+
+ * mln/value/interval.hh,
+ * tests/value/interval.cc: Rename nelements() to nvalues().
+
+2012-10-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Replace range class with interval and improve it.
* mln/value/range.hh,
diff --git a/milena/mln/value/interval.hh b/milena/mln/value/interval.hh
index a4cdf8c..13c7947 100644
--- a/milena/mln/value/interval.hh
+++ b/milena/mln/value/interval.hh
@@ -67,7 +67,7 @@ namespace mln
unsigned index_of(const T& v) const;
/// Return the number of values in this interval.
- unsigned nelements() const;
+ unsigned nvalues() const;
/// Return True if this interval contains only one value.
bool is_degenerated() const;
@@ -80,7 +80,7 @@ namespace mln
private:
T first_;
T last_;
- unsigned nelements_;
+ unsigned nvalues_;
};
// comparison
@@ -213,9 +213,9 @@ namespace mln
first_ = first;
last_ = last;
- nelements_ = 0;
+ nvalues_ = 0;
for (T v = first_; v <= last_; value::inc(v))
- ++nelements_;
+ ++nvalues_;
}
template <typename T>
@@ -245,6 +245,7 @@ namespace mln
T
interval<T>::ith_element(unsigned i) const
{
+ mln_precondition(i < nvalues());
return first_ + i * iota<T>::value();
}
@@ -252,14 +253,15 @@ namespace mln
unsigned
interval<T>::index_of(const T& v) const
{
+ mln_precondition(has(v));
return (v - first_) / iota<T>::value();
}
template <typename T>
unsigned
- interval<T>::nelements() const
+ interval<T>::nvalues() const
{
- return nelements_;
+ return nvalues_;
}
template <typename T>
diff --git a/milena/tests/value/interval.cc b/milena/tests/value/interval.cc
index 86b9a55..0fd8e6d 100644
--- a/milena/tests/value/interval.cc
+++ b/milena/tests/value/interval.cc
@@ -47,7 +47,7 @@ int main()
R r(0, 0);
assert(r.is_degenerated());
assert(r.length() == 0);
- assert(r.nelements() == 1);
+ assert(r.nvalues() == 1);
}
{
@@ -64,7 +64,7 @@ int main()
R r(1, 5);
assert(!r.is_degenerated());
assert(r.length() == 4);
- assert(r.nelements() == 9);
+ assert(r.nvalues() == 9);
int ref_i = 2;
for (intsub<2> v = r.first(); v <= r.last(); inc(v))
--
1.7.2.5
Show replies by date