Changeset 2105


Ignore:
Timestamp:
Nov 21, 2012, 11:50:55 PM (7 years ago)
Author:
sam
Message:

core: implement hashing functions for half, float and double.

Location:
trunk/src
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r2100 r2105  
    1818    \
    1919    lol/unit.h lol/debug.h \
    20     lol/core/array.h lol/core/string.h lol/core/hash.h \
     20    lol/core/types.h lol/core/array.h lol/core/string.h lol/core/hash.h \
    2121    lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \
    2222    lol/math/math.h \
     
    3939    $(d3d9_sources) \
    4040    $(android_sources) \
    41     $(bullet_sources) \
    4241    \
    4342    core/hash.cpp core/string.cpp \
     
    7675    loldebug.h \
    7776    debug/fps.cpp debug/fps.h \
    78     debug/record.cpp debug/record.h debug/stats.cpp debug/stats.h
     77    debug/record.cpp debug/record.h debug/stats.cpp debug/stats.h \
     78    \
     79    $(bullet_sources)
    7980liblol_a_CPPFLAGS = @LOL_CFLAGS@ -I$(srcdir)/bullet
    8081
  • trunk/src/core.h

    r2097 r2105  
    7676// Base types
    7777#include <lol/debug.h>
     78#include <lol/core/types.h>
    7879#include <lol/core/array.h>
    7980#include <lol/core/string.h>
  • trunk/src/core/hash.cpp

    r2104 r2105  
    4242
    4343/*
    44  * Public Hash classes
     44 * Helper hash functions
    4545 */
    4646
    47 uint32_t Hash<int8_t>::operator ()(int8_t x)
     47static inline uint32_t Hash8(uint8_t x)
    4848{
    4949    uint32_t ret = 0xffffffffu;
     
    5252}
    5353
    54 uint32_t Hash<uint8_t>::operator ()(uint8_t x)
    55 {
    56     uint32_t ret = 0xffffffffu;
    57     ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8);
    58     return ret ^ 0xffffffffu;
    59 }
    60 
    61 uint32_t Hash<int16_t>::operator ()(int16_t x)
     54static inline uint32_t Hash16(uint16_t x)
    6255{
    6356    uint32_t ret = 0xffffffffu;
     
    6760}
    6861
    69 uint32_t Hash<uint16_t>::operator ()(uint16_t x)
    70 {
    71     uint32_t ret = 0xffffffffu;
    72     ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8);
    73     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8);
    74     return ret ^ 0xffffffffu;
    75 }
    76 
    77 uint32_t Hash<int32_t>::operator ()(int32_t x)
     62static inline uint32_t Hash32(uint32_t x)
    7863{
    7964    uint32_t ret = 0xffffffffu;
     
    8570}
    8671
    87 uint32_t Hash<uint32_t>::operator ()(uint32_t x)
    88 {
    89     uint32_t ret = 0xffffffffu;
    90     ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8);
    91     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8);
    92     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8);
    93     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8);
    94     return ret ^ 0xffffffffu;
    95 }
    96 
    97 uint32_t Hash<int64_t>::operator ()(int64_t x)
     72static inline uint32_t Hash64(uint64_t x)
    9873{
    9974    uint32_t ret = 0xffffffffu;
     
    10984}
    11085
     86/*
     87 * Integer hash functions
     88 */
     89
     90uint32_t Hash<int8_t>::operator ()(int8_t x)
     91{
     92    return Hash8((uint8_t)x);
     93}
     94
     95uint32_t Hash<uint8_t>::operator ()(uint8_t x)
     96{
     97    return Hash8(x);
     98}
     99
     100uint32_t Hash<int16_t>::operator ()(int16_t x)
     101{
     102    return Hash16((uint16_t)x);
     103}
     104
     105uint32_t Hash<uint16_t>::operator ()(uint16_t x)
     106{
     107    return Hash16(x);
     108}
     109
     110uint32_t Hash<int32_t>::operator ()(int32_t x)
     111{
     112    return Hash32((uint32_t)x);
     113}
     114
     115uint32_t Hash<uint32_t>::operator ()(uint32_t x)
     116{
     117    return Hash32(x);
     118}
     119
     120uint32_t Hash<int64_t>::operator ()(int64_t x)
     121{
     122    return Hash64((uint64_t)x);
     123}
     124
    111125uint32_t Hash<uint64_t>::operator ()(uint64_t x)
    112126{
    113     uint32_t ret = 0xffffffffu;
    114     ret = data.crc32_table[(uint8_t)(ret ^ x)] ^ (ret >> 8);
    115     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 8))] ^ (ret >> 8);
    116     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 16))] ^ (ret >> 8);
    117     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 24))] ^ (ret >> 8);
    118     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 32))] ^ (ret >> 8);
    119     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 40))] ^ (ret >> 8);
    120     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 48))] ^ (ret >> 8);
    121     ret = data.crc32_table[(uint8_t)(ret ^ (x >> 56))] ^ (ret >> 8);
    122     return ret ^ 0xffffffffu;
     127    return Hash64(x);
    123128}
     129
     130/*
     131 * Floating-point hash functions
     132 */
     133
     134uint32_t Hash<half>::operator ()(half f)
     135{
     136    return Hash16(f.bits);
     137}
     138
     139uint32_t Hash<float>::operator ()(float f)
     140{
     141    union { float tmp; uint32_t x; } u = { f };
     142    return Hash32(u.x);
     143}
     144
     145uint32_t Hash<double>::operator ()(double f)
     146{
     147    union { double tmp; uint64_t x; } u = { f };
     148    return Hash64(u.x);
     149}
     150
     151/*
     152 * String and array hash functions
     153 */
    124154
    125155static uint32_t HashCharString(char const *s)
  • trunk/src/lol/core/array.h

    r2086 r2105  
    1616//
    1717
    18 #if !defined __LOL_ARRAY_H__
    19 #define __LOL_ARRAY_H__
     18#if !defined __LOL_CORE_ARRAY_H__
     19#define __LOL_CORE_ARRAY_H__
    2020
    2121#include <new>
     
    508508} /* namespace lol */
    509509
    510 #endif // __LOL_ARRAY_H__
    511 
     510#endif // __LOL_CORE_ARRAY_H__
     511
  • trunk/src/lol/core/hash.h

    r2104 r2105  
    1515//
    1616
    17 #if !defined __LOL_HASH_H__
    18 #define __LOL_HASH_H__
     17#if !defined __LOL_CORE_HASH_H__
     18#define __LOL_CORE_HASH_H__
    1919
    2020namespace lol
     
    3232template<> class Hash<uint64_t> { public: uint32_t operator()(uint64_t); };
    3333
     34template<> class Hash<half>     { public: uint32_t operator()(half); };
     35template<> class Hash<float>    { public: uint32_t operator()(float); };
     36template<> class Hash<double>   { public: uint32_t operator()(double); };
     37template<> class Hash<ldouble>  { public: uint32_t operator()(ldouble); };
     38
    3439template<> class Hash<char const *>
    3540{
     
    4651} /* namespace lol */
    4752
    48 #endif // __LOL_HASH_H__
     53#endif // __LOL_CORE_HASH_H__
    4954
  • trunk/src/lol/core/string.h

    r2100 r2105  
    1515//
    1616
    17 #if !defined __LOL_STRING_H__
    18 #define __LOL_STRING_H__
     17#if !defined __LOL_CORE_STRING_H__
     18#define __LOL_CORE_STRING_H__
    1919
    2020#include <lol/core/array.h>
     
    120120} /* namespace lol */
    121121
    122 #endif // __LOL_STRING_H__
     122#endif // __LOL_CORE_STRING_H__
    123123
  • trunk/src/lol/math/math.h

    r2058 r2105  
    2929#undef min
    3030#undef max
    31 
    32 /* There are many reasons for wanting single-word type names, the most
    33  * important one being compilation speedups in our vector.h: we can hide
    34  * some global methods in namespaces that contain the name of the type,
    35  * but namespaces cannot have spaces in their names. */
    36 typedef long double ldouble;
    3731
    3832/* Standard cmath functions */
  • trunk/src/lol/math/real.h

    r1893 r2105  
    200200
    201201/*
    202  * The real type used for real numbers
    203  */
    204 typedef Real<16> real;
    205 
    206 /*
    207202 * Mandatory forward declarations of template specialisations
    208203 */
  • trunk/src/lolcore.vcxproj

    r2100 r2105  
    586586    <ClInclude Include="lol\core\hash.h" />
    587587    <ClInclude Include="lol\core\string.h" />
     588    <ClInclude Include="lol\core\types.h" />
    588589    <ClInclude Include="lol\debug.h" />
    589590    <ClInclude Include="lol\math\half.h" />
  • trunk/src/lolcore.vcxproj.filters

    r2100 r2105  
    734734    </ClInclude>
    735735    <ClInclude Include="array.h">
    736       <Filter>src\...</Filter>
     736      <Filter>src\core</Filter>
     737    </ClInclude>
     738    <ClInclude Include="types.h">
     739      <Filter>src\core</Filter>
    737740    </ClInclude>
    738741    <ClInclude Include="hash.h">
    739       <Filter>src\...</Filter>
     742      <Filter>src\core</Filter>
    740743    </ClInclude>
    741744    <ClInclude Include="audio.h">
Note: See TracChangeset for help on using the changeset viewer.