vtf-logo

SparseArray.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_SparseArray_h__)
00009 #define __ads_SparseArray_h__
00010 
00011 // If we are debugging the whole ads package.
00012 #if defined(DEBUG_ads) && !defined(DEBUG_SparseArray)
00013 #define DEBUG_SparseArray
00014 #endif
00015 
00016 #include "Array.h"
00017 
00018 #include "../iterator/TransformIterator.h"
00019 
00020 BEGIN_NAMESPACE_ADS
00021 
00022 
00023 // Note: Doxygen will not pick up this class documentation because it is a 
00024 // declaration and there is no class definition.  Only specializations are
00025 // defined.
00027 
00031 template<int N, typename T = double>
00032 class SparseArray;
00033 
00034 
00035 //-----------------------------------------------------------------------------
00038 
00039 // CONTINUE: I think I can remove these since I have functions defined for
00040 // ArrayContainer's.
00041 #if 0
00042 //
00043 // Mathematical functions
00044 //
00045 
00047 template<int N, typename T>
00048 inline
00049 T
00050 computeSum(const SparseArray<N,T>& x) {
00051   return std::accumulate(x.begin(), x.end(), T(0));
00052 }
00053     
00055 template<int N, typename T>
00056 inline
00057 T
00058 computeProduct(const SparseArray<N,T>& x) {
00059   return std::accumulate(x.begin(), x.end(), T(1), std::multiplies<T>());
00060 }
00061 
00063 template<int N, typename T>
00064 inline
00065 T
00066 computeMinimum(const SparseArray<N,T>& x) {
00067   return *std::min_element(x.begin(), x.end());
00068 }
00069     
00071 template<int N, typename T>
00072 inline
00073 T
00074 computeMaximum(const SparseArray<N,T>& x) {
00075   return *std::max_element(x.begin(), x.end());
00076 }
00077 
00078 #endif
00079 
00080 //
00081 // Equality.
00082 //
00083 
00084 // CONTINUE: I don't think I need these because I have the member functions.
00085 #if 0
00087 template<int N, typename T>
00088 inline
00089 bool
00090 operator==(const SparseArray<N,T>& x, const SparseArray<N,T>& y) {
00091   return x.isEqual(y);
00092 }
00093 
00095 template<int N, typename T>
00096 inline
00097 bool
00098 operator!=(const SparseArray<N,T>& x, const SparseArray<N,T>& y) {
00099   return !(x == y);
00100 }
00101 #endif
00102 
00103 //
00104 // File I/O.
00105 //
00106 
00108 
00121 template<int N, typename T>
00122 inline
00123 std::ostream&
00124 operator<<(std::ostream& out, const SparseArray<N,T>& x) {
00125   x.put(out);
00126   return out;
00127 }
00128 
00130 
00143 template<int N, typename T>
00144 inline
00145 std::istream&
00146 operator>>(std::istream& in, SparseArray<N,T>& x) {
00147   x.get(in);
00148   return in;
00149 }
00150 
00152 
00153 END_NAMESPACE_ADS
00154 
00155 #define __ads_SparseArray1_h__
00156 #include "SparseArray1.h"
00157 #undef __ads_SparseArray1_h__
00158 
00159 #define __ads_SparseArray2_h__
00160 #include "SparseArray2.h"
00161 #undef __ads_SparseArray2_h__
00162 
00163 #endif

Generated on Fri Aug 24 12:55:28 2007 for Algorithms and Data Structures Package by  doxygen 1.4.7