Skip to content

Commit

Permalink
1. new fm_sort for large objects
Browse files Browse the repository at this point in the history
2. extra functions removed which were extremely specific to ascending and descending order sorting.
3. files renamed from .cpp and .h to .hpp
  • Loading branch information
fenilgmehta committed Feb 12, 2019
1 parent 9ebf30b commit 359167c
Show file tree
Hide file tree
Showing 16 changed files with 1,847 additions and 1,951 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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"
// 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"
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)
4 changes: 2 additions & 2 deletions src/basic_sorts.cpp → src/basic_sorts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace ir_sort {
// ##
//############################################################################

int_fast32_t INSERTION_SORT_THRESHOLD = 30; // 25
int_fast32_t MERGE_SORT_THRESHOLD = 29; // 135
int_fast32_t INSERTION_SORT_THRESHOLD = 30; // 25
int_fast32_t MERGE_SORT_THRESHOLD = 256; // 135

// insertion_sort threshold in merge_sort
// 0 to 1360
Expand Down
1,621 changes: 0 additions & 1,621 deletions src/integer_sort.cpp

This file was deleted.

1,627 changes: 1,621 additions & 6 deletions src/integer_sort.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <cstdint>
#include <iterator>

#include "basic_sorts.cpp"
#include "integer_sort.hpp"
#include "basic_sorts.hpp"
#include "ir_commons.hpp"

namespace ir_sort {
namespace object_integer_sort_functions {
Expand Down
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 359167c

Please sign in to comment.