提交 ad78a984 编写于 作者: Y yihaoDeng

[TD-4614]<feature> add equal func to hashTable

上级 01f52f01
...@@ -27,6 +27,13 @@ extern "C" { ...@@ -27,6 +27,13 @@ extern "C" {
#define TSDB_PATTERN_NOWILDCARDMATCH 2 #define TSDB_PATTERN_NOWILDCARDMATCH 2
#define TSDB_PATTERN_STRING_MAX_LEN 20 #define TSDB_PATTERN_STRING_MAX_LEN 20
#define FLT_COMPAR_TOL_FACTOR 4
#define FLT_EQUAL(_x, _y) (fabs((_x) - (_y)) <= (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON))
#define FLT_GREATER(_x, _y) (!FLT_EQUAL((_x), (_y)) && ((_x) > (_y)))
#define FLT_LESS(_x, _y) (!FLT_EQUAL((_x), (_y)) && ((_x) < (_y)))
#define FLT_GREATEREQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) > (_y)))
#define FLT_LESSEQUAL(_x, _y) (FLT_EQUAL((_x), (_y)) || ((_x) < (_y)))
#define PATTERN_COMPARE_INFO_INITIALIZER { '%', '_' } #define PATTERN_COMPARE_INFO_INITIALIZER { '%', '_' }
typedef struct SPatternCompareInfo { typedef struct SPatternCompareInfo {
......
...@@ -90,13 +90,10 @@ int32_t compareFloatVal(const void *pLeft, const void *pRight) { ...@@ -90,13 +90,10 @@ int32_t compareFloatVal(const void *pLeft, const void *pRight) {
if (isnan(p2)) { if (isnan(p2)) {
return 1; return 1;
} }
if (FLT_EQUAL(p1, p2)) {
float ret = p1 - p2;
if (fabs(ret) < FLT_EPSILON) {
return 0; return 0;
} else {
return ret > 0? 1 : -1;
} }
return FLT_GREATER(p1, p2) ? 1: -1;
} }
int32_t compareDoubleVal(const void *pLeft, const void *pRight) { int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
...@@ -114,13 +111,10 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) { ...@@ -114,13 +111,10 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) {
if (isnan(p2)) { if (isnan(p2)) {
return 1; return 1;
} }
if (FLT_EQUAL(p1, p2)) {
double ret = p1 - p2;
if (fabs(ret) < FLT_EPSILON) {
return 0; return 0;
} else {
return ret > 0? 1 : -1;
} }
return FLT_GREATER(p1, p2) ? 1: -1;
} }
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {
......
...@@ -26,8 +26,7 @@ ...@@ -26,8 +26,7 @@
(h) *= 0x85ebca6b; \ (h) *= 0x85ebca6b; \
(h) ^= (h) >> 13; \ (h) ^= (h) >> 13; \
(h) *= 0xc2b2ae35; \ (h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; \ (h) ^= (h) >> 16; } while (0)
} while (0)
uint32_t MurmurHash3_32(const char *key, uint32_t len) { uint32_t MurmurHash3_32(const char *key, uint32_t len) {
const uint8_t *data = (const uint8_t *)key; const uint8_t *data = (const uint8_t *)key;
...@@ -84,22 +83,24 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) { ...@@ -84,22 +83,24 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (isnan(f)) { if (isnan(f)) {
return 0x7fc00000; return 0x7fc00000;
} }
if (fabs(f - 0.0) < FLT_EPSILON) {
if (FLT_EQUAL(f, 0.0)) {
return 0; return 0;
} }
int t = (int)round(f);
return *(uint32_t *)(key); return (uint32_t)t;
} }
uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) { uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
double f = GET_DOUBLE_VAL(key); double f = GET_DOUBLE_VAL(key);
if (isnan(f)) { if (isnan(f)) {
return 0x7fc00000; return 0x7fc00000;
} }
if (fabs(f - 0.0) < FLT_EPSILON) {
if (FLT_EQUAL(f, 0.0)) {
return 0; return 0;
} }
return *(uint32_t *)(key); int t = (int)(round(f));
return (uint32_t)t;
} }
uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) { uint32_t taosIntHash_64(const char *key, uint32_t UNUSED_PARAM(len)) {
uint64_t val = *(uint64_t *)key; uint64_t val = *(uint64_t *)key;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册