FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_SparseRowGraph.hpp
1 
2 /*--------------------------------------------------------------------*/
3 /* Copyright 2005 Sandia Corporation. */
4 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
5 /* non-exclusive license for use of this work by or on behalf */
6 /* of the U.S. Government. Export of this program may require */
7 /* a license from the United States Government. */
8 /*--------------------------------------------------------------------*/
9 
10 #ifndef _fei_SparseRowGraph_hpp_
11 #define _fei_SparseRowGraph_hpp_
12 
13 #include <fei_macros.hpp>
14 #include <vector>
15 #include <algorithm>
16 
17 namespace fei {
24  public:
28  {}
29 
34  {}
35 
37  virtual ~SparseRowGraph() {}
38 
40  bool operator==(const fei::SparseRowGraph& othergraph) const;
41 
43  bool operator!=(const fei::SparseRowGraph& othergraph) const;
44 
46  std::vector<int> rowNumbers;
47 
54  std::vector<int> rowOffsets;
55 
59  std::vector<int> packedColumnIndices;
60 
63  };//class SparseRowGraph
64 
65 inline bool SparseRowGraph::operator==(const fei::SparseRowGraph& othergraph) const
66 {
67  if (rowNumbers != othergraph.rowNumbers) return(false);
68  if (rowOffsets != othergraph.rowOffsets) return(false);
69  if (packedColumnIndices != othergraph.packedColumnIndices) return(false);
70  return(true);
71 }
72 
73 inline bool SparseRowGraph::operator!=(const fei::SparseRowGraph& othergraph) const
74 {
75  return( !(*this == othergraph) );
76 }
77 
85 inline
86 int find_row_start(int row, const SparseRowGraph& srg)
87 {
88  std::vector<int>::const_iterator rowNumbers_iter =
89  std::lower_bound(srg.rowNumbers.begin(), srg.rowNumbers.end(), row);
90  if (rowNumbers_iter == srg.rowNumbers.end() || *rowNumbers_iter != row) {
91  return -1;
92  }
93 
94  size_t offset = rowNumbers_iter - srg.rowNumbers.begin();
95  return srg.rowOffsets[offset];
96 }
97 
98 }//namespace fei
99 
100 #endif
101 
int find_row_start(int row, const SparseRowGraph &srg)
bool operator==(const fei::SparseRowGraph &othergraph) const
std::vector< int > rowNumbers
bool operator!=(const fei::SparseRowGraph &othergraph) const
std::vector< int > packedColumnIndices
std::vector< int > rowOffsets
SparseRowGraph(const SparseRowGraph &src)