Skip to content

Feature/add algo #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 19, 2025
Merged
21 changes: 14 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ SET ( cppcore_container_src
SOURCE_GROUP( code FILES ${cppcore_src} )
SOURCE_GROUP( code\\common FILES ${cppcore_common_src} )
SOURCE_GROUP( code\\container FILES ${cppcore_container_src} )
SOURCE_GROUP( code\\IO FILES ${cppcore_io_src} )
SOURCE_GROUP( code\\io FILES ${cppcore_io_src} )
SOURCE_GROUP( code\\memory FILES ${cppcore_memory_src} )
SOURCE_GROUP( code\\random FILES ${cppcore_random_src} )

Expand Down Expand Up @@ -139,27 +139,33 @@ IF( CPPCORE_BUILD_UNITTESTS )

SET( cppcore_container_test_src
test/container/TArrayTest.cpp
test/container/TAlgorithmTest.cpp
test/container/THashMapTest.cpp
test/container/TListTest.cpp
test/container/TQueueTest.cpp
test/container/TStaticArrayTest.cpp
)

SET( cppcore_io_test_src
test/io/FileSystemTest.cpp
)

SET( cppcore_memory_test_src
test/memory/TStackAllocatorTest.cpp
test/memory/TPoolAllocatorTest.cpp
test/memory/TScratchAllocatorTest.cpp
)

SET( cppcore_random_test_src
test/Random/RandomGeneratorTest.cpp
test/random/RandomGeneratorTest.cpp
)

SOURCE_GROUP( code FILES ${cppcore_test_src} )
SOURCE_GROUP( code\\common FILES ${cppcore_common_test_src} )
SOURCE_GROUP( code\\container FILES ${cppcore_container_test_src} )
SOURCE_GROUP( code\\memory FILES ${cppcore_memory_test_src} )
SOURCE_GROUP( code\\random FILES ${cppcore_random_test_src} )
SOURCE_GROUP(code FILES ${cppcore_test_src} )
SOURCE_GROUP(code\\common FILES ${cppcore_common_test_src} )
SOURCE_GROUP(code\\io FILES ${cppcore_io_test_src} )
SOURCE_GROUP(code\\container FILES ${cppcore_container_test_src} )
SOURCE_GROUP(code\\memory FILES ${cppcore_memory_test_src} )
SOURCE_GROUP(code\\random FILES ${cppcore_random_test_src} )

# Prevent overriding the parent project's compiler/linker
# settings on Windows
Expand All @@ -179,6 +185,7 @@ IF( CPPCORE_BUILD_UNITTESTS )
ADD_EXECUTABLE( cppcore_unittest
${cppcore_test_src}
${cppcore_common_test_src}
${cppcore_io_test_src}
${cppcore_memory_test_src}
${cppcore_random_test_src}
${cppcore_container_test_src}
Expand Down
8 changes: 4 additions & 4 deletions code/Random/RandomGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ unsigned int mersenne_twister() {
}

RandomGenerator::RandomGenerator( GeneratorType type ) noexcept :
m_type( type ) {
::srand(static_cast<unsigned int>(time(nullptr)));
mType( type ) {
::srand( static_cast<unsigned int>(time(nullptr)));
}

int RandomGenerator::get( int lower, int upper ) {
int ret( 0 );
if ( GeneratorType::Standard == m_type ) {
if ( GeneratorType::Standard == mType ) {
ret = ::rand() % upper + lower;
} else if (GeneratorType::MersenneTwister == m_type) {
} else if (GeneratorType::MersenneTwister == mType) {
ret = mersenne_twister() % upper + lower;
}

Expand Down
4 changes: 2 additions & 2 deletions contrib/googletest-1.15.2/googletest/generated/gmock.pc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libdir=C:/Program Files (x86)/osre/lib
includedir=C:/Program Files (x86)/osre/include
libdir=C:/Program Files (x86)/cppcore/lib
includedir=C:/Program Files (x86)/cppcore/include

Name: gmock
Description: GoogleMock (without main() function)
Expand Down
4 changes: 2 additions & 2 deletions contrib/googletest-1.15.2/googletest/generated/gmock_main.pc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libdir=C:/Program Files (x86)/osre/lib
includedir=C:/Program Files (x86)/osre/include
libdir=C:/Program Files (x86)/cppcore/lib
includedir=C:/Program Files (x86)/cppcore/include

Name: gmock_main
Description: GoogleMock (with main() function)
Expand Down
4 changes: 2 additions & 2 deletions contrib/googletest-1.15.2/googletest/generated/gtest.pc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libdir=C:/Program Files (x86)/osre/lib
includedir=C:/Program Files (x86)/osre/include
libdir=C:/Program Files (x86)/cppcore/lib
includedir=C:/Program Files (x86)/cppcore/include

Name: gtest
Description: GoogleTest (without main() function)
Expand Down
4 changes: 2 additions & 2 deletions contrib/googletest-1.15.2/googletest/generated/gtest_main.pc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
libdir=C:/Program Files (x86)/osre/lib
includedir=C:/Program Files (x86)/osre/include
libdir=C:/Program Files (x86)/cppcore/lib
includedir=C:/Program Files (x86)/cppcore/include

Name: gtest_main
Description: GoogleTest (with main() function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\develop\projects\osre\x64\Debug\ZERO_CHECK</FullPath>
<FullPath>C:\develop\projects\cppcore\x64\Debug\ZERO_CHECK</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\develop\projects\osre\x64\Debug\ZERO_CHECK</FullPath>
<FullPath>C:\develop\projects\cppcore\x64\Debug\ZERO_CHECK</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
Expand Down
42 changes: 42 additions & 0 deletions include/cppcore/Container/TAlgorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-----------------------------------------------------------------------------------------------
The MIT License (MIT)

Copyright (c) 2014-2025 Kim Kulling

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------------------------*/
#pragma once

#include <cstddef>
#include <cassert>

namespace cppcore {

/// @brief Function to calulate the distance between two iterators.
/// @tparam TIt The container iterator
/// @param begin The first container iterator
/// @param end The second container iterator
/// @return The distance between the two iterators.
template<class TIt>
inline size_t distance(TIt begin, TIt end) {
assert(begin < end);
const size_t distance = end - begin;
return distance;
}

} // namespace cppcore
Loading