acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
hash32.h
1//
2// hash32.h
3// acme
4//
5// Created by Camilo Sasuke Thomas Borregaard Soerensen on 29/11/22.
6// Copyright (c) 2022 Camilo Sasuke Tsumanuma. All rights reserved.
7//
8// Refactoring by camilo on 2023-01-09 10:32 <3ThomasBorregaardSorensen!!
9//
10#pragma once
11
12
13struct hash32
14{
15
16
17 ::u32 m_u;
18
19
20 hash32() : m_u(0) {};
21 template < typename T >
22 hash32(const T * p) : m_u((::u32)(::uptr)p) {};
23 template < prototype_integral INTEGRAL >
24 constexpr hash32(INTEGRAL i) : m_u((::u32)i) { }
25 template < prototype_enum ENUM >
26 constexpr hash32(ENUM e) : m_u((::u32)e) { }
27 template < prototype_floating FLOATING >
28 constexpr hash32(FLOATING f) : hash32(&f, sizeof(f)) { }
29 template < typename T >
30 constexpr hash32(const ::pointer < T > & t) : hash32(t.m_p) { }
31 constexpr hash32(const void * p, memsize s):m_u(0) { while (--s >= 0) m_u = (m_u << 5) ^ *((::u8*&)p)++; }
32
33
34 constexpr ::hash32 operator + (::hash32 u)
35 {
36 return (m_u << 16) ^ u.m_u;
37 }
38
39
40};
41
42
43template < typename T >
44::hash32 as_hash32(const T & t) { return (::hash32)t; }
45
46#include <typeindex>
47
48template < >
49inline ::hash32 as_hash32<::std::type_index>(const ::std::type_index & typeindex)
50{ return (::hash32)typeindex.hash_code(); }
51
52//#include "acme/include/_numeric_concepts.h"
53//#include "acme/prototype/prototype/enumeration.h"
54//#include "acme/prototype/prototype/pointer.h"
55
56//
57//struct hash32
58//{
59//
60// ::u32 m_u;
61//
62//
63// template < typename T >
64// hash32(const T* p) : m_u((::u32)(::uptr)p) {}
65// template < prototype_integral INTEGRAL >
66// hash32(INTEGRAL i) : m_u((::u32)i) {}
67// template < a_enum ENUM >
68// hash32(const ::enumeration < ENUM > & e) : m_u((::u32)e.m_eenum) {}
69// hash32(::f32 f) : m_u(*(::u32 *)&f) {}
70// hash32(::f64 d) : m_u(((::u32*)&d)[0]| ((::u32*)&d)[1]) {}
71// template < typename T >
72// hash32(const ::pointer < T >& t) : m_u((::u32)(::uptr)t.m_p) {}
73// hash32(const ::hash32& hash32) : m_u(hash32.m_u) {}
74// hash32() {}
75//
76//};
77
78
79
80template < typename ENUM >
81constexpr c_flag<ENUM>::operator hash32() const
82{
83 return (::u32)m_cflag;
84}
85
86template < typename ENUM>
87constexpr enumeration<ENUM>::operator hash32() const
88{
89 return (::u32)m_eenum;
90}
91
92
Definition enumeration.h:14
Definition enumeration.h:219
Definition hash32.h:14