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

This commit is contained in:
yihaoDeng 2021-06-10 05:40:57 +08:00
parent 01f52f01fa
commit ad78a984e8
3 changed files with 24 additions and 22 deletions

View File

@ -27,6 +27,13 @@ extern "C" {
#define TSDB_PATTERN_NOWILDCARDMATCH 2
#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 { '%', '_' }
typedef struct SPatternCompareInfo {

View File

@ -90,13 +90,10 @@ int32_t compareFloatVal(const void *pLeft, const void *pRight) {
if (isnan(p2)) {
return 1;
}
float ret = p1 - p2;
if (fabs(ret) < FLT_EPSILON) {
if (FLT_EQUAL(p1, p2)) {
return 0;
} else {
return ret > 0? 1 : -1;
}
}
return FLT_GREATER(p1, p2) ? 1: -1;
}
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)) {
return 1;
}
double ret = p1 - p2;
if (fabs(ret) < FLT_EPSILON) {
if (FLT_EQUAL(p1, p2)) {
return 0;
} else {
return ret > 0? 1 : -1;
}
}
return FLT_GREATER(p1, p2) ? 1: -1;
}
int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) {

View File

@ -26,8 +26,7 @@
(h) *= 0x85ebca6b; \
(h) ^= (h) >> 13; \
(h) *= 0xc2b2ae35; \
(h) ^= (h) >> 16; \
} while (0)
(h) ^= (h) >> 16; } while (0)
uint32_t MurmurHash3_32(const char *key, uint32_t len) {
const uint8_t *data = (const uint8_t *)key;
@ -84,22 +83,24 @@ uint32_t taosFloatHash(const char *key, uint32_t UNUSED_PARAM(len)) {
if (isnan(f)) {
return 0x7fc00000;
}
if (fabs(f - 0.0) < FLT_EPSILON) {
if (FLT_EQUAL(f, 0.0)) {
return 0;
}
return *(uint32_t *)(key);
}
int t = (int)round(f);
return (uint32_t)t;
}
uint32_t taosDoubleHash(const char *key, uint32_t UNUSED_PARAM(len)) {
double f = GET_DOUBLE_VAL(key);
if (isnan(f)) {
return 0x7fc00000;
}
if (fabs(f - 0.0) < FLT_EPSILON) {
if (FLT_EQUAL(f, 0.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)) {
uint64_t val = *(uint64_t *)key;