FEI Version of the Day
fei_SparseRowGraph.hpp
00001 
00002 /*--------------------------------------------------------------------*/
00003 /*    Copyright 2005 Sandia Corporation.                              */
00004 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00005 /*    non-exclusive license for use of this work by or on behalf      */
00006 /*    of the U.S. Government.  Export of this program may require     */
00007 /*    a license from the United States Government.                    */
00008 /*--------------------------------------------------------------------*/
00009 
00010 #ifndef _fei_SparseRowGraph_hpp_
00011 #define _fei_SparseRowGraph_hpp_
00012 
00013 #include <fei_macros.hpp>
00014 #include <vector>
00015 #include <algorithm>
00016 
00017 namespace fei {
00023   class SparseRowGraph {
00024   public:
00026     SparseRowGraph()
00027       : rowNumbers(), rowOffsets(), packedColumnIndices(), blockEntries(false)
00028       {}
00029 
00031     SparseRowGraph(const SparseRowGraph& src)
00032       : rowNumbers(src.rowNumbers), rowOffsets(src.rowOffsets),
00033       packedColumnIndices(src.packedColumnIndices), blockEntries(src.blockEntries)
00034       {}
00035 
00037     virtual ~SparseRowGraph() {}
00038 
00040     bool operator==(const fei::SparseRowGraph& othergraph) const;
00041 
00043     bool operator!=(const fei::SparseRowGraph& othergraph) const;
00044 
00046     std::vector<int> rowNumbers;
00047 
00054     std::vector<int> rowOffsets;
00055 
00059     std::vector<int> packedColumnIndices;
00060 
00062     bool blockEntries;
00063   };//class SparseRowGraph
00064 
00065 inline bool SparseRowGraph::operator==(const fei::SparseRowGraph& othergraph) const
00066 {
00067   if (rowNumbers != othergraph.rowNumbers) return(false);
00068   if (rowOffsets != othergraph.rowOffsets) return(false);
00069   if (packedColumnIndices != othergraph.packedColumnIndices) return(false);
00070   return(true);
00071 }
00072 
00073 inline bool SparseRowGraph::operator!=(const fei::SparseRowGraph& othergraph) const
00074 {
00075   return( !(*this == othergraph) );
00076 }
00077 
00085 inline
00086 int find_row_start(int row, const SparseRowGraph& srg)
00087 {
00088   std::vector<int>::const_iterator rowNumbers_iter =
00089     std::lower_bound(srg.rowNumbers.begin(), srg.rowNumbers.end(), row);
00090   if (rowNumbers_iter == srg.rowNumbers.end() || *rowNumbers_iter != row) {
00091     return -1;
00092   }
00093 
00094   size_t offset = rowNumbers_iter - srg.rowNumbers.begin();
00095   return srg.rowOffsets[offset];
00096 }
00097 
00098 }//namespace fei
00099 
00100 #endif
00101 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends