10 #ifndef EIGEN_RANDOMSETTER_H
11 #define EIGEN_RANDOMSETTER_H
13 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
28 typedef std::map<KeyType,Scalar>
Type;
36 #ifdef EIGEN_UNORDERED_MAP_SUPPORT
53 template<
typename Scalar>
struct StdUnorderedMapTraits
56 typedef std::unordered_map<KeyType,Scalar>
Type;
61 static void setInvalidKey(
Type&,
const KeyType&) {}
63 #endif // EIGEN_UNORDERED_MAP_SUPPORT
65 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
71 using namespace ::google;
73 template<
typename KeyType,
typename Scalar>
75 typedef dense_hash_map<KeyType, Scalar>
type;
78 template<
typename KeyType,
typename Scalar>
79 struct SparseHashMap {
80 typedef sparse_hash_map<KeyType, Scalar>
type;
89 template<
typename Scalar>
struct GoogleDenseHashMapTraits
97 static void setInvalidKey(
Type& map,
const KeyType& k)
98 { map.set_empty_key(k); }
105 template<
typename Scalar>
struct GoogleSparseHashMapTraits
113 static void setInvalidKey(
Type&,
const KeyType&) {}
166 template<
typename SparseMatrixType,
167 template <
typename T>
class MapTraits =
168 #if defined(EIGEN_GOOGLEHASH_SUPPORT)
169 GoogleDenseHashMapTraits
170 #elif defined(_HASH_MAP)
175 ,
int OuterPacketBits = 6>
186 typedef typename MapTraits<ScalarWrapper>::KeyType
KeyType;
206 const Index outerSize =
SwapStorage ? target.innerSize() : target.outerSize();
207 const Index innerSize =
SwapStorage ? target.outerSize() : target.innerSize();
213 Index aux = innerSize - 1;
222 MapTraits<ScalarWrapper>::setInvalidKey(
m_hashmaps[k],ik);
226 for (
typename SparseMatrixType::InnerIterator it(*
mp_target,
j); it; ++it)
239 Index prevOuter = -1;
242 const Index outerOffset = (1<<OuterPacketBits) * k;
244 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
247 const Index inner = it->first & keyBitsMask;
248 if (prevOuter!=outer)
250 for (
Index j=prevOuter+1;
j<=outer;++
j)
254 mp_target->insertBackByOuterInner(outer, inner) = it->second.value;
261 VectorXi positions(
mp_target->outerSize());
267 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
269 const Index outer = it->first & keyBitsMask;
279 positions[
j] = count;
288 const Index outerOffset = (1<<OuterPacketBits) * k;
290 for (
typename HashMapType::iterator it =
m_hashmaps[k].begin(); it!=
end; ++it)
293 const Index outer = it->first & keyBitsMask;
299 Index i = (positions[outer]++) - 1;
300 while ( (
i >= posStart) && (
mp_target->innerIndexPtr()[
i] > inner) )
306 mp_target->innerIndexPtr()[
i+1] = internal::convert_index<StorageIndex>(inner);
307 mp_target->valuePtr()[
i+1] = it->second.value;
319 const Index outerMajor = outer >> OuterPacketBits;
349 #endif // EIGEN_RANDOMSETTER_H