提交 3bb98e1a 编写于 作者: A AlexDuan

add arg avoid modify man call

上级 fcc3cc8e
...@@ -67,7 +67,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto); ...@@ -67,7 +67,7 @@ void tHistogramDestroy(SHistogramInfo** pHisto);
void tHistogramPrint(SHistogramInfo* pHisto); void tHistogramPrint(SHistogramInfo* pHisto);
int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val); int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val, int32_t maxEntries);
SHeapEntry* tHeapCreate(int32_t numOfEntries); SHeapEntry* tHeapCreate(int32_t numOfEntries);
void tHeapSort(SHeapEntry* pEntry, int32_t len); void tHeapSort(SHeapEntry* pEntry, int32_t len);
......
...@@ -161,8 +161,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) { ...@@ -161,8 +161,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
} }
#if defined(USE_ARRAYLIST) #if defined(USE_ARRAYLIST)
int32_t idx = histoBinarySearch((*pHisto)->elems, (*pHisto)->numOfEntries, val); int32_t idx = histoBinarySearch((*pHisto)->elems, (*pHisto)->numOfEntries, val, (*pHisto)->maxEntries);
if(idx >= (*pHisto)->maxEntries) idx = (*pHisto)->maxEntries - 1;
assert(idx >= 0 && idx < (*pHisto)->maxEntries && (*pHisto)->elems != NULL); assert(idx >= 0 && idx < (*pHisto)->maxEntries && (*pHisto)->elems != NULL);
if ((*pHisto)->elems[idx].val == val && idx >= 0) { if ((*pHisto)->elems[idx].val == val && idx >= 0) {
...@@ -360,7 +359,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) { ...@@ -360,7 +359,7 @@ int32_t tHistogramAdd(SHistogramInfo** pHisto, double val) {
return 0; return 0;
} }
int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val) { int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val, int32_t maxEntries) {
int32_t end = len - 1; int32_t end = len - 1;
int32_t start = 0; int32_t start = 0;
...@@ -378,6 +377,7 @@ int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val) { ...@@ -378,6 +377,7 @@ int32_t histoBinarySearch(SHistBin* pEntry, int32_t len, double val) {
} }
int32_t ret = start > end ? start : end; int32_t ret = start > end ? start : end;
if(ret >= maxEntries) ret = maxEntries - 1;
if (ret < 0) { if (ret < 0) {
return 0; return 0;
} else { } else {
...@@ -470,7 +470,7 @@ void tHistogramPrint(SHistogramInfo* pHisto) { ...@@ -470,7 +470,7 @@ void tHistogramPrint(SHistogramInfo* pHisto) {
*/ */
int64_t tHistogramSum(SHistogramInfo* pHisto, double v) { int64_t tHistogramSum(SHistogramInfo* pHisto, double v) {
#if defined(USE_ARRAYLIST) #if defined(USE_ARRAYLIST)
int32_t slotIdx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, v); int32_t slotIdx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, v, pHisto->maxEntries);
if (pHisto->elems[slotIdx].val != v) { if (pHisto->elems[slotIdx].val != v) {
slotIdx -= 1; slotIdx -= 1;
......
...@@ -98,19 +98,19 @@ TEST(testCase, histogram_binary_search) { ...@@ -98,19 +98,19 @@ TEST(testCase, histogram_binary_search) {
pHisto->elems[i].val = i; pHisto->elems[i].val = i;
} }
int32_t idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 1); int32_t idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 1, pHisto->maxEntries);
assert(idx == 1); assert(idx == 1);
idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 9); idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 9, pHisto->maxEntries);
assert(idx == 9); assert(idx == 9);
idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 20); idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 20, pHisto->maxEntries);
assert(idx == 10); assert(idx == 10);
idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, -1); idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, -1, pHisto->maxEntries);
assert(idx == 0); assert(idx == 0);
idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 3.9); idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 3.9, pHisto->maxEntries);
assert(idx == 4); assert(idx == 4);
free(pHisto); free(pHisto);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册