00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_AUTOMATA_IMPLEMENTATION_LISTG_LISTG_SPARSE_INTERVAL_HXX
00018 # define VCSN_AUTOMATA_IMPLEMENTATION_LISTG_LISTG_SPARSE_INTERVAL_HXX
00019
00020 namespace vcsn
00021 {
00022 namespace misc
00023 {
00024
00025
00026
00027
00028 template <class T, class ExcludedContainer>
00029 SparseIterator<handler<T, unsigned>, ExcludedContainer>::
00030 SparseIterator (integer_t from,
00031 const excluded_container_t& c)
00032 : excluded_ (&c),
00033 integer_ (from)
00034 {}
00035
00036 template <class T, class ExcludedContainer>
00037 SparseIterator<handler<T, unsigned>, ExcludedContainer>&
00038 SparseIterator<handler<T, unsigned>, ExcludedContainer>::operator++ ()
00039 {
00040 if (excluded_->size () == 0)
00041 ++integer_;
00042 else
00043 do
00044 ++integer_;
00045 while (excluded_->find (handler_t(integer_)) != excluded_->end ());
00046 return *this;
00047 }
00048
00049 template <class T, class ExcludedContainer>
00050 SparseIterator<handler<T, unsigned>, ExcludedContainer>&
00051 SparseIterator<handler<T, unsigned>, ExcludedContainer>::operator-- ()
00052 {
00053 if (excluded_->size () == 0)
00054 --integer_;
00055 else
00056 do
00057 --integer_;
00058 while (excluded_->find (handler_t(integer_)) != excluded_->end ());
00059 return *this;
00060 }
00061
00062 template <class T, class ExcludedContainer>
00063 SparseIterator<handler<T, unsigned>, ExcludedContainer>
00064 SparseIterator<handler<T, unsigned>, ExcludedContainer>::operator++ (int)
00065 {
00066 SparseIterator tmp = *this;
00067 ++*this;
00068 return tmp;
00069 }
00070
00071 template <class T, class ExcludedContainer>
00072 SparseIterator<handler<T, unsigned>, ExcludedContainer>
00073 SparseIterator<handler<T, unsigned>, ExcludedContainer>::operator-- (int)
00074 {
00075 SparseIterator tmp = *this;
00076 --*this;
00077 return tmp;
00078 }
00079
00080 template <class T, class ExcludedContainer>
00081 typename SparseIterator<handler<T, unsigned>, ExcludedContainer>::
00082 integer_t
00083 SparseIterator<handler<T, unsigned>, ExcludedContainer>::operator* ()
00084 {
00085 return handler_t(integer_);
00086 }
00087
00088 template <class T, class ExcludedContainer>
00089 bool
00090 SparseIterator<handler<T, unsigned>, ExcludedContainer>
00091 ::operator!= (const SparseIterator& i)
00092 {
00093 return i.integer_ != integer_;
00094 }
00095
00096 template <class T, class ExcludedContainer>
00097 bool
00098 SparseIterator<handler<T, unsigned>, ExcludedContainer>
00099 ::operator== (const SparseIterator& i)
00100 {
00101 return i.integer_ == integer_;
00102 }
00103
00104 template <class T, class ExcludedContainer>
00105 SparseIterator<handler<T, unsigned>, ExcludedContainer>&
00106 SparseIterator<handler<T, unsigned>, ExcludedContainer>
00107 ::operator= (const SparseIterator& i)
00108 {
00109 integer_ = i.integer_;
00110 excluded_ = i.excluded_;
00111 return *this;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00125 template <class T, class ExcludedContainer>
00126 SparseInterval<handler<T, unsigned>, ExcludedContainer>
00127 ::SparseInterval (integer_t f, integer_t t, const excluded_container_t& c)
00128 : excluded_ (c),
00129 from_ (f),
00130 to_ (t)
00131 {
00132 precondition (from_ <= to_ + 1);
00133 precondition (excluded_.find (handler_t(to_ + 1)) == excluded_.end ());
00134 precondition (to_ - from_ + 1 > excluded_.size());
00135 }
00136
00137 template <class T, class ExcludedContainer>
00138 SparseInterval<handler<T, unsigned>, ExcludedContainer>
00139 ::SparseInterval (const SparseInterval& a)
00140 : excluded_ (a.excluded_),
00141 from_ (a.from_),
00142 to_ (a.to_)
00143 {
00144 }
00145
00146 template <class T, class ExcludedContainer>
00147 unsigned
00148 SparseInterval<handler<T, unsigned>, ExcludedContainer>::size () const
00149 {
00150 return to_ - from_ + 1 - excluded_.size ();
00151 }
00152
00153 template <class T, class ExcludedContainer>
00154 std::string
00155 SparseInterval<handler<T, unsigned>, ExcludedContainer>::to_string () const
00156 {
00157 std::stringstream s;
00158 s << "from :" << from_ << " to : " << to_ << " ex:";
00159 for (typename ExcludedContainer::iterator i = excluded_.begin ();
00160 i != excluded_.end ();
00161 ++i)
00162 s << *i << " ";
00163 return s.str ();
00164 }
00165
00166 template <class T, class ExcludedContainer>
00167 typename SparseInterval<handler<T, unsigned>, ExcludedContainer>::iterator
00168 SparseInterval<handler<T, unsigned>, ExcludedContainer>::begin () const
00169 {
00170 unsigned from = from_;
00171
00172 if (excluded_.size () != 0)
00173 while (excluded_.find (handler_t(from)) != excluded_.end ())
00174 ++from;
00175 return iterator (handler_t(from), excluded_);
00176 }
00177
00178 template <class T, class ExcludedContainer>
00179 typename SparseInterval<handler<T, unsigned>, ExcludedContainer>::iterator
00180 SparseInterval<handler<T, unsigned>, ExcludedContainer>::end () const
00181 {
00182 return iterator (handler_t(to_ + 1), excluded_);
00183 }
00184
00185 template <class T, class ExcludedContainer>
00186 typename SparseInterval<handler<T, unsigned>, ExcludedContainer>::handler_t
00187 SparseInterval<handler<T, unsigned>, ExcludedContainer>::back () const
00188 {
00189 unsigned to = to_;
00190
00191 if (excluded_.size () != 0)
00192 while (excluded_.find (handler_t(to)) != excluded_.end ())
00193 --to;
00194 return *(iterator (handler_t(to), excluded_));
00195 }
00196
00197
00198 }
00199 }
00200
00201 #endif // ! VCSN_MISC_SPARSE_INTERVAL_HXX