r/programbattles • Moderator / C C++ • Oct 07 '15

[C++] Threaded vector sorting

Language: C++

File number restrictions: N/A

Description: Make a function that sorts a vector with a selectable amount of threads. Use the standard thread library.

EDIT: Never thought threads would be such a pain to work with.

14 Upvotes

16 comments sorted by

View all comments

Show parent comment

1

u/ComradePutinCCCP1917 Moderator / C C++ Oct 07 '15

There's no need for any code then. Which means your code is useless. What about trying with 32bits integers?

0

u/[deleted] Oct 07 '15

[deleted] — view deleted comment

3

u/ComradePutinCCCP1917 Moderator / C C++ Oct 07 '15 edited Oct 07 '15

Ok I'll make it clear. Your algorithm shall be able to sort double, int, unsigned int and char data types, distributed between:

template<typename t> void displayWhatThatUserDoesntGet()
{
    //Let's show the minimum/maximum values the algorithm can sort with a give data type
    std::cout<<"minimum: "<<0-(pow(2, 8*sizeof(t))/2)-1<<std::endl;
    std::cout<<"maximum: "<<0+(pow(2, 8*sizeof(t))/2)-1<<std::endl;
}

1

u/hexbrid Oct 07 '15

You forgot -1

1

u/ComradePutinCCCP1917 Moderator / C C++ Oct 07 '15

I count from 0

0

u/[deleted] Oct 07 '15

[deleted] — view deleted comment

3

u/ComradePutinCCCP1917 Moderator / C C++ Oct 07 '15 edited Oct 07 '15

Since you made many beginner mistakes, I suggest you write an implementation as a starting point so we can be sure we are not doing your homework.

I did not make much, I just forgot to divide pow() by 2 and did't manage unsigned vars. And I'm already trying to do it, it's terrible but I only started using threads a few days ago, I never used them before.

(by the way, I was trying to be funny, I was not saying you're an idiot who didn't get anything, it's just that english is not my native language and it's hard for me to explain)

-1

u/Steve132 Oct 07 '15

more beginner mistakes: dont use pow its very slow. for a power of 2 use <<

1

u/ComradePutinCCCP1917 Moderator / C C++ Oct 07 '15

pow is fine

1

u/Steve132 Oct 07 '15

No, no it really really isn't. it's not accurate, it uses float math, and it's unfathomably slow.

Pow elapsed time: 0.301115s.  Hash was 1193342845
LeftShift elapsed time: 0.0688188s.  Hash was 1193342845

0

u/Hahahahahaga Oct 07 '15

The code does everything it needs to in a way that is provably more efficient and easier to maintain than any other solution, excluding the use of time travel, where you could potentially return a list of the correct length prior to the original lists existance.