From c73dc3897e51aba3efc163f1724db61d4711c841 Mon Sep 17 00:00:00 2001 From: Alex Zolotarev Date: Mon, 7 Mar 2011 00:20:02 +0000 Subject: [PATCH] Timsort now is compilable as C++ --- coding/coding.pro | 4 ++-- coding/timsort/{timsort.c => timsort.cpp} | 13 ++++++++----- coding/timsort/timsort.h | 18 ------------------ coding/timsort/timsort.hpp | 5 +++++ std/stdlib.hpp | 12 ++++++++++++ 5 files changed, 27 insertions(+), 25 deletions(-) rename coding/timsort/{timsort.c => timsort.cpp} (99%) delete mode 100644 coding/timsort/timsort.h create mode 100644 coding/timsort/timsort.hpp create mode 100644 std/stdlib.hpp diff --git a/coding/coding.pro b/coding/coding.pro index df457d44fc..5ff0e3a9ca 100644 --- a/coding/coding.pro +++ b/coding/coding.pro @@ -16,7 +16,7 @@ SOURCES += \ file_container.cpp \ bzip2_compressor.cpp \ gzip_compressor.cpp \ - timsort/timsort.c \ + timsort/timsort.cpp \ HEADERS += \ @@ -69,4 +69,4 @@ HEADERS += \ coder_util.hpp \ bzip2_compressor.hpp \ gzip_compressor.hpp \ - timsort/timsort.h \ + timsort/timsort.hpp \ diff --git a/coding/timsort/timsort.c b/coding/timsort/timsort.cpp similarity index 99% rename from coding/timsort/timsort.c rename to coding/timsort/timsort.cpp index 06a4466003..6069d91cbf 100644 --- a/coding/timsort/timsort.c +++ b/coding/timsort/timsort.cpp @@ -1,4 +1,7 @@ -#include "timsort.h" +#include "timsort.hpp" + +#include "../../std/memcpy.hpp" +#include "../../std/stdlib.hpp" typedef int cmpFunc(const void *, const void *); @@ -676,7 +679,7 @@ static void timMergeLow(timMergeState *aState, */ timMergeGetMem(aState, aLen1); memcpy(aState->mMergeMem, sArray + aBase1 * sWidth, sWidth * aLen1); - sTmp = aState->mMergeMem; + sTmp = static_cast(aState->mMergeMem); sCursor1 = 0; sCursor2 = aBase2; @@ -896,7 +899,7 @@ static void timMergeHigh(timMergeState *aState, /* Copy second run into temp memory */ memcpy(aState->mMergeMem, sArray + aBase2 * sWidth, sWidth * aLen2); - sTmp = aState->mMergeMem; + sTmp = static_cast(aState->mMergeMem); sCursor1 = aBase1 + aLen1 - 1; sCursor2 = aLen2 - 1; @@ -1105,7 +1108,7 @@ static void timMergeAt(timMergeState *aState, uint32_t aWhere, cmpFunc *aCmpCb) * Prior elements in run1 can be ignored (because they are already in place). */ k = timGallopRight((uint8_t *)aState->mArray + sBaseB * aState->mWidth, - aState->mArray, + static_cast(aState->mArray), aState->mWidth, sBaseA, sLenA, @@ -1123,7 +1126,7 @@ static void timMergeAt(timMergeState *aState, uint32_t aWhere, cmpFunc *aCmpCb) * (because they are already in place). */ sLenB = timGallopLeft((uint8_t *)aState->mArray + (sBaseA + sLenA - 1) * aState->mWidth, - aState->mArray, + static_cast(aState->mArray), aState->mWidth, sBaseB, sLenB, diff --git a/coding/timsort/timsort.h b/coding/timsort/timsort.h deleted file mode 100644 index bd5c91b5c3..0000000000 --- a/coding/timsort/timsort.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __TIM_SORT_H__ -#define __TIM_SORT_H__ - -#ifndef _MSC_VER - #include -#else - typedef unsigned char uint8_t; - typedef __int32 int32_t; - typedef unsigned __int32 uint32_t; -#endif - -#include -#include -#include - -void timsort(void *aArray, size_t aElementCnt, size_t aWidth, int (*aCmpCb)(const void *, const void *)); - -#endif diff --git a/coding/timsort/timsort.hpp b/coding/timsort/timsort.hpp new file mode 100644 index 0000000000..87744fc566 --- /dev/null +++ b/coding/timsort/timsort.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "../../std/stdint.hpp" + +void timsort(void *aArray, size_t aElementCnt, size_t aWidth, int (*aCmpCb)(const void *, const void *)); diff --git a/std/stdlib.hpp b/std/stdlib.hpp new file mode 100644 index 0000000000..b8079a6f96 --- /dev/null +++ b/std/stdlib.hpp @@ -0,0 +1,12 @@ +#pragma once +#include "common_defines.hpp" + +#ifdef new +#undef new +#endif + +#include + +#ifdef DEBUG_NEW +#define new DEBUG_NEW +#endif