escript  Revision_4925
esysUtils/src/IndexList.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 /****************************************************************************/
19 
20 /* esysUtils: IndexList */
21 
22 /****************************************************************************/
23 
24 /* Author: Lutz Gross, l.gross@uq.edu.au */
25 
26 /****************************************************************************/
27 
28 #ifndef __ESYSUTILS_INDEXLIST_H__
29 #define __ESYSUTILS_INDEXLIST_H__
30 
31 #include "types.h"
32 
33 #include <algorithm>
34 #include <list>
35 #include <vector>
36 
37 namespace esysUtils {
38 
39 struct IndexList;
40 typedef std::vector<IndexList> IndexListArray;
41 
42 struct IndexList {
43  std::list<index_t> m_list;
44 
46  inline void insertIndex(index_t index)
47  {
48  if (std::find(m_list.begin(), m_list.end(), index) == m_list.end())
49  m_list.push_back(index);
50  }
51 
53  inline dim_t count(index_t range_min, index_t range_max) const
54  {
55  dim_t out=0;
56  std::list<index_t>::const_iterator it;
57  for (it=m_list.begin(); it != m_list.end(); it++) {
58  if (*it >= range_min && range_max > *it)
59  ++out;
60  }
61  return out;
62  }
63 
65  inline void toArray(index_t* array, index_t range_min, index_t range_max,
66  index_t index_offset) const
67  {
68  index_t idx = 0;
69  std::list<index_t>::const_iterator it;
70  for (it=m_list.begin(); it != m_list.end(); it++) {
71  if (*it >= range_min && range_max > *it) {
72  array[idx] = (*it)+index_offset;
73  ++idx;
74  }
75  }
76  }
77 };
78 
79 } // namespace esysUtils
80 
81 #endif // __ESYSUTILS_INDEXLIST_H__
82 
dim_t count(index_t range_min, index_t range_max) const
counts the number of row indices in the IndexList in
Definition: esysUtils/src/IndexList.h:53
std::vector< IndexList > IndexListArray
Definition: esysUtils/src/IndexList.h:39
Definition: esysUtils/src/IndexList.h:42
void insertIndex(index_t index)
inserts row index into the IndexList in if it does not exist
Definition: esysUtils/src/IndexList.h:46
int index_t
Definition: types.h:25
void toArray(index_t *array, index_t range_min, index_t range_max, index_t index_offset) const
index list to array
Definition: esysUtils/src/IndexList.h:65
std::list< index_t > m_list
Definition: esysUtils/src/IndexList.h:43
int dim_t
Definition: types.h:24