@@ -349,7 +349,28 @@ struct CachedDatatype
349
349
};
350
350
351
351
// Work around the fact that references aren't part of the typeid result
352
- using type_hash_t = std::pair<std::type_index, std::size_t >;
352
+ using type_hash_t = std::pair<std::size_t , std::size_t >;
353
+
354
+ namespace detail
355
+ {
356
+ // See http://www.cse.yorku.ca/~oz/hash.html
357
+ inline std::size_t djb2_hash (const char * str)
358
+ {
359
+ std::size_t hash = 5381 ;
360
+ while (auto c = static_cast <unsigned char >(*str++))
361
+ {
362
+ hash = ((hash << 5 ) + hash) ^ c; /* hash * 33 ^ c */
363
+ }
364
+
365
+ return hash;
366
+ }
367
+
368
+ template <typename T>
369
+ inline std::size_t type_hash ()
370
+ {
371
+ return djb2_hash (typeid (T).name ());
372
+ }
373
+ }
353
374
354
375
} // namespace jlcxx
355
376
@@ -361,7 +382,7 @@ struct hash<jlcxx::type_hash_t>
361
382
{
362
383
std::size_t operator ()(const jlcxx::type_hash_t & h) const noexcept
363
384
{
364
- std::size_t h1 = std::hash<std::type_index >{}(h.first );
385
+ std::size_t h1 = std::hash<std::size_t >{}(h.first );
365
386
std::size_t h2 = std::hash<std::size_t >{}(h.second );
366
387
return h1 ^ (h2 << 1 );
367
388
}
@@ -380,7 +401,7 @@ struct TypeHash
380
401
{
381
402
static inline type_hash_t value ()
382
403
{
383
- return std::make_pair (std::type_index ( typeid (T) ), std::size_t (0 ));
404
+ return std::make_pair (detail::type_hash<T>( ), std::size_t (0 ));
384
405
}
385
406
};
386
407
@@ -389,7 +410,7 @@ struct TypeHash<T&>
389
410
{
390
411
static inline type_hash_t value ()
391
412
{
392
- return std::make_pair (std::type_index ( typeid (T) ), std::size_t (1 ));
413
+ return std::make_pair (detail::type_hash<T>( ), std::size_t (1 ));
393
414
}
394
415
};
395
416
@@ -398,7 +419,7 @@ struct TypeHash<const T&>
398
419
{
399
420
static inline type_hash_t value ()
400
421
{
401
- return std::make_pair (std::type_index ( typeid (T) ), std::size_t (2 ));
422
+ return std::make_pair (detail::type_hash<T>( ), std::size_t (2 ));
402
423
}
403
424
};
404
425
@@ -435,9 +456,9 @@ class JuliaTypeCache
435
456
if (!insert_success)
436
457
{
437
458
type_hash_t old_hash = inserted_it->first ;
438
- std::cout << " Warning: Type " << new_hash. first .name () << " already had a mapped type set as "
439
- << julia_type_name (inserted_it->second .get_dt ()) << " and const-ref indicator " << old_hash.second << " and C++ type name " << old_hash. first . name ()
440
- << " . Hash comparison: old(" << old_hash.first . hash_code () << " ," << old_hash.second << " ) == new(" << old_hash.first . hash_code () << " ," << old_hash.second << " ) == "
459
+ std::cout << " Warning: Type " << typeid (SourceT) .name () << " already had a mapped type set as "
460
+ << julia_type_name (inserted_it->second .get_dt ()) << " and const-ref indicator " << old_hash.second
461
+ << " . Hash comparison: old(" << old_hash.first << " ," << old_hash.second << " ) == new(" << old_hash.first << " ," << old_hash.second << " ) == "
441
462
<< std::boolalpha << (old_hash == new_hash) << std::endl;
442
463
return ;
443
464
}
0 commit comments