tarray.h 2.1 KB
Newer Older
H
more  
hzcheng 已提交
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/*
 * 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 TDENGINE_TAOSARRAY_H
#define TDENGINE_TAOSARRAY_H

#ifdef __cplusplus
extern "C" {
#endif

#include "os.h"

#define TARRAY_MIN_SIZE 8
#define TARRAY_GET_ELEM(array, index) ((array)->pData + (index) * (array)->elemSize)

typedef struct SArray {
  size_t size;
  size_t capacity;
  size_t elemSize;

  void* pData;
} SArray;

/**
 *
 * @param size
 * @param elemSize
 * @return
 */
void* taosArrayInit(size_t size, size_t elemSize);

/**
 *
 * @param pArray
 * @param pData
 * @return
 */
void* taosArrayPush(SArray* pArray, void* pData);

/**
 *
 * @param pArray
 */
void taosArrayPop(SArray* pArray);

/**
H
hjxilinx 已提交
59
 * get the data from array
H
more  
hzcheng 已提交
60 61 62 63 64 65 66
 * @param pArray
 * @param index
 * @return
 */
void* taosArrayGet(SArray* pArray, size_t index);

/**
H
hjxilinx 已提交
67 68 69 70 71 72 73 74 75
 * get the pointer data from the array
 * @param pArray
 * @param index
 * @return
 */
void* taosArrayGetP(SArray* pArray, size_t index);

/**
 * return the size of array
H
more  
hzcheng 已提交
76 77 78
 * @param pArray
 * @return
 */
H
hjxilinx 已提交
79
size_t taosArrayGetSize(const SArray* pArray);
H
more  
hzcheng 已提交
80 81

/**
H
hjxilinx 已提交
82
 * insert data into array
H
more  
hzcheng 已提交
83 84 85 86
 * @param pArray
 * @param index
 * @param pData
 */
H
hjxilinx 已提交
87
void* taosArrayInsert(SArray* pArray, size_t index, void* pData);
H
more  
hzcheng 已提交
88 89

/**
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
 * remove data entry of the given index
 * @param pArray
 * @param index
 */
void taosArrayRemove(SArray* pArray, size_t index);

/**
 * copy the whole array from source to destination
 * @param pDst
 * @param pSrc
 */
void taosArrayCopy(SArray* pDst, SArray* pSrc);

/**
 * destroy array list
H
more  
hzcheng 已提交
105 106
 * @param pArray
 */
H
hjxilinx 已提交
107
void taosArrayDestroy(SArray* pArray);
H
more  
hzcheng 已提交
108 109 110 111 112 113

#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_TAOSARRAY_H