Skip to content

Commit

Permalink
Merge branch 'conform_to_cpp_standard' into bug_fix_and_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fenilgmehta committed Jun 21, 2019
2 parents 9ebf30b + 64c227d commit 3945418
Show file tree
Hide file tree
Showing 17 changed files with 1,361 additions and 2,491 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
cmake-build-debug/*
CMakeList.txt

ProgressReport.md
ProgressReport_sorting.md
references/*
test/*.out

Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.8)
project(project_Sorting C CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE on)

add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(references)

#file(GLOB sourceFILES *.cpp *.c *.hpp)
#FOREACH (sourceFile ${sourceFILES})
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ The graphs above shows how ir_sort::integer_sort starts performing better with h
Usage
----------------------------------
For projects:
```
// copy the following four files to the project folder: "basic_sorts.hpp", "integer_sort.hpp", "integer_sort.cpp" and "integer_sort_objects_small.cpp"
```c++
// copy the following four files to the project folder: "basic_sorts.hpp", "ir_commons.hpp", "integer_sort.cpp" and "integer_sort_objects_small.cpp"

// paste the following lines in the file start
include "integer_sort.cpp"
```

For competitions:
```
```c++
// copy the namespace "ir_sort" from "ir_sort_competitions.cpp" to the main ".cpp" program file

// to call the function, from the namespace "ir_sort"
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FOREACH (sourceFile ${sourceFILES})
endforeach (sourceFile)

#add_executable(basic_sorts.cpp basic_sorts.cpp)
#add_executable(integer_sort.hpp integer_sort.hpp)
#add_executable(ir_commons.hpp ir_commons.hpp)
#add_executable(integer_sort.cpp integer_sort.cpp)
#add_executable(integer_sort_objects_small.cpp integer_sort_objects_small.cpp)
#add_executable(ir_sort_competitions.cpp ir_sort_competitions.cpp)
437 changes: 0 additions & 437 deletions src/basic_sorts.cpp

This file was deleted.

1,621 changes: 0 additions & 1,621 deletions src/integer_sort.cpp

This file was deleted.

1,070 changes: 1,064 additions & 6 deletions src/integer_sort.hpp

Large diffs are not rendered by default.

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions src/ir_commons.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#ifndef IR_SORT_INTEGER_SORT_HPP
#define IR_SORT_INTEGER_SORT_HPP

#include <cstdint>

//*****************************************************************************************************************************************

namespace ir_sort{
namespace integer_sort_common{

//############################################################################
// ##
// C O U N T B I T S ##
// ##
//############################################################################

template<typename T>
inline int_fast16_t countBits_positive(T num) {
int_fast16_t result = 0;

while (num > 0) {
num >>= 1;
result += 1;
}

return result;
}

template<typename T>
inline int_fast16_t countBits_negative(const T &negativeNum) {
auto num = static_cast<uint_fast64_t>(-negativeNum);
int_fast16_t result = 0;

while (num > 0) {
num >>= 1;
result += 1;
}

return result;
}

template<typename T>
inline int_fast16_t countBits(const T &num) {
if (num < 0) return countBits_negative(num);
return countBits_positive(num);
}

//############################################################################
// ##
// S E T I T E R A T I O N S ##
// ##
//############################################################################

inline void set_BitShift_Iterations(const int_fast16_t &arrMax_bits, int_fast16_t &bitsShift, int_fast16_t &iterationsRequired) {
if (arrMax_bits <= 8) { // 8 bits = 1 iteration
bitsShift = arrMax_bits;
iterationsRequired = 1;
} else if (arrMax_bits <= 10) {
bitsShift = 5;
iterationsRequired = 2;
} else if (arrMax_bits <= 12) {
bitsShift = 6;
iterationsRequired = 2;
} else if (arrMax_bits <= 14) {
bitsShift = 7;
iterationsRequired = 2;
} else if (arrMax_bits <= 16) { // 16 bits = 2 iterations
bitsShift = 8;
iterationsRequired = 2;
} else if (arrMax_bits <= 18) {
bitsShift = 6;
iterationsRequired = 3;
} else if (arrMax_bits <= 21) {
bitsShift = 7;
iterationsRequired = 3;
} else if (arrMax_bits <= 24) { // 24 bits = 3 iterations
bitsShift = 8;
iterationsRequired = 3;
} else if (arrMax_bits <= 28) {
bitsShift = 7;
iterationsRequired = 4;
} else if (arrMax_bits <= 32) { // 32 bits = 4 iterations
bitsShift = 8;
iterationsRequired = 4;
} else if (arrMax_bits <= 35) {
bitsShift = 7;
iterationsRequired = 5;
} else if (arrMax_bits <= 40) { // 40 bits = 5 iterations
bitsShift = 8;
iterationsRequired = 5;
} else if (arrMax_bits <= 42) {
bitsShift = 7;
iterationsRequired = 6;
} else if (arrMax_bits <= 48) { // 48 bits = 6 iterations
bitsShift = 8;
iterationsRequired = 6;
} else if (arrMax_bits == 49) {
bitsShift = 7;
iterationsRequired = 7;
} else if (arrMax_bits <= 56) { // 56 bits = 7 iterations
bitsShift = 8;
iterationsRequired = 7;
} else if (arrMax_bits <= 64) { // 64 bits = 8 iterations
bitsShift = 8;
iterationsRequired = 8;
} else { // Handle the situation where int128_t of int256_t or int512_t or int1024_t or anything else is used to create the array / array index
bitsShift = 8;
iterationsRequired = ((arrMax_bits+1) >> 3);
}
}
} // namespace integer_sort_common
} // namespace ir_sort


//*****************************************************************************************************************************************
#endif //IR_SORT_INTEGER_SORT_HPP
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ FOREACH (sourceFile ${sourceFILES})
endforeach (sourceFile)

#add_executable(raw_data_generator_integer.cpp raw_data_generator_integer.cpp)
#add_executable(project_Fastest-Integer-Sort.cpp project_Fastest-Integer-Sort.cpp)
#add_executable(project_SortingBest_integer.cpp project_SortingBest_integer.cpp)
#add_executable(project_SortingBest_object.cpp project_SortingBest_object.cpp)
16 changes: 16 additions & 0 deletions test/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# /usr/bin/time -f "%M KB used" ./a.out < 3_input

if [[ $# -eq 1 ]]
then
# if [[ "a.out" -ot "${1}" || "a.out" -nt "${1}" ]]
# then
echo "Compiling ..." > "/dev/stderr"
g++ -O2 "${1}"
# fi;
else
# if [[ "$2" -ot "${1}" || "$2" -nt "${1}" ]]
# then
echo "Compiling ..." > "/dev/stderr"
g++ -O2 "${1}" -o "${2}"
# fi;
fi;
Loading

0 comments on commit 3945418

Please sign in to comment.