ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.97 by root, Fri Mar 26 01:04:44 2010 UTC vs.
Revision 1.99 by root, Fri Apr 9 02:45:16 2010 UTC

99 99
100// sign0 returns -1, 0 or +1 100// sign0 returns -1, 0 or +1
101template<typename T> 101template<typename T>
102static inline T sign0 (T v) { return v ? sign (v) : 0; } 102static inline T sign0 (T v) { return v ? sign (v) : 0; }
103 103
104template<typename T, typename U>
105static inline T copysign (T a, U b) { return a > 0 ? b : -b; }
106
104// div* only work correctly for div > 0 107// div* only work correctly for div > 0
105// div, with correct rounding (< 0.5 downwards, >=0.5 upwards) 108// div, with correct rounding (< 0.5 downwards, >=0.5 upwards)
106template<typename T> static inline T div (T val, T div) 109template<typename T> static inline T div (T val, T div)
107{ 110{
108 return expect_false (val < 0) ? - ((-val + (div - 1) / 2) / div) : (val + div / 2) / div; 111 return expect_false (val < 0) ? - ((-val + (div - 1) / 2) / div) : (val + div / 2) / div;
573 // FNV-1a is faster on many cpus because the multiplication 576 // FNV-1a is faster on many cpus because the multiplication
574 // runs concurrently with the looping logic. 577 // runs concurrently with the looping logic.
575 uint32_t hash = STRHSH_NULL; 578 uint32_t hash = STRHSH_NULL;
576 579
577 while (*s) 580 while (*s)
578 hash = (hash ^ *s++) * 16777619; 581 hash = (hash ^ *s++) * 16777619U;
579 582
580 return hash; 583 return hash;
581} 584}
582 585
583static inline uint32_t 586static inline uint32_t
584memhsh (const char *s, size_t len) 587memhsh (const char *s, size_t len)
585{ 588{
586 uint32_t hash = STRHSH_NULL; 589 uint32_t hash = STRHSH_NULL;
587 590
588 while (len--) 591 while (len--)
589 hash = (hash ^ *s++) * 16777619; 592 hash = (hash ^ *s++) * 16777619U;
590 593
591 return hash; 594 return hash;
592} 595}
593 596
594struct str_hash 597struct str_hash

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines