00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef MORE_GEN_EQUI_SET_H
00030 #define MORE_GEN_EQUI_SET_H
00031
00032
00033
00034 namespace more {
00035 namespace gen {
00036
00037
00038
00039 template<typename Number>
00040 struct equi_set
00041 {
00042 equi_set(Number begin, Number end, Number step)
00043 : m_beg(begin), m_end(end), m_step(step) {}
00044
00045 bool contains(Number i)
00046 {
00047 return !(i < m_beg) && i < m_end;
00048 }
00049
00050 equi_set& operator|=(equi_set const& rhs) const;
00051
00052 friend Number below(equi_set const& x) const {return x.m_beg-m_step;}
00053 friend Number min(equi_set const& x) const { return x.m_beg; }
00054 friend Number max(equi_set const& x) const { return x.m_end-m_step; }
00055 friend Number above(equi_set const& x) const { return x.m_end; }
00056
00057 private:
00058 Number m_beg;
00059 Number m_end;
00060 Number m_step;
00061 };
00062
00063 template<typename Number>
00064 equi_set<Number>&
00065 equi_set<Number>::operator|=(equi_set const& rhs)
00066 {
00067 if (m_step == rhs.m_step) {
00068 if ((m_beg - rhs.m_beg) % m_step == 0) {
00069 if (rhs.m_beg < m_beg) {
00070 if (rhs.m_end < m_beg)
00071 goto fail;
00072 m_beg = rhs.m_beg;
00073 }
00074 if (m_end < rhs.m_end) {
00075 if (m_end < rhs.m_beg)
00076 goto fail;
00077 m_end = rhs.m_end;
00078 }
00079 return *this;
00080 }
00081 throw std::logic_error("more::math::equi_set::operator|=: "
00082 "Case is not implemented.");
00083 }
00084 fail:
00085 throw std::logic_error("more::math::equi_set::operator|=: "
00086 "Result set can not be represented.");
00087 }
00088
00089 }}
00090
00091
00092
00093 #endif