|
@@ -174,14 +174,6 @@ uint64_t random();
|
|
|
*/
|
|
|
bool scopy(char *dest,unsigned int len,const char *src);
|
|
|
|
|
|
-static ZT_ALWAYS_INLINE float normalize(float value, int64_t bigMin, int64_t bigMax, int32_t targetMin, int32_t targetMax)
|
|
|
-{
|
|
|
- int64_t bigSpan = bigMax - bigMin;
|
|
|
- int64_t smallSpan = targetMax - targetMin;
|
|
|
- float valueScaled = (value - (float)bigMin) / (float)bigSpan;
|
|
|
- return (float)targetMin + valueScaled * (float)smallSpan;
|
|
|
-}
|
|
|
-
|
|
|
/**
|
|
|
* Tokenize a string (alias for strtok_r or strtok_s depending on platform)
|
|
|
*
|
|
@@ -189,7 +181,7 @@ static ZT_ALWAYS_INLINE float normalize(float value, int64_t bigMin, int64_t big
|
|
|
* @param delim Delimiters
|
|
|
* @param saveptr Pointer to a char * for temporary reentrant storage
|
|
|
*/
|
|
|
-static ZT_ALWAYS_INLINE char *stok(char *str,const char *delim,char **saveptr)
|
|
|
+ZT_ALWAYS_INLINE char *stok(char *str,const char *delim,char **saveptr)
|
|
|
{
|
|
|
#ifdef __WINDOWS__
|
|
|
return strtok_s(str,delim,saveptr);
|
|
@@ -198,11 +190,11 @@ static ZT_ALWAYS_INLINE char *stok(char *str,const char *delim,char **saveptr)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-static ZT_ALWAYS_INLINE unsigned int strToUInt(const char *s) { return (unsigned int)strtoul(s,(char **)0,10); }
|
|
|
-static ZT_ALWAYS_INLINE int strToInt(const char *s) { return (int)strtol(s,(char **)0,10); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned long strToULong(const char *s) { return strtoul(s,(char **)0,10); }
|
|
|
-static ZT_ALWAYS_INLINE long strToLong(const char *s) { return strtol(s,(char **)0,10); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned long long strToU64(const char *s)
|
|
|
+ZT_ALWAYS_INLINE unsigned int strToUInt(const char *s) { return (unsigned int)strtoul(s,(char **)0,10); }
|
|
|
+ZT_ALWAYS_INLINE int strToInt(const char *s) { return (int)strtol(s,(char **)0,10); }
|
|
|
+ZT_ALWAYS_INLINE unsigned long strToULong(const char *s) { return strtoul(s,(char **)0,10); }
|
|
|
+ZT_ALWAYS_INLINE long strToLong(const char *s) { return strtol(s,(char **)0,10); }
|
|
|
+ZT_ALWAYS_INLINE unsigned long long strToU64(const char *s)
|
|
|
{
|
|
|
#ifdef __WINDOWS__
|
|
|
return (unsigned long long)_strtoui64(s,(char **)0,10);
|
|
@@ -210,7 +202,7 @@ static ZT_ALWAYS_INLINE unsigned long long strToU64(const char *s)
|
|
|
return strtoull(s,(char **)0,10);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE long long strTo64(const char *s)
|
|
|
+ZT_ALWAYS_INLINE long long strTo64(const char *s)
|
|
|
{
|
|
|
#ifdef __WINDOWS__
|
|
|
return (long long)_strtoi64(s,(char **)0,10);
|
|
@@ -218,11 +210,11 @@ static ZT_ALWAYS_INLINE long long strTo64(const char *s)
|
|
|
return strtoll(s,(char **)0,10);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE unsigned int hexStrToUInt(const char *s) { return (unsigned int)strtoul(s,(char **)0,16); }
|
|
|
-static ZT_ALWAYS_INLINE int hexStrToInt(const char *s) { return (int)strtol(s,(char **)0,16); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned long hexStrToULong(const char *s) { return strtoul(s,(char **)0,16); }
|
|
|
-static ZT_ALWAYS_INLINE long hexStrToLong(const char *s) { return strtol(s,(char **)0,16); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned long long hexStrToU64(const char *s)
|
|
|
+ZT_ALWAYS_INLINE unsigned int hexStrToUInt(const char *s) { return (unsigned int)strtoul(s,(char **)0,16); }
|
|
|
+ZT_ALWAYS_INLINE int hexStrToInt(const char *s) { return (int)strtol(s,(char **)0,16); }
|
|
|
+ZT_ALWAYS_INLINE unsigned long hexStrToULong(const char *s) { return strtoul(s,(char **)0,16); }
|
|
|
+ZT_ALWAYS_INLINE long hexStrToLong(const char *s) { return strtol(s,(char **)0,16); }
|
|
|
+ZT_ALWAYS_INLINE unsigned long long hexStrToU64(const char *s)
|
|
|
{
|
|
|
#ifdef __WINDOWS__
|
|
|
return (unsigned long long)_strtoui64(s,(char **)0,16);
|
|
@@ -230,7 +222,7 @@ static ZT_ALWAYS_INLINE unsigned long long hexStrToU64(const char *s)
|
|
|
return strtoull(s,(char **)0,16);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE long long hexStrTo64(const char *s)
|
|
|
+ZT_ALWAYS_INLINE long long hexStrTo64(const char *s)
|
|
|
{
|
|
|
#ifdef __WINDOWS__
|
|
|
return (long long)_strtoi64(s,(char **)0,16);
|
|
@@ -246,7 +238,7 @@ static ZT_ALWAYS_INLINE long long hexStrTo64(const char *s)
|
|
|
* @param len Length in bytes
|
|
|
* @return Non-cryptographic hash suitable for use in a hash table
|
|
|
*/
|
|
|
-static unsigned long ZT_ALWAYS_INLINE hashString(const void *restrict key,const unsigned int len)
|
|
|
+ZT_ALWAYS_INLINE unsigned long hashString(const void *restrict key,const unsigned int len)
|
|
|
{
|
|
|
const uint8_t *p = reinterpret_cast<const uint8_t *>(key);
|
|
|
unsigned long h = 0;
|
|
@@ -262,13 +254,13 @@ static unsigned long ZT_ALWAYS_INLINE hashString(const void *restrict key,const
|
|
|
}
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
-static ZT_ALWAYS_INLINE unsigned int countBits(const uint8_t v) { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned int countBits(const uint16_t v) { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned int countBits(const uint32_t v) { return (unsigned int)__builtin_popcountl((unsigned long)v); }
|
|
|
-static ZT_ALWAYS_INLINE unsigned int countBits(const uint64_t v) { return (unsigned int)__builtin_popcountll((unsigned long long)v); }
|
|
|
+ZT_ALWAYS_INLINE unsigned int countBits(const uint8_t v) { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
|
|
+ZT_ALWAYS_INLINE unsigned int countBits(const uint16_t v) { return (unsigned int)__builtin_popcount((unsigned int)v); }
|
|
|
+ZT_ALWAYS_INLINE unsigned int countBits(const uint32_t v) { return (unsigned int)__builtin_popcountl((unsigned long)v); }
|
|
|
+ZT_ALWAYS_INLINE unsigned int countBits(const uint64_t v) { return (unsigned int)__builtin_popcountll((unsigned long long)v); }
|
|
|
#else
|
|
|
template<typename T>
|
|
|
-static ZT_ALWAYS_INLINE unsigned int countBits(T v)
|
|
|
+ZT_ALWAYS_INLINE unsigned int countBits(T v)
|
|
|
{
|
|
|
v = v - ((v >> 1) & (T)~(T)0/3);
|
|
|
v = (v & (T)~(T)0/15*3) + ((v >> 2) & (T)~(T)0/15*3);
|
|
@@ -278,9 +270,9 @@ static ZT_ALWAYS_INLINE unsigned int countBits(T v)
|
|
|
#endif
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
-static ZT_ALWAYS_INLINE uint8_t hton(uint8_t n) { return n; }
|
|
|
-static ZT_ALWAYS_INLINE int8_t hton(int8_t n) { return n; }
|
|
|
-static ZT_ALWAYS_INLINE uint16_t hton(uint16_t n)
|
|
|
+ZT_ALWAYS_INLINE uint8_t hton(uint8_t n) { return n; }
|
|
|
+ZT_ALWAYS_INLINE int8_t hton(int8_t n) { return n; }
|
|
|
+ZT_ALWAYS_INLINE uint16_t hton(uint16_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -292,8 +284,8 @@ static ZT_ALWAYS_INLINE uint16_t hton(uint16_t n)
|
|
|
return htons(n);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int16_t hton(int16_t n) { return (int16_t)Utils::hton((uint16_t)n); }
|
|
|
-static ZT_ALWAYS_INLINE uint32_t hton(uint32_t n)
|
|
|
+ZT_ALWAYS_INLINE int16_t hton(int16_t n) { return (int16_t)Utils::hton((uint16_t)n); }
|
|
|
+ZT_ALWAYS_INLINE uint32_t hton(uint32_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -305,8 +297,8 @@ static ZT_ALWAYS_INLINE uint32_t hton(uint32_t n)
|
|
|
return htonl(n);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int32_t hton(int32_t n) { return (int32_t)Utils::hton((uint32_t)n); }
|
|
|
-static ZT_ALWAYS_INLINE uint64_t hton(uint64_t n)
|
|
|
+ZT_ALWAYS_INLINE int32_t hton(int32_t n) { return (int32_t)Utils::hton((uint32_t)n); }
|
|
|
+ZT_ALWAYS_INLINE uint64_t hton(uint64_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -327,16 +319,16 @@ static ZT_ALWAYS_INLINE uint64_t hton(uint64_t n)
|
|
|
);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int64_t hton(int64_t n) { return (int64_t)hton((uint64_t)n); }
|
|
|
+ZT_ALWAYS_INLINE int64_t hton(int64_t n) { return (int64_t)hton((uint64_t)n); }
|
|
|
#else
|
|
|
template<typename T>
|
|
|
static ZT_ALWAYS_INLINE T hton(T n) { return n; }
|
|
|
#endif
|
|
|
|
|
|
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
|
-static ZT_ALWAYS_INLINE uint8_t ntoh(uint8_t n) { return n; }
|
|
|
-static ZT_ALWAYS_INLINE int8_t ntoh(int8_t n) { return n; }
|
|
|
-static ZT_ALWAYS_INLINE uint16_t ntoh(uint16_t n)
|
|
|
+ZT_ALWAYS_INLINE uint8_t ntoh(uint8_t n) { return n; }
|
|
|
+ZT_ALWAYS_INLINE int8_t ntoh(int8_t n) { return n; }
|
|
|
+ZT_ALWAYS_INLINE uint16_t ntoh(uint16_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -348,8 +340,8 @@ static ZT_ALWAYS_INLINE uint16_t ntoh(uint16_t n)
|
|
|
return htons(n);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int16_t ntoh(int16_t n) { return (int16_t)Utils::ntoh((uint16_t)n); }
|
|
|
-static ZT_ALWAYS_INLINE uint32_t ntoh(uint32_t n)
|
|
|
+ZT_ALWAYS_INLINE int16_t ntoh(int16_t n) { return (int16_t)Utils::ntoh((uint16_t)n); }
|
|
|
+ZT_ALWAYS_INLINE uint32_t ntoh(uint32_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -361,8 +353,8 @@ static ZT_ALWAYS_INLINE uint32_t ntoh(uint32_t n)
|
|
|
return ntohl(n);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int32_t ntoh(int32_t n) { return (int32_t)Utils::ntoh((uint32_t)n); }
|
|
|
-static ZT_ALWAYS_INLINE uint64_t ntoh(uint64_t n)
|
|
|
+ZT_ALWAYS_INLINE int32_t ntoh(int32_t n) { return (int32_t)Utils::ntoh((uint32_t)n); }
|
|
|
+ZT_ALWAYS_INLINE uint64_t ntoh(uint64_t n)
|
|
|
{
|
|
|
#if defined(__GNUC__)
|
|
|
#if defined(__FreeBSD__)
|
|
@@ -383,13 +375,13 @@ static ZT_ALWAYS_INLINE uint64_t ntoh(uint64_t n)
|
|
|
);
|
|
|
#endif
|
|
|
}
|
|
|
-static ZT_ALWAYS_INLINE int64_t ntoh(int64_t n) { return (int64_t)ntoh((uint64_t)n); }
|
|
|
+ZT_ALWAYS_INLINE int64_t ntoh(int64_t n) { return (int64_t)ntoh((uint64_t)n); }
|
|
|
#else
|
|
|
template<typename T>
|
|
|
-static ZT_ALWAYS_INLINE T ntoh(T n) { return n; }
|
|
|
+ZT_ALWAYS_INLINE T ntoh(T n) { return n; }
|
|
|
#endif
|
|
|
|
|
|
-static ZT_ALWAYS_INLINE uint64_t readUInt64(const void *const p)
|
|
|
+ZT_ALWAYS_INLINE uint64_t readUInt64(const void *const p)
|
|
|
{
|
|
|
#ifdef ZT_NO_TYPE_PUNNING
|
|
|
const uint8_t *const b = reinterpret_cast<const uint8_t *>(p);
|
|
@@ -407,7 +399,7 @@ static ZT_ALWAYS_INLINE uint64_t readUInt64(const void *const p)
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-static ZT_ALWAYS_INLINE void putUInt64(void *const p,const uint64_t i)
|
|
|
+ZT_ALWAYS_INLINE void putUInt64(void *const p,const uint64_t i)
|
|
|
{
|
|
|
#ifdef ZT_NO_TYPE_PUNNING
|
|
|
uint8_t *const b = reinterpret_cast<uint8_t *>(p);
|