DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSparseVector.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkSparseVector_h
19 #define __itkSparseVector_h
20 
21 #include "itkIntTypes.h"
22 
23 #include "utlSTDHeaders.h"
24 
25 namespace itk
26 {
32 template< typename TValueType, typename TKeyType = SizeValueType >
34 {
35 public:
36 
38  typedef TValueType ValueType;
39  typedef TKeyType KeyType;
40  typedef TKeyType ElementIdentifier;
41  typedef TValueType ComponentType;
42  typedef utl_unordered_map<TKeyType, TValueType> InternalDataType;
43  typedef SparseVector Self;
44 
47  {
49  m_Data.clear();
50  }
51 
54  {
55  }
56 
58  void Fill(TValueType const & v)
59  {
61  m_Data.clear();
62  }
63 
65  void Clear()
66  {
67  m_Data.clear();
68  }
69 
71  TValueType & operator[](unsigned int i)
72  {
73  return m_Data[i];
74  }
75 
77  TValueType operator[](unsigned int i) const
78  {
79  TValueType value;
80  typename InternalDataType::const_iterator it = m_Data.find( i );
81 
82  if ( it == m_Data.end() )
83  {
84  value = m_FillBufferValue;
85  }
86  else
87  {
88  value = it->second;
89  }
90 
91  return value;
92  }
93 
94  inline unsigned int GetSize(void) const
95  {
96  return m_Data.size();
97  }
98 
99  inline unsigned int Size(void) const
100  {
101  return m_Data.size();
102  }
103 
105  InternalDataType * GetDataPointer()
106  {
107  return &m_Data;
108  }
109 
110  const InternalDataType * GetDataPointer() const
111  {
112  return &m_Data;
113  }
114 
115 private:
116 
117  InternalDataType m_Data; // data
118  ValueType m_FillBufferValue;
119 };
120 
121 } // namespace itk
122 
123 #endif
TValueType ComponentType
TKeyType ElementIdentifier
ValueType m_FillBufferValue
unsigned int GetSize(void) const
SparseVector Self
InternalDataType m_Data
Represents a sparse array.
void Fill(TValueType const &v)
unsigned int Size(void) const
TValueType ValueType
TValueType & operator[](unsigned int i)
InternalDataType * GetDataPointer()
const InternalDataType * GetDataPointer() const
utl_unordered_map< TKeyType, TValueType > InternalDataType
TValueType operator[](unsigned int i) const