17 #ifndef VCSN_MISC_SPARSE_INTERVAL_HXX
18 # define VCSN_MISC_SPARSE_INTERVAL_HXX
32 template <
class Integer,
class ExcludedContainer>
33 SparseIterator<Integer, ExcludedContainer>::
34 SparseIterator (integer_t from,
35 const excluded_container_t& c)
40 template <
class Integer,
class ExcludedContainer>
41 SparseIterator<Integer, ExcludedContainer>&
42 SparseIterator<Integer, ExcludedContainer>::operator++ ()
44 if (excluded_->size () == 0)
45 integer_ = integer_ + 1;
48 integer_ = integer_ + 1;
49 while (excluded_->find (integer_) != excluded_->end ());
53 template <
class Integer,
class ExcludedContainer>
54 SparseIterator<Integer, ExcludedContainer>&
55 SparseIterator<Integer, ExcludedContainer>::operator-- ()
57 if (excluded_->size () == 0)
58 integer_ = integer_ - 1;
61 integer_ = integer_ - 1;
62 while (excluded_->find (integer_) != excluded_->end ());
66 template <
class Integer,
class ExcludedContainer>
67 SparseIterator<Integer, ExcludedContainer>
68 SparseIterator<Integer, ExcludedContainer>::operator++ (
int)
70 SparseIterator tmp = *
this;
75 template <
class Integer,
class ExcludedContainer>
76 SparseIterator<Integer, ExcludedContainer>
77 SparseIterator<Integer, ExcludedContainer>::operator-- (
int)
79 SparseIterator tmp = *
this;
84 template <
class Integer,
class ExcludedContainer>
85 typename SparseIterator<Integer, ExcludedContainer>::
92 template <
class Integer,
class ExcludedContainer>
97 return i.integer_ != integer_;
100 template <
class Integer,
class ExcludedContainer>
102 SparseIterator<Integer, ExcludedContainer>
103 ::operator== (
const SparseIterator& i)
const
105 return i.integer_ == integer_;
108 template <
class Integer,
class ExcludedContainer>
109 SparseIterator<Integer, ExcludedContainer>&
110 SparseIterator<Integer, ExcludedContainer>
111 ::operator= (
const SparseIterator& i)
113 integer_ = i.integer_;
114 excluded_ = i.excluded_;
129 template <
class Integer,
class ExcludedContainer>
136 precondition (from_ <= to_ + 1);
137 precondition (excluded_.find (to_ + 1) == excluded_.end ());
140 template <
class Integer,
class ExcludedContainer>
143 : excluded_ (a.excluded_),
149 template <
class Integer,
class ExcludedContainer>
151 SparseInterval<Integer, ExcludedContainer>::size ()
const
153 return to_ < from_ ? 0 : to_ - from_ + 1 - excluded_.size ();
156 template <
class Integer,
class ExcludedContainer>
157 typename SparseInterval<Integer, ExcludedContainer>::integer_t
158 SparseInterval<Integer, ExcludedContainer>::max ()
const
162 while (excluded_.find (r) != excluded_.end ())
167 template <
class Integer,
class ExcludedContainer>
169 SparseInterval<Integer, ExcludedContainer>::to_string ()
const
172 s <<
"from :" << from_ <<
" to : " << to_ <<
" ex:";
173 for (
typename ExcludedContainer::iterator i = excluded_.begin ();
174 i != excluded_.end ();
180 template <
class Integer,
class ExcludedContainer>
181 typename SparseInterval<Integer, ExcludedContainer>::iterator
182 SparseInterval<Integer, ExcludedContainer>::begin ()
const
186 if (excluded_.size () != 0)
187 while (excluded_.find (from) != excluded_.end ())
189 return iterator (from, excluded_);
192 template <
class Integer,
class ExcludedContainer>
193 typename SparseInterval<Integer, ExcludedContainer>::iterator
194 SparseInterval<Integer, ExcludedContainer>::end ()
const
196 return iterator (to_ + 1, excluded_);
202 #endif // ! VCSN_MISC_SPARSE_INTERVAL_HXX