index_util.h 2.0 KB
Newer Older
dengyihao's avatar
dengyihao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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/>.
 */
#ifndef __INDEX_UTIL_H__
#define __INDEX_UTIL_H__

S
Shengliang Guan 已提交
18
#include "indexInt.h"
dengyihao's avatar
dengyihao 已提交
19

dengyihao's avatar
dengyihao 已提交
20 21 22 23
#ifdef __cplusplus
extern "C" {
#endif

dengyihao's avatar
dengyihao 已提交
24 25 26 27
#define SERIALIZE_MEM_TO_BUF(buf, key, mem)                     \
  do {                                                          \
    memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem)); \
    buf += sizeof(key->mem);                                    \
dengyihao's avatar
dengyihao 已提交
28 29 30
  } while (0)

#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \
31
  do {                                               \
dengyihao's avatar
dengyihao 已提交
32
    memcpy((void *)buf, (void *)key->mem, len);      \
33
    buf += len;                                      \
dengyihao's avatar
dengyihao 已提交
34 35
  } while (0)

dengyihao's avatar
dengyihao 已提交
36 37 38 39 40 41
#define SERIALIZE_VAR_TO_BUF(buf, var, type)    \
  do {                                          \
    type c = var;                               \
    assert(sizeof(type) == sizeof(c));          \
    memcpy((void *)buf, (void *)&c, sizeof(c)); \
    buf += sizeof(c);                           \
dengyihao's avatar
dengyihao 已提交
42 43 44
  } while (0)

#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \
45
  do {                                          \
dengyihao's avatar
dengyihao 已提交
46
    memcpy((void *)buf, (void *)var, len);      \
47
    buf += len;                                 \
dengyihao's avatar
dengyihao 已提交
48 49
  } while (0)

dengyihao's avatar
dengyihao 已提交
50 51 52 53 54 55 56
/* multi sorted result intersection
 * input: [1, 2, 4, 5]
 *        [2, 3, 4, 5]
 *        [1, 4, 5]
 * output:[4, 5]
 */
void iIntersection(SArray *interResults, SArray *finalResult);
dengyihao's avatar
dengyihao 已提交
57
void iUnion(SArray *interResults, SArray *finalResult);
dengyihao's avatar
dengyihao 已提交
58 59 60 61 62
#ifdef __cplusplus
}
#endif

#endif