1 #ifndef TIL_RLE_ARRAY_H 2 #define TIL_RLE_ARRAY_H 23 template <
typename T,
typename TCount =
unsigned int >
36 typedef std::list<Segment> Data;
59 : m_data(1,
Segment(TCount(i), value))
70 {
return iterator(m_data.begin(), 0, 0, *
this); }
72 {
return iterator(m_data.end(), 0, m_size, *
this); }
81 void set(std::pair<typename Data::iterator, TCount> & index,
const T & value);
82 template <
typename XIterator >
83 const T &
get(std::pair<XIterator, TCount> & index)
const 84 {
return index.first->value(); }
86 std::size_t
size()
const {
return m_size; }
91 for (
typename Data::const_iterator iRepValue = m_data.begin(); iRepValue != m_data.end(); ++iRepValue)
93 std::cout <<
"Value : " << iRepValue->value() <<
" ";
94 std::cout <<
"Repeat : " << iRepValue->length() <<
", ";
96 std::cout << std::endl;
109 template <
typename T,
typename TCount >
118 Segment(TCount r,
const T &v) : m_value(v), m_length(r) {};
124 const TCount &
length()
const {
return m_length; }
126 const T &
value()
const {
return m_value; }
140 template <
typename T,
typename TCount >
144 typedef typename Data::const_iterator
Base;
150 template <
typename T,
typename TCount >
154 typedef typename Data::iterator
Base;
168 template <
typename TRLEArray,
typename TIterator >
191 : m_valueProxy(index_type(i, segindex), c)
196 template <
typename XRLEArray,
typename XIterator >
198 : m_valueProxy(b.proxy())
206 std::size_t
pos()
const {
return m_i; }
209 const ValueProxy &
proxy()
const {
return m_valueProxy; }
227 if (++(m_valueProxy.index().second) == m_valueProxy.index().first->length())
232 ++(m_valueProxy.index().first);
233 m_valueProxy.index().second = 0;
239 std::cout <<
"Pointing on " << m_valueProxy.index().first->value() <<
" "<< m_valueProxy.index().first->length() << std::endl;
240 std::cout <<
"Local pos: " << m_valueProxy.index().second << std::endl;
241 std::cout <<
"Absolute pos: " << m_i << std::endl;
254 ValueProxy m_valueProxy;
262 template <
typename TRLEArray1,
typename TRLEArray2,
typename TIterator1,
typename TIterator2 >
269 {
return (i1.
proxy().index().first == i2.proxy().index().first) && (i1.
proxy().index().second == i2.proxy().index().second); }
273 template <
typename TRLEArray1,
typename TRLEArray2,
typename TIterator1,
typename TIterator2 >
280 {
return !(i1 == i2); }
288 template <
typename T,
typename TCount >
298 : Base(i, segindex, pos, c)
303 template <
typename XRLEArray,
typename XIterator >
307 template <
typename T,
typename TCount >
317 : Base(i, segindex, pos, c)
A Segment is composed of a value and a length.
rle_array_iterator_base< TRLEArray, TIterator > Self
const ValueProxy & proxy() const
Base::reference reference
rle_array_iterator_base(const rle_array_iterator_base< XRLEArray, XIterator > &b)
Base::value_type value_type
std::pair< TIterator, count_type > index_type
detail::rle_array_iterator_base< rle_array< T, TCount >, typename Data::iterator > Base
ValueProxy::const_pointer pointer
Adds some left-value operations to const_value_proxy.
const_sparse_iterator(const Base &b)
const T & operator[](std::size_t i) const
Belongs to package Box Do not include directly, include til/Box.h instead.
const T & const_reference
value_proxy< TRLEArray, index_type, policy::VPAccess_Default< container, index_type & > > ValueProxy
sparse_iterator(const Base &b)
Data::const_iterator Base
const_iterator(const typename Data::const_iterator &i, TCount segindex, std::size_t pos, const rle_array< T, TCount > &c)
Base::value_type value_type
const TCount & length() const
const_iterator end() const
Base::reference reference
Segment(TCount r, const T &v)
rle_array(std::size_t i, T value=T())
Standard constructor providing a size and an optional fill value.
rle_array< T, TCount > Self
const_iterator begin() const
rle_array()
Default constructor, yield a zero-size container.
TRLEArray::count_type count_type
iterator(const typename Data::iterator &i, TCount segindex, std::size_t pos, rle_array< T, TCount > &c)
policy::VPAccess_Default< container, index_type & > ::const_pointer const_pointer
A run-length encoded array.
rle_array_iterator_base(const TIterator &i, count_type segindex, std::size_t pos, container &c)
detail::rle_array_iterator_base< const rle_array< T, TCount >, typename Data::const_iterator > Base
container::value_type value_type
std::size_t pos() const
Return the current position of the iterator in the array.
const_iterator(const detail::rle_array_iterator_base< XRLEArray, XIterator > &b)
This is only to convert from an rle_array<T,TCount>::iterator, so that one can write const_iterator i...