1 #ifndef _snl_fei_MapContig_hpp_
2 #define _snl_fei_MapContig_hpp_
12 #include <fei_macros.hpp>
18 template<
typename VAL_TYPE>
24 MapContig(
const MapContig<VAL_TYPE>& src);
35 typedef typename std::pair<int,VAL_TYPE>
value_type;
45 MapContig<VAL_TYPE>* mapPtr)
46 :
offset_(offset), mapPtr_(mapPtr)
56 if (!mapPtr_)
return(*
this);
57 int len = mapPtr_->len_;
58 int* keysPtr = mapPtr_->keysPtr_;
59 int first = mapPtr_->first_;
63 if (keysPtr[
offset_] >= first)
break;
73 return(
offset_ == rhs.offset_);
79 return(
offset_ != rhs.offset_ );
96 mapPtr_ = src.mapPtr_;
103 MapContig<VAL_TYPE>* mapPtr_;
118 iterator
find(
int key);
127 friend class iterator;
129 std::vector<int> keys_;
132 std::vector<VAL_TYPE> values_;
133 VAL_TYPE* valuesPtr_;
138 template<
typename VAL_TYPE>
140 : keys_(lastKey-firstKey+1),
142 values_(lastKey-firstKey+1),
144 len_(lastKey-firstKey+1)
146 keysPtr_ = keys_.size()>0 ? &keys_[0] : NULL;
147 for(
int i=0; i<len_; ++i) {
148 keysPtr_[i] = firstKey+i;
150 valuesPtr_ = values_.size()>0 ? &values_[0] : NULL;
152 m_end_ = iterator(len_,
this);
155 template<
typename VAL_TYPE>
156 MapContig<VAL_TYPE>::MapContig(
const MapContig<VAL_TYPE>& src)
159 values_(src.values_),
163 keysPtr_ = keys_.size()>0 ? &keys_[0] : NULL;
164 valuesPtr_ = values_.size()>0 ? &values_[0] : NULL;
165 m_end_ = iterator(len_,
this);
168 template<
typename VAL_TYPE>
169 MapContig<VAL_TYPE>::~MapContig()
173 template<
typename VAL_TYPE>
174 inline typename MapContig<VAL_TYPE>::iterator MapContig<VAL_TYPE>::begin()
176 return( iterator(0,
this) );
179 template<
typename VAL_TYPE>
180 inline typename MapContig<VAL_TYPE>::iterator& MapContig<VAL_TYPE>::end()
185 template<
typename VAL_TYPE>
186 inline std::pair<typename MapContig<VAL_TYPE>::iterator,
bool>
187 MapContig<VAL_TYPE>::insert(
typename MapContig<VAL_TYPE>::value_type val)
189 int localkey = val.first - first_;
190 if (localkey < 0 || localkey >= len_) {
191 return( std::pair<iterator,bool>(m_end_,
false) );
194 valuesPtr_[localkey] = val.second;
196 return( std::pair<iterator,bool>(iterator(localkey,
this),
true));
199 template<
typename VAL_TYPE>
200 inline typename MapContig<VAL_TYPE>::iterator
201 MapContig<VAL_TYPE>::insert(
typename MapContig<VAL_TYPE>::iterator& pos,
202 typename MapContig<VAL_TYPE>::value_type val)
204 int offset = pos.offset_;
205 if (offset < 0 || offset >=len_ || pos == m_end_) {
206 offset = val.first - first_;
207 if (offset < 0 || offset >= len_) {
212 valuesPtr_[offset] = val.second;
214 return( iterator(offset,
this) );
217 template<
typename VAL_TYPE>
218 inline typename MapContig<VAL_TYPE>::iterator MapContig<VAL_TYPE>::find(
int key)
220 int localkey = key - first_;
221 if (localkey < 0 || localkey >= len_) {
225 return(iterator(localkey,
this));
228 template<
typename VAL_TYPE>
229 inline typename MapContig<VAL_TYPE>::iterator MapContig<VAL_TYPE>::lower_bound(
int key)
231 int localkey = key - first_;
232 if (localkey < 0 || localkey >= len_) {
236 return(iterator(localkey,
this));
239 template<
typename VAL_TYPE>
240 int MapContig<VAL_TYPE>::size()
const
std::pair< int, VAL_TYPE > value_type
std::pair< iterator, bool > insert(value_type val)
iterator & operator=(const iterator &src)
bool operator==(const iterator &rhs)
iterator lower_bound(int key)
bool operator!=(const iterator &rhs)
MapContig(int firstKey, int lastKey)