-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
9ebf30b
commit 359167c
Showing
16 changed files
with
1,847 additions
and
1,951 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.