This commit is contained in:
Shengliang Guan 2022-02-28 10:00:54 +08:00
parent 39bf54bba5
commit 40ba2bd866
6 changed files with 34 additions and 60 deletions

View File

@ -16,7 +16,7 @@
#ifndef _TD_UTIL_ENCODE_H_ #ifndef _TD_UTIL_ENCODE_H_
#define _TD_UTIL_ENCODE_H_ #define _TD_UTIL_ENCODE_H_
#include "freelist.h" #include "tfreelist.h"
#include "tcoding.h" #include "tcoding.h"
#include "tmacro.h" #include "tmacro.h"

View File

@ -16,7 +16,6 @@
#ifndef _TD_UTIL_FREELIST_H_ #ifndef _TD_UTIL_FREELIST_H_
#define _TD_UTIL_FREELIST_H_ #define _TD_UTIL_FREELIST_H_
#include "os.h"
#include "tlist.h" #include "tlist.h"
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -12,8 +12,10 @@
* You should have received a copy of the GNU Affero General Public License * 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/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_UTIL_LIST_H #ifndef _TD_UTIL_LIST_H_
#define _TD_UTIL_LIST_H #define _TD_UTIL_LIST_H_
#include "os.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -28,12 +30,12 @@ extern "C" {
#define TD_SLIST(TYPE) \ #define TD_SLIST(TYPE) \
struct { \ struct { \
struct TYPE *sl_head_; \ struct TYPE *sl_head_; \
int sl_neles_; \ int32_t sl_neles_; \
} }
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_) #define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_) #define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_) #define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_) #define TD_SLIST_NODE_NEXT_WITH_FIELD(sln, field) ((sln)->field.sl_next_)
#define TD_SLIST_INIT(sl) \ #define TD_SLIST_INIT(sl) \
@ -79,16 +81,16 @@ extern "C" {
struct { \ struct { \
struct TYPE *dl_head_; \ struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \ struct TYPE *dl_tail_; \
int dl_neles_; \ int32_t dl_neles_; \
} }
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_) #define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_) #define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_) #define TD_DLIST_NODE_PREV_WITH_FIELD(dln, field) ((dln)->field.dl_prev_)
#define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_) #define TD_DLIST_NODE_NEXT_WITH_FIELD(dln, field) ((dln)->field.dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_) #define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_) #define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_) #define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define TD_DLIST_INIT(dl) \ #define TD_DLIST_INIT(dl) \
do { \ do { \
@ -200,29 +202,29 @@ typedef struct SListNode {
typedef struct { typedef struct {
TD_DLIST(SListNode); TD_DLIST(SListNode);
int eleSize; int32_t eleSize;
} SList; } SList;
typedef struct { typedef struct {
SListNode * next; SListNode *next;
TD_LIST_DIRECTION_T direction; TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
#define listHead(l) TD_DLIST_HEAD(l) #define listHead(l) TD_DLIST_HEAD(l)
#define listTail(l) TD_DLIST_TAIL(l) #define listTail(l) TD_DLIST_TAIL(l)
#define listNEles(l) TD_DLIST_NELES(l) #define listNEles(l) TD_DLIST_NELES(l)
#define listEleSize(l) ((l)->eleSize) #define listEleSize(l) ((l)->eleSize)
#define isListEmpty(l) (TD_DLIST_NELES(l) == 0) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
#define listNodeFree(n) free(n) #define listNodeFree(n) free(n)
void tdListInit(SList *list, int eleSize); void tdListInit(SList *list, int32_t eleSize);
void tdListEmpty(SList *list); void tdListEmpty(SList *list);
SList * tdListNew(int eleSize); SList *tdListNew(int32_t eleSize);
void * tdListFree(SList *list); void *tdListFree(SList *list);
void tdListPrependNode(SList *list, SListNode *node); void tdListPrependNode(SList *list, SListNode *node);
void tdListAppendNode(SList *list, SListNode *node); void tdListAppendNode(SList *list, SListNode *node);
int tdListPrepend(SList *list, void *data); int32_t tdListPrepend(SList *list, void *data);
int tdListAppend(SList *list, void *data); int32_t tdListAppend(SList *list, void *data);
SListNode *tdListPopHead(SList *list); SListNode *tdListPopHead(SList *list);
SListNode *tdListPopTail(SList *list); SListNode *tdListPopTail(SList *list);
SListNode *tdListGetHead(SList *list); SListNode *tdListGetHead(SList *list);
@ -239,4 +241,4 @@ SListNode *tdListNext(SListIter *pIter);
} }
#endif #endif
#endif /*_TD_UTIL_LIST_H*/ #endif /*_TD_UTIL_LIST_H_*/

View File

@ -1,27 +0,0 @@
/*
* 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 _TD_UTIL_INT_H_
#define _TD_UTIL_INT_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_INT_H_*/

View File

@ -13,15 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#define _DEFAULT_SOURCE
#include "tlist.h" #include "tlist.h"
#include "os.h"
void tdListInit(SList *list, int eleSize) { void tdListInit(SList *list, int32_t eleSize) {
TD_DLIST_INIT(list); TD_DLIST_INIT(list);
listEleSize(list) = eleSize; listEleSize(list) = eleSize;
} }
SList *tdListNew(int eleSize) { SList *tdListNew(int32_t eleSize) {
SList *list = (SList *)malloc(sizeof(SList)); SList *list = (SList *)malloc(sizeof(SList));
if (list == NULL) return NULL; if (list == NULL) return NULL;
@ -50,7 +50,7 @@ void tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, no
void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); } void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); }
int tdListPrepend(SList *list, void *data) { int32_t tdListPrepend(SList *list, void *data) {
SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize); SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize);
if (node == NULL) return -1; if (node == NULL) return -1;
@ -60,7 +60,7 @@ int tdListPrepend(SList *list, void *data) {
return 0; return 0;
} }
int tdListAppend(SList *list, void *data) { int32_t tdListAppend(SList *list, void *data) {
SListNode *node = (SListNode *)calloc(1, sizeof(SListNode) + list->eleSize); SListNode *node = (SListNode *)calloc(1, sizeof(SListNode) + list->eleSize);
if (node == NULL) return -1; if (node == NULL) return -1;

View File

@ -1,6 +1,6 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "freelist.h" #include "tfreelist.h"
TEST(TD_UTIL_FREELIST_TEST, simple_test) { TEST(TD_UTIL_FREELIST_TEST, simple_test) {
SFreeList fl; SFreeList fl;