escript  Revision_Unversioneddirectory
esysUtils/src/IndexList.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 // pre-reserving saves time under OpenMP. The 85 is a value taken over
34 // from revision ~101 by jgs.
35 #define ESYS_INDEXLIST_LENGTH 85
36 
37 namespace esysUtils {
38 
39 struct IndexList {
40  IndexList() : n(0), extension(NULL) {}
41  ~IndexList() { delete extension; }
42 
46 
48  inline void insertIndex(index_t index)
49  {
50  for (dim_t i=0; i<n; i++) {
51  if (m_list[i] == index)
52  return;
53  }
54  if (n < ESYS_INDEXLIST_LENGTH) {
55  m_list[n++] = index;
56  } else {
57  if (extension == NULL)
58  extension = new IndexList();
59  extension->insertIndex(index);
60  }
61  }
62 
64  inline dim_t count(index_t range_min, index_t range_max) const
65  {
66  dim_t out=0;
67  for (dim_t i=0; i < n; i++) {
68  if (m_list[i] >= range_min && range_max > m_list[i])
69  ++out;
70  }
71  if (extension)
72  out += extension->count(range_min, range_max);
73  return out;
74  }
75 
77  inline void toArray(index_t* array, index_t range_min, index_t range_max,
78  index_t index_offset) const
79  {
80  index_t idx = 0;
81  for (dim_t i=0; i < n; i++) {
82  if (m_list[i] >= range_min && range_max > m_list[i]) {
83  array[idx] = m_list[i]+index_offset;
84  ++idx;
85  }
86  }
87  if (extension)
88  extension->toArray(&array[idx], range_min, range_max, index_offset);
89  }
90 };
91 
92 } // namespace esysUtils
93 
94 #endif // __ESYSUTILS_INDEXLIST_H__
95 
IndexList * extension
Definition: esysUtils/src/IndexList.h:45
dim_t n
Definition: esysUtils/src/IndexList.h:44
#define ESYS_INDEXLIST_LENGTH
Definition: esysUtils/src/IndexList.h:35
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:64
index_t m_list[85]
Definition: esysUtils/src/IndexList.h:43
Definition: esysUtils/src/IndexList.h:39
void insertIndex(index_t index)
inserts row index into the IndexList in if it does not exist
Definition: esysUtils/src/IndexList.h:48
Definition: Esys_MPI.cpp:32
int index_t
Definition: types.h:24
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:77
IndexList()
Definition: esysUtils/src/IndexList.h:40
index_t dim_t
Definition: types.h:27
~IndexList()
Definition: esysUtils/src/IndexList.h:41