lhashTests.cpp 1.9 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include <gtest/gtest.h>
#include <iostream>
#include "executorimpl.h"
#include "tlinearhash.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"

TEST(testCase, linear_hash_Tests) {
wafwerar's avatar
wafwerar 已提交
28
  taosSeedRand(time(NULL));
H
Haojun Liao 已提交
29 30

  _hash_fn_t fn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT);
H
Haojun Liao 已提交
31 32 33
#if 0
  SLHashObj* pHashObj = tHashInit(256, 4096, fn, 320);
  for(int32_t i = 0; i < 5000000; ++i) {
H
Haojun Liao 已提交
34 35
    int32_t code = tHashPut(pHashObj, &i, sizeof(i), &i, sizeof(i));
    assert(code == 0);
H
Haojun Liao 已提交
36 37
  }

H
Haojun Liao 已提交
38
//  tHashPrint(pHashObj, LINEAR_HASH_STATIS);
H
Haojun Liao 已提交
39

H
Haojun Liao 已提交
40 41 42 43 44 45 46 47
//  for(int32_t i = 0; i < 10000; ++i) {
//    char* v = tHashGet(pHashObj, &i, sizeof(i));
//    if (v != NULL) {
////      printf("find value: %d, key:%d\n", *(int32_t*) v, i);
//    } else {
//      printf("failed to found key:%d in hash\n", i);
//    }
//  }
H
Haojun Liao 已提交
48

H
Haojun Liao 已提交
49
  tHashPrint(pHashObj, LINEAR_HASH_STATIS);
H
Haojun Liao 已提交
50 51 52 53 54
  tHashCleanup(pHashObj);
#endif

#if 0
  SHashObj* pHashObj = taosHashInit(1000, fn, false, HASH_NO_LOCK);
H
Haojun Liao 已提交
55
  for(int32_t i = 0; i < 1000000; ++i) {
H
Haojun Liao 已提交
56 57 58 59 60 61 62 63 64 65
    taosHashPut(pHashObj, &i, sizeof(i), &i, sizeof(i));
  }

  for(int32_t i = 0; i < 10000; ++i) {
    void* v = taosHashGet(pHashObj, &i, sizeof(i));
  }
  taosHashCleanup(pHashObj);
#endif

}