diff --git a/StaticMath/AllLibs/AllLibs.cpp b/StaticMath/AllLibs/AllLibs.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4107d3743a551639fc20a6f54c54a1b30f452720 --- /dev/null +++ b/StaticMath/AllLibs/AllLibs.cpp @@ -0,0 +1,70 @@ +#include +#include +#include "MathLibrary.h" +#include +#include "../DynamicLib/DynMerg.h" + +int main() +{ + int n = 0; + while ((n <= 0) || (n >= 10)) + { + printf("input length of array\n"); + scanf_s("%d", &n); + } + srand(time(nullptr)); + printf("first array\n"); + printf("\n"); + int *a = new int[n]; + for (int i = 0; i < n; i++) + a[i] = rand() % 20 - 10; + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + merge(a, n); + printf("array sorted with static lib\n"); + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + printf("\n"); + printf("second array\n"); + printf("\n"); + for (int i = 0; i < n; i++) + a[i] = rand() % 20 - 10; + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + + typedef int (CALLBACK* DLLFUNC) (int*, int); + HINSTANCE load; + DLLFUNC Dllfunc; + load = LoadLibrary("DynamicLib"); + if (load != nullptr) + { + Dllfunc = (DLLFUNC)GetProcAddress(load, "MergeD"); + if (Dllfunc != nullptr) + { + Dllfunc(a, n); + } + FreeLibrary(load); + } + printf("array sorted with explicit dynamic lib\n"); + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + printf("\n"); + printf("third array\n"); + printf("\n"); + for (int i = 0; i < n; i++) + a[i] = rand() % 20 - 10; + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + MergeD(a, n); + printf("array sorted with implicit dynamic lib\n"); + for (int i = 0; i < n; i++) + printf("%d ", a[i]); + printf("\n"); + delete[] a; + return 0; +} \ No newline at end of file diff --git a/StaticMath/AllLibs/AllLibs.vcxproj b/StaticMath/AllLibs/AllLibs.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..a867ee1896958b7e7fd7a96c4b2c1954af9fd5b9 --- /dev/null +++ b/StaticMath/AllLibs/AllLibs.vcxproj @@ -0,0 +1,152 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {bdbe7d2c-ac32-4c9f-988e-8a6e198fe848} + AllLibs + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\user\source\repos\StaticMath\MathLibrary;C:\Users\user\source\repos\StaticMath\DynamicLib;%(AdditionalIncludeDirectories) + + + Console + true + ..\$(IntDir);%(AdditionalLibraryDirectories) + DynamicLib.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\user\source\repos\StaticMath\MathLibrary;C:\Users\user\source\repos\StaticMath\DynamicLib;%(AdditionalIncludeDirectories) + + + Console + true + true + true + ..\$(IntDir);%(AdditionalLibraryDirectories) + DynamicLib.lib;%(AdditionalDependencies) + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\user\source\repos\StaticMath\MathLibrary;C:\Users\user\source\repos\StaticMath\DynamicLib;%(AdditionalIncludeDirectories) + + + Console + true + ..\$(IntDir);%(AdditionalLibraryDirectories) + DynamicLib.lib;%(AdditionalDependencies) + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + C:\Users\user\source\repos\StaticMath\MathLibrary;C:\Users\user\source\repos\StaticMath\DynamicLib;%(AdditionalIncludeDirectories) + + + Console + true + true + true + ..\$(IntDir);%(AdditionalLibraryDirectories) + DynamicLib.lib;%(AdditionalDependencies) + + + + + + + + {30d05401-eeee-45f0-8781-45dffb51cf98} + + + + + + \ No newline at end of file diff --git a/StaticMath/DynamicLib/DynMerg.cpp b/StaticMath/DynamicLib/DynMerg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5fd581eb9096fcb0eb7d7cd801c4a7f8379f10aa --- /dev/null +++ b/StaticMath/DynamicLib/DynMerg.cpp @@ -0,0 +1,25 @@ +#include "DynMerg.h" +#include +#include +#include +using namespace std; +void MergeD(int* A, int fsize) +{ + if (fsize < 2)return; + MergeD(A, fsize / 2); + MergeD(&A[fsize / 2], fsize - (fsize / 2)); + int* buf = new int[fsize]; + int idbuf = 0, idl = 0, idr = fsize / 2; + while ((idl < fsize / 2) && (idr < fsize)) + { + if (A[idl] < A[idr]) + buf[idbuf++] = A[idl++]; + else + buf[idbuf++] = A[idr++]; + } + while (idl < fsize / 2) buf[idbuf++] = A[idl++]; + while (idr < fsize) buf[idbuf++] = A[idr++]; + for (idl = 0; idl < fsize; idl++) + A[idl] = buf[idl]; + delete[]buf; +}; diff --git a/StaticMath/DynamicLib/DynMerg.h b/StaticMath/DynamicLib/DynMerg.h new file mode 100644 index 0000000000000000000000000000000000000000..b6472614a4383be1f1ae488f4f6d1e623295ea95 --- /dev/null +++ b/StaticMath/DynamicLib/DynMerg.h @@ -0,0 +1,7 @@ +#pragma once +#ifdef DYNAMICLIB_EXPORT +#define DYNAMICLIB_API __declspec(dllexport) +#else +#define DYNAMICLIB_API __declspec(dllimport) +#endif +extern "C" DYNAMICLIB_API void MergeD(int* , int ); diff --git a/StaticMath/DynamicLib/DynamicLib.vcxproj b/StaticMath/DynamicLib/DynamicLib.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..42be3689db53686342428904491aa204660a14ca --- /dev/null +++ b/StaticMath/DynamicLib/DynamicLib.vcxproj @@ -0,0 +1,138 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {0343aedf-2efb-4d29-9571-c2c47c935c86} + DynamicLib + 10.0 + + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + DynamicLibrary + true + v143 + MultiByte + + + DynamicLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + Level3 + true + DYNAMICLIB_EXPORT + true + + + Console + true + + + + + Level3 + true + true + true + DYNAMICLIB_EXPORT + true + + + Console + true + true + true + + + + + Level3 + true + DYNAMICLIB_EXPORT + true + + + Console + true + + + + + Level3 + true + true + true + DYNAMICLIB_EXPORT + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/StaticMath/MathLibrary/MathLibrary.cpp b/StaticMath/MathLibrary/MathLibrary.cpp new file mode 100644 index 0000000000000000000000000000000000000000..539156d9c3cb737cb87311dff6c4946db76d4738 --- /dev/null +++ b/StaticMath/MathLibrary/MathLibrary.cpp @@ -0,0 +1,26 @@ + + +#include "MathLibrary.h" +#include +#include + +void merge(int* A, int fsize) +{ + if (fsize < 2)return; + merge(A, fsize / 2); + merge(&A[fsize / 2], fsize - (fsize / 2)); + int* buf = new int[fsize]; + int idbuf = 0, idl = 0, idr = fsize / 2; + while ((idl < fsize / 2) && (idr < fsize)) + { + if (A[idl] < A[idr]) + buf[idbuf++] = A[idl++]; + else + buf[idbuf++] = A[idr++]; + } + while (idl < fsize / 2) buf[idbuf++] = A[idl++]; + while (idr < fsize) buf[idbuf++] = A[idr++]; + for (idl = 0; idl < fsize; idl++) + A[idl] = buf[idl]; + delete[]buf; +}; \ No newline at end of file diff --git a/StaticMath/MathLibrary/MathLibrary.h b/StaticMath/MathLibrary/MathLibrary.h new file mode 100644 index 0000000000000000000000000000000000000000..53ab7ce407fd11c4f859478917b3391c84400e7f --- /dev/null +++ b/StaticMath/MathLibrary/MathLibrary.h @@ -0,0 +1,3 @@ + +#pragma once +void merge(int*, int); diff --git a/StaticMath/MathLibrary/MathLibrary.vcxproj b/StaticMath/MathLibrary/MathLibrary.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..0884f7589dce211ef5351975cf3d04ccfb0918b8 --- /dev/null +++ b/StaticMath/MathLibrary/MathLibrary.vcxproj @@ -0,0 +1,143 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {30d05401-eeee-45f0-8781-45dffb51cf98} + MathLibrary + 10.0 + StaticLib + + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + StaticLibrary + true + v143 + Unicode + + + StaticLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + + + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + + + true + true + true + + + + + Level3 + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + + + true + + + + + Level3 + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + + + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/StaticMath/StaticMath.sln b/StaticMath/StaticMath.sln new file mode 100644 index 0000000000000000000000000000000000000000..2d38b89dd4f79d22dc9cb364d75e5f3d9d9c855d --- /dev/null +++ b/StaticMath/StaticMath.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StaticLib", "MathLibrary\MathLibrary.vcxproj", "{30D05401-EEEE-45F0-8781-45DFFB51CF98}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DynamicLib", "DynamicLib\DynamicLib.vcxproj", "{0343AEDF-2EFB-4D29-9571-C2C47C935C86}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AllLibs", "AllLibs\AllLibs.vcxproj", "{BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Debug|x64.ActiveCfg = Debug|x64 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Debug|x64.Build.0 = Debug|x64 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Debug|x86.ActiveCfg = Debug|Win32 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Debug|x86.Build.0 = Debug|Win32 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Release|x64.ActiveCfg = Release|x64 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Release|x64.Build.0 = Release|x64 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Release|x86.ActiveCfg = Release|Win32 + {30D05401-EEEE-45F0-8781-45DFFB51CF98}.Release|x86.Build.0 = Release|Win32 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Debug|x64.ActiveCfg = Debug|x64 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Debug|x64.Build.0 = Debug|x64 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Debug|x86.ActiveCfg = Debug|Win32 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Debug|x86.Build.0 = Debug|Win32 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Release|x64.ActiveCfg = Release|x64 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Release|x64.Build.0 = Release|x64 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Release|x86.ActiveCfg = Release|Win32 + {0343AEDF-2EFB-4D29-9571-C2C47C935C86}.Release|x86.Build.0 = Release|Win32 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Debug|x64.ActiveCfg = Debug|x64 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Debug|x64.Build.0 = Debug|x64 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Debug|x86.ActiveCfg = Debug|Win32 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Debug|x86.Build.0 = Debug|Win32 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Release|x64.ActiveCfg = Release|x64 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Release|x64.Build.0 = Release|x64 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Release|x86.ActiveCfg = Release|Win32 + {BDBE7D2C-AC32-4C9F-988E-8A6E198FE848}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {38BC51DA-2C71-49C7-A65B-8978FB3BF262} + EndGlobalSection +EndGlobal