1 #ifndef _snl_fei_RaggedTable_hpp_
2 #define _snl_fei_RaggedTable_hpp_
12 #include <fei_macros.hpp>
14 #include <snl_fei_SetTraits_specialize.hpp>
15 #include <snl_fei_MapTraits_specialize.hpp>
17 #include <fei_IndexTable.hpp>
18 #include <fei_Pool_alloc.hpp>
28 template<
typename MAP_TYPE,
typename SET_TYPE>
36 RaggedTable(
const RaggedTable<MAP_TYPE,SET_TYPE>& src);
65 const MAP_TYPE&
getMap()
const;
72 typedef typename MAP_TYPE::iterator
iterator;
81 bool equal(
const RaggedTable<MAP_TYPE,SET_TYPE>& rhs,
bool quiet=
true)
const;
89 template<
typename MAP_TYPE,
typename SET_TYPE>
98 template<
typename MAP_TYPE,
typename SET_TYPE>
99 inline RaggedTable<MAP_TYPE,SET_TYPE>::RaggedTable(
const RaggedTable<MAP_TYPE,SET_TYPE>& src)
105 template<
typename MAP_TYPE,
typename SET_TYPE>
106 RaggedTable<MAP_TYPE,SET_TYPE>::~RaggedTable()
108 iterator it = begin();
109 iterator it_end = end();
110 for(; it!=it_end; ++it) {
111 poolAllocatorSet_.destroy( it->second );
112 poolAllocatorSet_.deallocate( it->second, 1 );
116 template<
typename MAP_TYPE,
typename SET_TYPE>
117 inline void RaggedTable<MAP_TYPE,SET_TYPE>::addIndices(
int row,
121 iterator m_end = map_.end();
122 iterator m_iter = MapTraits<MAP_TYPE>::lower_bound(map_, row);
124 SET_TYPE* mapped_indices = NULL;
126 bool found_row =
false;
127 if (m_iter != m_end) {
128 if ((*m_iter).first == row) {
129 mapped_indices = (*m_iter).second;
135 mapped_indices = poolAllocatorSet_.allocate(1);
136 poolAllocatorSet_.construct(mapped_indices, dummy);
137 typename MAP_TYPE::value_type val(row, mapped_indices);
138 MapTraits<MAP_TYPE>::insert(map_, m_iter, val);
141 for(
int i=0; i<numIndices; ++i) {
142 SetTraits<SET_TYPE>::insert(mapped_indices, indices[i]);
146 template<
typename MAP_TYPE,
typename SET_TYPE>
147 inline void RaggedTable<MAP_TYPE,SET_TYPE>::addIndices(
int numRows,
152 iterator m_end = map_.end();
154 SET_TYPE* mapped_indices = NULL;
156 for(
int i=0; i<numRows; ++i) {
158 m_iter = MapTraits<MAP_TYPE>::lower_bound(map_, row);
160 bool found_row =
false;
161 if (m_iter != m_end) {
162 const typename MAP_TYPE::value_type& m_pair = *m_iter;
163 if (m_pair.first == row) {
164 mapped_indices = m_pair.second;
170 mapped_indices = poolAllocatorSet_.allocate(1);
171 poolAllocatorSet_.construct(mapped_indices, dummy);
172 typename MAP_TYPE::value_type val(row, mapped_indices);
173 MapTraits<MAP_TYPE>::insert(map_, m_iter, val);
176 for(
int j=0; j<numIndices; ++j) {
177 SetTraits<SET_TYPE>::insert(mapped_indices, indices[j]);
182 template<
typename MAP_TYPE,
typename SET_TYPE>
183 inline MAP_TYPE& RaggedTable<MAP_TYPE,SET_TYPE>::getMap()
188 template<
typename MAP_TYPE,
typename SET_TYPE>
189 inline const MAP_TYPE& RaggedTable<MAP_TYPE,SET_TYPE>::getMap()
const
194 template<
typename MAP_TYPE,
typename SET_TYPE>
195 inline typename RaggedTable<MAP_TYPE,SET_TYPE>::row_type*
196 RaggedTable<MAP_TYPE,SET_TYPE>::getRow(
int row)
198 iterator m_end = map_.end();
199 iterator m_iter = map_.find(row);
200 return( m_end == m_iter ? NULL : (*m_iter).second );
203 template<
typename MAP_TYPE,
typename SET_TYPE>
204 inline typename RaggedTable<MAP_TYPE,SET_TYPE>::iterator
205 RaggedTable<MAP_TYPE,SET_TYPE>::begin()
207 return(map_.begin());
210 template<
typename MAP_TYPE,
typename SET_TYPE>
211 inline typename RaggedTable<MAP_TYPE,SET_TYPE>::iterator
212 RaggedTable<MAP_TYPE,SET_TYPE>::end()
217 template<
typename MAP_TYPE,
typename SET_TYPE>
218 inline void RaggedTable<MAP_TYPE,SET_TYPE>::addDiagonals(
int numIndices,
221 for(
int i=0; i<numIndices; ++i) {
222 int ind = indices[i];
223 addIndices(ind, 1, &ind);
227 template<
typename MAP_TYPE,
typename SET_TYPE>
228 bool RaggedTable<MAP_TYPE,SET_TYPE>::equal(
const RaggedTable<MAP_TYPE,SET_TYPE>& rhs,
bool quiet)
const
230 if (map_.size() != rhs.getMap().size()) {
232 FEI_COUT <<
"RaggedTable::equal sizes don't match." << FEI_ENDL;
237 typename map_type::const_iterator
238 m_iter = map_.begin(),
241 typename map_type::const_iterator
242 rhs_iter = rhs.getMap().begin();
244 for(; m_iter != m_end; ++m_iter, ++rhs_iter) {
245 if (rhs_iter->first != m_iter->first) {
247 FEI_COUT <<
"RaggedTable::equal keys don't match." << FEI_ENDL;
252 if (*(rhs_iter->second) != *(m_iter->second)) {
254 FEI_COUT <<
"RaggedTable::equal row-values don't match." << FEI_ENDL;
void addDiagonals(int numIndices, const int *indices)
RaggedTable(int firstKey, int lastKey)
SET_TYPE * getRow(int row)
MAP_TYPE::iterator iterator
void addIndices(int row, int numIndices, const int *indices)
bool equal(const RaggedTable< MAP_TYPE, SET_TYPE > &rhs, bool quiet=true) const