diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/indexCache.h similarity index 96% rename from source/libs/index/inc/index_cache.h rename to source/libs/index/inc/indexCache.h index 086e75d99f..3ea986ad48 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/indexCache.h @@ -1,6 +1,5 @@ /* - * Copyright (c) 2019 TAOS Data, Inc. - * + * Copyright (c) 2019 TAOS Data, Inc. * * 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. @@ -16,7 +15,7 @@ #define __INDEX_CACHE_H__ #include "indexInt.h" -#include "index_util.h" +#include "indexUtil.h" #include "tskiplist.h" // ----------------- key structure in skiplist --------------------- diff --git a/source/libs/index/inc/index_comm.h b/source/libs/index/inc/indexComm.h similarity index 100% rename from source/libs/index/inc/index_comm.h rename to source/libs/index/inc/indexComm.h diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/indexFst.h similarity index 98% rename from source/libs/index/inc/index_fst.h rename to source/libs/index/inc/indexFst.h index b131aa0d9d..39ad5ffa8c 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/indexFst.h @@ -20,12 +20,12 @@ extern "C" { #endif +#include "indexFstAutomation.h" +#include "indexFstCountingWriter.h" +#include "indexFstNode.h" +#include "indexFstRegistry.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_automation.h" -#include "index_fst_counting_writer.h" -#include "index_fst_node.h" -#include "index_fst_registry.h" -#include "index_fst_util.h" #define OUTPUT_PREFIX(a, b) ((a) > (b) ? (b) : (a) diff --git a/source/libs/index/inc/index_fst_automation.h b/source/libs/index/inc/indexFstAutomation.h similarity index 98% rename from source/libs/index/inc/index_fst_automation.h rename to source/libs/index/inc/indexFstAutomation.h index 786d3eb7d2..3a0f74ee76 100644 --- a/source/libs/index/inc/index_fst_automation.h +++ b/source/libs/index/inc/indexFstAutomation.h @@ -19,8 +19,8 @@ extern "C" { #endif +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_util.h" typedef struct AutomationCtx AutomationCtx; diff --git a/source/libs/index/inc/index_fst_common.h b/source/libs/index/inc/indexFstCommon.h similarity index 100% rename from source/libs/index/inc/index_fst_common.h rename to source/libs/index/inc/indexFstCommon.h diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/indexFstCountingWriter.h similarity index 100% rename from source/libs/index/inc/index_fst_counting_writer.h rename to source/libs/index/inc/indexFstCountingWriter.h diff --git a/source/libs/index/inc/index_fst_node.h b/source/libs/index/inc/indexFstNode.h similarity index 96% rename from source/libs/index/inc/index_fst_node.h rename to source/libs/index/inc/indexFstNode.h index 4dbf4cea04..4bbc739c73 100644 --- a/source/libs/index/inc/index_fst_node.h +++ b/source/libs/index/inc/indexFstNode.h @@ -20,9 +20,9 @@ extern "C" { #endif +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" #define FST_BUILDER_NODE_IS_FINAL(bn) (bn->isFinal) #define FST_BUILDER_NODE_TRANS_ISEMPTY(bn) (taosArrayGetSize(bn->trans) == 0) diff --git a/source/libs/index/inc/index_fst_registry.h b/source/libs/index/inc/indexFstRegistry.h similarity index 97% rename from source/libs/index/inc/index_fst_registry.h rename to source/libs/index/inc/indexFstRegistry.h index 20b70e2866..09cde6c131 100644 --- a/source/libs/index/inc/index_fst_registry.h +++ b/source/libs/index/inc/indexFstRegistry.h @@ -19,9 +19,9 @@ extern "C" { #endif +#include "indexFstNode.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_node.h" -#include "index_fst_util.h" typedef struct FstRegistryCell { CompiledAddr addr; diff --git a/source/libs/index/inc/index_fst_util.h b/source/libs/index/inc/indexFstUtil.h similarity index 99% rename from source/libs/index/inc/index_fst_util.h rename to source/libs/index/inc/indexFstUtil.h index f173dd9a15..d0bbc923d1 100644 --- a/source/libs/index/inc/index_fst_util.h +++ b/source/libs/index/inc/indexFstUtil.h @@ -20,8 +20,8 @@ extern "C" { #endif +#include "indexFstCommon.h" #include "indexInt.h" -#include "index_fst_common.h" typedef uint64_t FstType; typedef uint64_t CompiledAddr; diff --git a/source/libs/index/inc/indexSparse.h b/source/libs/index/inc/indexSparse.h new file mode 100644 index 0000000000..8035f6e08d --- /dev/null +++ b/source/libs/index/inc/indexSparse.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#ifndef _TD_INDEX_SPARSE_H_ +#define _TD_INDEX_SPARSE_H_ + +#include "tarray.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct FstSparseSet { + SArray *dense; + SArray *sparse; + int32_t size; +} FstSparseSet; + +FstSparseSet *sparSetCreate(int32_t sz); +void sparSetDestroy(FstSparseSet *s); +uint32_t sparSetLen(FstSparseSet *ss); +uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip); +uint32_t sparSetGet(FstSparseSet *ss, uint32_t i); +bool sparSetContains(FstSparseSet *ss, uint32_t ip); +void sparSetClear(FstSparseSet *ss); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/libs/index/inc/index_tfile.h b/source/libs/index/inc/indexTfile.h similarity index 97% rename from source/libs/index/inc/index_tfile.h rename to source/libs/index/inc/indexTfile.h index 3794898d3a..9712e4b30f 100644 --- a/source/libs/index/inc/index_tfile.h +++ b/source/libs/index/inc/indexTfile.h @@ -15,11 +15,11 @@ #ifndef __INDEX_TFILE_H__ #define __INDEX_TFILE_H__ +#include "indexFst.h" +#include "indexFstCountingWriter.h" #include "indexInt.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tlockfree.h" #ifdef __cplusplus diff --git a/source/libs/index/inc/index_util.h b/source/libs/index/inc/indexUtil.h similarity index 100% rename from source/libs/index/inc/index_util.h rename to source/libs/index/inc/indexUtil.h diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 61dd952381..d3ca3a1acf 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -14,11 +14,11 @@ */ #include "index.h" +#include "indexCache.h" +#include "indexComm.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_comm.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tdef.h" #include "tsched.h" @@ -236,11 +236,11 @@ int indexDelete(SIndex* index, SIndexMultiTermQuery* query) { return 1; } -int indexRebuild(SIndex* index, SIndexOpts* opts){ +int indexRebuild(SIndex* index, SIndexOpts* opts) { #ifdef USE_INVERTED_INDEX #endif - return 0; + return 0; } SIndexOpts* indexOptsCreate() { diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/indexCache.c similarity index 99% rename from source/libs/index/src/index_cache.c rename to source/libs/index/src/indexCache.c index bf907726bc..ca26cf38e5 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/indexCache.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include "index_cache.h" -#include "index_comm.h" -#include "index_util.h" +#include "indexCache.h" +#include "indexComm.h" +#include "indexUtil.h" #include "tcompare.h" #include "tsched.h" diff --git a/source/libs/index/src/index_comm.c b/source/libs/index/src/indexComm.c similarity index 100% rename from source/libs/index/src/index_comm.c rename to source/libs/index/src/indexComm.c diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/indexFst.c similarity index 99% rename from source/libs/index/src/index_fst.c rename to source/libs/index/src/indexFst.c index eaefaca887..24bc7a93a2 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/indexFst.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ -#include "index_fst.h" +#include "indexFst.h" +#include "indexFstAutomation.h" #include "indexInt.h" -#include "index_fst_automation.h" #include "tchecksum.h" #include "tcoding.h" diff --git a/source/libs/index/src/index_fst_automation.c b/source/libs/index/src/indexFstAutomation.c similarity index 99% rename from source/libs/index/src/index_fst_automation.c rename to source/libs/index/src/indexFstAutomation.c index 20e981559d..0702e3b94e 100644 --- a/source/libs/index/src/index_fst_automation.c +++ b/source/libs/index/src/indexFstAutomation.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "index_fst_automation.h" +#include "indexFstAutomation.h" StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueType ty, void* val) { StartWithStateValue* sv = taosMemoryCalloc(1, sizeof(StartWithStateValue)); diff --git a/source/libs/index/src/index_fst_common.c b/source/libs/index/src/indexFstCommon.c similarity index 74% rename from source/libs/index/src/index_fst_common.c rename to source/libs/index/src/indexFstCommon.c index 2d7586e8d9..e2544c7ac3 100644 --- a/source/libs/index/src/index_fst_common.c +++ b/source/libs/index/src/indexFstCommon.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_common.h" +#include "indexFstCommon.h" const uint8_t COMMON_INPUTS[] = { 84, // '\x00' @@ -274,20 +274,23 @@ const uint8_t COMMON_INPUTS[] = { }; const char COMMON_INPUTS_INV[] = { - 't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h', 'l', 'm', - '-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3', 'y', '5', '&', '_', - '4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x', 'C', 'D', 'A', 'S', 'F', 'I', - 'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N', 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', - 'U', 'V', ',', 'Y', 'K', 'J', 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', - '!', '\'', '*', '@', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', - '\x0c', '\r', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', - '\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|', '}', '\x7f', - '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', '\x8c', '\x8d', '\x8e', '\x8f', - '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', - '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7', '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', - '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', - '\xc0', '\xc1', '\xc2', '\xc3', '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', - '\xd0', '\xd1', '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf', - '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', '\xee', '\xef', - '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', '\xfc', '\xfd', '\xfe', '\xff', + 't', 'e', '/', 'o', 'a', 's', 'r', 'i', 'p', 'c', 'n', 'w', '.', 'h', + 'l', 'm', '-', 'd', 'u', '0', '1', '2', 'g', '=', ':', 'b', 'f', '3', + 'y', '5', '&', '_', '4', 'v', '9', '6', '7', '8', 'k', '%', '?', 'x', + 'C', 'D', 'A', 'S', 'F', 'I', 'B', 'E', 'j', 'P', 'T', 'z', 'R', 'N', + 'M', '+', 'L', 'O', 'q', 'H', 'G', 'W', 'U', 'V', ',', 'Y', 'K', 'J', + 'Z', 'X', 'Q', ';', ')', '(', '~', '[', ']', '$', '!', '\'', '*', '@', + '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\t', '\n', '\x0b', '\x0c', '\r', + '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1a', '\x1b', + '\x1c', '\x1d', '\x1e', '\x1f', ' ', '"', '#', '<', '>', '\\', '^', '`', '{', '|', + '}', '\x7f', '\x80', '\x81', '\x82', '\x83', '\x84', '\x85', '\x86', '\x87', '\x88', '\x89', '\x8a', '\x8b', + '\x8c', '\x8d', '\x8e', '\x8f', '\x90', '\x91', '\x92', '\x93', '\x94', '\x95', '\x96', '\x97', '\x98', '\x99', + '\x9a', '\x9b', '\x9c', '\x9d', '\x9e', '\x9f', '\xa0', '\xa1', '\xa2', '\xa3', '\xa4', '\xa5', '\xa6', '\xa7', + '\xa8', '\xa9', '\xaa', '\xab', '\xac', '\xad', '\xae', '\xaf', '\xb0', '\xb1', '\xb2', '\xb3', '\xb4', '\xb5', + '\xb6', '\xb7', '\xb8', '\xb9', '\xba', '\xbb', '\xbc', '\xbd', '\xbe', '\xbf', '\xc0', '\xc1', '\xc2', '\xc3', + '\xc4', '\xc5', '\xc6', '\xc7', '\xc8', '\xc9', '\xca', '\xcb', '\xcc', '\xcd', '\xce', '\xcf', '\xd0', '\xd1', + '\xd2', '\xd3', '\xd4', '\xd5', '\xd6', '\xd7', '\xd8', '\xd9', '\xda', '\xdb', '\xdc', '\xdd', '\xde', '\xdf', + '\xe0', '\xe1', '\xe2', '\xe3', '\xe4', '\xe5', '\xe6', '\xe7', '\xe8', '\xe9', '\xea', '\xeb', '\xec', '\xed', + '\xee', '\xef', '\xf0', '\xf1', '\xf2', '\xf3', '\xf4', '\xf5', '\xf6', '\xf7', '\xf8', '\xf9', '\xfa', '\xfb', + '\xfc', '\xfd', '\xfe', '\xff', }; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/indexFstCountingWriter.c similarity index 94% rename from source/libs/index/src/index_fst_counting_writer.c rename to source/libs/index/src/indexFstCountingWriter.c index 6a161ba7e9..76ff4309b5 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/indexFstCountingWriter.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ -#include "os.h" -#include "index_fst_counting_writer.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_fst_util.h" +#include "os.h" #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { @@ -82,7 +82,9 @@ static int writeCtxDoFlush(WriterCtx* ctx) { WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int32_t capacity) { WriterCtx* ctx = taosMemoryCalloc(1, sizeof(WriterCtx)); - if (ctx == NULL) { return NULL; } + if (ctx == NULL) { + return NULL; + } ctx->type = type; if (ctx->type == TFile) { @@ -126,7 +128,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int return ctx; END: - if (ctx->type == TMemory) { taosMemoryFree(ctx->mem.buf); } + if (ctx->type == TMemory) { + taosMemoryFree(ctx->mem.buf); + } taosMemoryFree(ctx); return NULL; } @@ -148,14 +152,18 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { // stat(ctx->file.buf, &fstat); // indexError("write file size: %d", (int)(fstat.st_size)); } - if (remove) { unlink(ctx->file.buf); } + if (remove) { + unlink(ctx->file.buf); + } } taosMemoryFree(ctx); } FstCountingWriter* fstCountingWriterCreate(void* wrt) { FstCountingWriter* cw = taosMemoryCalloc(1, sizeof(FstCountingWriter)); - if (cw == NULL) { return NULL; } + if (cw == NULL) { + return NULL; + } cw->wrt = wrt; //(void *)(writerCtxCreate(TFile, readOnly)); @@ -169,7 +177,9 @@ void fstCountingWriterDestroy(FstCountingWriter* cw) { } int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) { - if (write == NULL) { return 0; } + if (write == NULL) { + return 0; + } // update checksum // write data to file/socket or mem WriterCtx* ctx = write->wrt; @@ -182,7 +192,9 @@ int fstCountingWriterWrite(FstCountingWriter* write, uint8_t* buf, uint32_t len) return len; } int fstCountingWriterRead(FstCountingWriter* write, uint8_t* buf, uint32_t len) { - if (write == NULL) { return 0; } + if (write == NULL) { + return 0; + } WriterCtx* ctx = write->wrt; int nRead = ctx->read(ctx, buf, len); // assert(nRead == len); diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/indexFstNode.c similarity index 89% rename from source/libs/index/src/index_fst_node.c rename to source/libs/index/src/indexFstNode.c index a0d59150d7..e11f9dd37d 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/indexFstNode.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_node.h" +#include "indexFstNode.h" FstBuilderNode* fstBuilderNodeDefault() { FstBuilderNode* bn = taosMemoryMalloc(sizeof(FstBuilderNode)); @@ -22,31 +22,45 @@ FstBuilderNode* fstBuilderNodeDefault() { return bn; } void fstBuilderNodeDestroy(FstBuilderNode* node) { - if (node == NULL) { return; } + if (node == NULL) { + return; + } taosArrayDestroy(node->trans); taosMemoryFree(node); } bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) { - if (n1 == n2) { return true; } - if (n1 == NULL || n2 == NULL) { return false; } + if (n1 == n2) { + return true; + } + if (n1 == NULL || n2 == NULL) { + return false; + } - if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) { return false; } + if (n1->isFinal != n2->isFinal || n1->finalOutput != n2->finalOutput) { + return false; + } size_t s1 = n1->trans ? taosArrayGetSize(n1->trans) : 0; size_t s2 = n2->trans ? taosArrayGetSize(n2->trans) : 0; - if (s1 != s2) { return false; } + if (s1 != s2) { + return false; + } for (size_t i = 0; i < s1; i++) { FstTransition* t1 = taosArrayGet(n1->trans, i); FstTransition* t2 = taosArrayGet(n2->trans, i); - if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) { return false; } + if (t1->inp != t2->inp || t1->out != t2->out || t1->addr != t2->addr) { + return false; + } } return true; } FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); - if (node == NULL) { return NULL; } + if (node == NULL) { + return NULL; + } // size_t sz = taosArrayGetSize(src->trans); @@ -64,7 +78,9 @@ FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) { } // not destroy src, User's bussiness void fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { - if (dst == NULL || src == NULL) { return; } + if (dst == NULL || src == NULL) { + return; + } dst->isFinal = src->isFinal; dst->finalOutput = src->finalOutput; diff --git a/source/libs/index/src/index_fst_registry.c b/source/libs/index/src/indexFstRegister.c similarity index 93% rename from source/libs/index/src/index_fst_registry.c rename to source/libs/index/src/indexFstRegister.c index 7b6b8df25f..34efee0d0d 100644 --- a/source/libs/index/src/index_fst_registry.c +++ b/source/libs/index/src/indexFstRegister.c @@ -13,8 +13,8 @@ * along with this program. If not, see . */ +#include "indexFstRegistry.h" #include "os.h" -#include "index_fst_registry.h" uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { // TODO(yihaoDeng): refactor later @@ -35,7 +35,9 @@ uint64_t fstRegistryHash(FstRegistry* registry, FstBuilderNode* bNode) { } static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { size_t sz = taosArrayGetSize(arr); - if (a >= sz || b >= sz) { return; } + if (a >= sz || b >= sz) { + return; + } FstRegistryCell* cell1 = (FstRegistryCell*)taosArrayGet(arr, a); FstRegistryCell* cell2 = (FstRegistryCell*)taosArrayGet(arr, b); @@ -52,7 +54,9 @@ static void fstRegistryCellSwap(SArray* arr, uint32_t a, uint32_t b) { static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { size_t sz = taosArrayGetSize(arr); - if (start >= sz && end >= sz) { return; } + if (start >= sz && end >= sz) { + return; + } assert(start >= end); @@ -66,7 +70,9 @@ static void fstRegistryCellPromote(SArray* arr, uint32_t start, uint32_t end) { FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { FstRegistry* registry = taosMemoryMalloc(sizeof(FstRegistry)); - if (registry == NULL) { return NULL; } + if (registry == NULL) { + return NULL; + } uint64_t nCells = tableSize * mruSize; SArray* tb = (SArray*)taosArrayInit(nCells, sizeof(FstRegistryCell)); @@ -87,7 +93,9 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { } void fstRegistryDestroy(FstRegistry* registry) { - if (registry == NULL) { return; } + if (registry == NULL) { + return; + } SArray* tb = registry->table; size_t sz = taosArrayGetSize(tb); @@ -100,7 +108,9 @@ void fstRegistryDestroy(FstRegistry* registry) { } FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNode) { - if (taosArrayGetSize(registry->table) <= 0) { return NULL; } + if (taosArrayGetSize(registry->table) <= 0) { + return NULL; + } uint64_t bucket = fstRegistryHash(registry, bNode); uint64_t start = registry->mruSize * bucket; uint64_t end = start + registry->mruSize; @@ -165,6 +175,4 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo } return entry; } -void fstRegistryEntryDestroy(FstRegistryEntry* entry) { - taosMemoryFree(entry); -} +void fstRegistryEntryDestroy(FstRegistryEntry* entry) { taosMemoryFree(entry); } diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/indexFstUtil.c similarity index 98% rename from source/libs/index/src/index_fst_util.c rename to source/libs/index/src/indexFstUtil.c index f9581f7202..ec9a6943dc 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/indexFstUtil.c @@ -12,8 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_fst_util.h" -#include "index_fst_common.h" +#include "indexFstUtil.h" +#include "indexFstCommon.h" // A sentinel value used to indicate an empty final state const CompiledAddr EMPTY_ADDRESS = 0; diff --git a/source/libs/index/src/index_json.c b/source/libs/index/src/indexJson.c similarity index 100% rename from source/libs/index/src/index_json.c rename to source/libs/index/src/indexJson.c diff --git a/source/libs/index/src/indexSparse.c b/source/libs/index/src/indexSparse.c new file mode 100644 index 0000000000..8bcf04602f --- /dev/null +++ b/source/libs/index/src/indexSparse.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * 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 . + */ + +#include "indexSparse.h" + +FstSparseSet *sparSetCreate(int32_t sz) { + FstSparseSet *ss = taosMemoryCalloc(1, sizeof(FstSparseSet)); + if (ss = NULL) { + return NULL; + } + + ss->dense = taosArrayInit(sz, sizeof(uint32_t)); + ss->sparse = taosArrayInit(sz, sizeof(uint32_t)); + ss->size = sz; + return ss; +} +void sparSetDestroy(FstSparseSet *ss) { + if (ss == NULL) { + return; + } + taosArrayDestroy(ss->dense); + taosArrayDestroy(ss->sparse); + taosMemoryFree(ss); +} +uint32_t sparSetLen(FstSparseSet *ss) { return ss == NULL ? 0 : ss->size; } +uint32_t sparSetAdd(FstSparseSet *ss, uint32_t ip) { + if (ss == NULL) { + return 0; + } + uint32_t i = ss->size; + taosArraySet(ss->dense, i, &ip); + taosArraySet(ss->sparse, ip, &i); + ss->size += 1; + return i; +} +uint32_t sparSetGet(FstSparseSet *ss, uint32_t i) { + if (i >= taosArrayGetSize(ss->dense)) { + return 0; + } + uint32_t *v = taosArrayGet(ss->dense, i); + return *v; +} +bool sparSetContains(FstSparseSet *ss, uint32_t ip) { + if (ip >= taosArrayGetSize(ss->sparse)) { + return false; + } + uint32_t i = *(uint32_t *)taosArrayGet(ss->sparse, ip); + if (i >= taosArrayGetSize(ss->dense)) { + return false; + } + uint32_t v = *(uint32_t *)taosArrayGet(ss->dense, i); + return v == ip; +} +void sparSetClear(FstSparseSet *ss) { + if (ss == NULL) { + return; + } + ss->size = 0; +} diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/indexTfile.c similarity index 99% rename from source/libs/index/src/index_tfile.c rename to source/libs/index/src/indexTfile.c index 53813e13e6..058c33b725 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/indexTfile.c @@ -13,12 +13,12 @@ p * * along with this program. If not, see . */ -#include "index_tfile.h" +#include "indexTfile.h" #include "index.h" -#include "index_comm.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_util.h" +#include "indexComm.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexUtil.h" #include "taosdef.h" #include "tcoding.h" #include "tcompare.h" diff --git a/source/libs/index/src/index_util.c b/source/libs/index/src/indexUtil.c similarity index 99% rename from source/libs/index/src/index_util.c rename to source/libs/index/src/indexUtil.c index 65c16ca65b..7b83cf465d 100644 --- a/source/libs/index/src/index_util.c +++ b/source/libs/index/src/indexUtil.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "index_util.h" +#include "indexUtil.h" #include "index.h" #include "tcompare.h" diff --git a/source/libs/index/test/fstTest.cc b/source/libs/index/test/fstTest.cc index e0b12a6f33..eff53108cd 100644 --- a/source/libs/index/test/fstTest.cc +++ b/source/libs/index/test/fstTest.cc @@ -5,12 +5,12 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" +#include "indexTfile.h" #include "tskiplist.h" #include "tutil.h" void* callback(void* s) { return s; } diff --git a/source/libs/index/test/fstUT.cc b/source/libs/index/test/fstUT.cc index e7efbaf21f..ab6c1a4704 100644 --- a/source/libs/index/test/fstUT.cc +++ b/source/libs/index/test/fstUT.cc @@ -6,12 +6,12 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" +#include "indexTfile.h" #include "tglobal.h" #include "tlog.h" #include "tskiplist.h" diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 0e4eb060cf..ee9da50ab2 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -18,13 +18,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tskiplist.h" #include "tutil.h" using namespace std; diff --git a/source/libs/index/test/jsonUT.cc b/source/libs/index/test/jsonUT.cc index df9f8b8439..9b0452425a 100644 --- a/source/libs/index/test/jsonUT.cc +++ b/source/libs/index/test/jsonUT.cc @@ -5,13 +5,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tglobal.h" #include "tskiplist.h" #include "tutil.h" diff --git a/source/libs/index/test/utilUT.cc b/source/libs/index/test/utilUT.cc index 6ba8cc9525..30f1a089f7 100644 --- a/source/libs/index/test/utilUT.cc +++ b/source/libs/index/test/utilUT.cc @@ -5,13 +5,13 @@ #include #include #include "index.h" +#include "indexCache.h" +#include "indexFst.h" +#include "indexFstCountingWriter.h" +#include "indexFstUtil.h" #include "indexInt.h" -#include "index_cache.h" -#include "index_fst.h" -#include "index_fst_counting_writer.h" -#include "index_fst_util.h" -#include "index_tfile.h" -#include "index_util.h" +#include "indexTfile.h" +#include "indexUtil.h" #include "tglobal.h" #include "tskiplist.h" #include "tutil.h"