Yiğit
#cbook
Yiğit
add ! or # or /get in front
thanks for information
Shahar
It's just to show that I expect it to be sorted
Fair enough. So I'll try embedding your code inside my function, and I'll try figuring it out. Thank you dude.
Anonymous
i guess the ! only works for report
Pavel
Done bro
That still not the whole code, there's no operations.h and operations.cpp
E
Hi guys , i am trying to input from istream like this: template<class T> void Counter<T>::add_from_stream(istream &input) { T t; while( (input >> t) && input.good()){ add(t); } } how i make it stop when i press enter for example i use this with 'cin' in C++ 98
Vlad
It can be a const pointer
Vlad
So you won't copy stuff around. But it's up to you
Vlad
I kinda forgot that you can't reassign references to a new address
Vlad
It can be a const pointer
const T* not T * const
Shahar
Maybe because it's a pair of generic types. But I can't overload their = because it's a predefined API
Shahar
wdym?
The IDE is yelling on this assignment: lastval = elem; with this error:No viable overloaded '='
Vlad
const elem_type* lastval;
Shahar
const elem_type* lastval;
Okay. So this is the function with your code: void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase { // std::vector<std::vector<std::pair<K2*, V2*>>> auto shuffledQueue = currentJobContext_.getShuffledQueue(); for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i) { // here we access all threads' intermediate vectors // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); // here we want to insert to shuffledQueue elements of type // std::vector<std::pair<K2*, V2*>> whose K2 is identical shuffledQueue.emplace_back(); // push empty vector for some reason const std::pair<K2*, V2*>* lastVal = &currIntermediateVec[0]; std::vector<std::pair<K2*, V2*>>* current = nullptr; for(const auto& elem : currIntermediateVec) { if(elem != *lastVal) { shuffledQueue.emplace_back(); // push empty vector for some reason current = &shuffledQueue.back(); } current->emplace_back(elem); lastVal = &elem; } } } // else => you aren't thread-0, so go wait on barrier }
Shahar
const elem_type* lastval;
What's the logic of this part? for(const auto& elem : currIntermediateVec) { if(elem != *lastVal) { shuffledQueue.emplace_back(); // push empty vector for some reason current = &shuffledQueue.back(); } current->emplace_back(elem); lastVal = &elem; } I'm not sure what's going on here
Pavel
https://wandbox.org/permlink/9Wj6SWPxVi1BnBB3
Hm seems like the signatures are correct. Do you compile the other three cpp files as well? https://wandbox.org/permlink/MNJAJd1JSLecSclQ
Pavel
Yess broo
Can you show how you do that? You can actually try to execute the command from the wandbox example (the one that starts with g++)
Pavel
but without the boost part
Pavel
g++ addition.cpp subtraction.cpp multiplication.cpp main.cpp
Ammar
What's the deal with this linkedin premium stuff?
Shahar
I create new vector and assign it's address so we would be populating a new one
Something strange. The final wanted vector of vectors must be the variable shuffledQueue, but your snippet doesn't insert to it nothing but empty vectors void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase { // std::vector<std::vector<std::pair<K2*, V2*>>> auto shuffledQueue = currentJobContext_.getShuffledQueue(); for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i) { // here we access all threads' intermediate vectors // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); // here we want to insert to shuffledQueue elements of type // std::vector<std::pair<K2*, V2*>> whose K2 is identical shuffledQueue.emplace_back(); // push empty vector for some reason const std::pair<K2*, V2*>* lastVal = &currIntermediateVec[0]; std::vector<std::pair<K2*, V2*>>* current = nullptr; for(const auto& elem : currIntermediateVec) { if(elem != *lastVal) { shuffledQueue.emplace_back(); // push empty vector for some reason current = &shuffledQueue.back(); } current->emplace_back(elem); lastVal = &elem; } } } // else => you aren't thread-0, so go wait on barrier }
Pavel
I don’t get you bro.
How do you compile your code, what do you use?
Pavel
what IDE or what console command?
Vlad
Cause it's vector of vectors
Shahar
Well I push empty vector and then populate it
Ah. You manage it with current or something like that.... Looks genius
Pavel
Dev C++
are all the files added to the project? did you name the three files with .cpp at the end?
Shahar
LOL. I find the logic flow difficult to understand. Not sure it does the job. Looks like a magic
Vlad
Just assign the last vector to a pointer so the code works with it
Shahar
It's easier then a bunch of counters imo
There is something I'm not sure about your implementation though. As we have those iterations: for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i) { // here we access all threads' intermediate vectors // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec();
Anonymous
c++ has 2 way of object manipulation, by pointers , by class variables
Shahar
So if at the first iteration you've built the required vectors with the same keys, at the second iteration, you already doesn't catch the vectors with identical K2 I think
Vlad
And your outer loop
Vlad
Put it into the function or something if it bugs you
Shahar
Put it into the function or something if it bugs you
i don't think it's integrated with the outer loop
Vlad
i don't think it's integrated with the outer loop
It doesn't but if it's in a separate function you know that it won't be doing funky stuff
Vlad
So automagically easier to debug
Shahar
It doesn't but if it's in a separate function you know that it won't be doing funky stuff
what if we have at the first iteration this vector [ [1,200], [1, 300], [5, 50] ] The shuffleQueue will be updated to: [ [[1,200], [1, 300]], [[5, 50]] ] and a the second iteration we have this one [ [1, 60] , [5, 10] ] The shuffleQueue will be updated to: [ [[1,200], [1, 300]], [[5, 50]], [[1, 60]] , [[5, 10]] ] We would expect it to be: [ [[1,200], [1, 300], [1, 60]], [[5, 50], [5, 10]] ] So actually we did here nothing....
Vlad
Because their values are unique
Shahar
It would put all of them into separate vectors
The point is we want shuffleQueue to contain vectors of pairs where each vector of pairs contains pairs with identical K2 (that is, key of the pair), and we don't want them to be separated
Anonymous
try this algo at more simple language before make it at c++, c++ allows lua interpretation, or use python by cli
Vlad
So it won't be just elem != *lastval
Vlad
You might compare their K2's or something
Vlad
So it won't be just elem != *lastval
To make it easier to maintain make it as a lambda comparator
Shahar
You might compare their K2's or something
No idea how to integrate it, it's a real mind-blowing.
Vlad
No idea how to integrate it, it's a real mind-blowing.
auto comp = [](auto& left, auto& right) { return left.V2 != right.V2; };
Vlad
So it would compare them only by the second part
Vlad
if(comp(elem, *lastVal)) { // do shit }
Shahar
auto comp = [](auto& left, auto& right) { return left.V2 != right.V2; };
I think this integration is an overkill... I'll try doing something else maybe. Thank you anyways
Pavel
Yess
Sorry, I can't look at it now (busy), but it seems that the code is fine. I've sent you the link where your code compiled correctly. So it seems like the problem somewhere in the way it is being built, but not sure
Shahar
auto comp = [](auto& left, auto& right) { return left.V2 != right.V2; };
void ThreadContext::invokeShufflePhase() { if (thread_id_ == 0) // by convention - only thread-0 performs the shuffle phase { std::unordered_map<K2*, IntermediateVec> keyToVectorOfPairs; for (size_t i = 0; i < currentJobContext_.getNumOfThreads(); ++i){ // std::vector<std::pair<K2*, V2*>> sorted by K2 auto currIntermediateVec = currentJobContext_.getThreadContext(i).getIntermediateVec(); for(const auto& elem : currIntermediateVec){ keyToVectorOfPairs[elem.first].emplace_back(elem); } } auto shuffledQueue = currentJobContext_.getShuffledQueue(); // std::vector<std::vector<std::pair<K2*, V2*>>> for(const auto& sameKeyPairVector : keyToVectorOfPairs){ shuffledQueue.emplace_back(sameKeyPairVector); } } // else => you aren't thread-0, so go wait on barrier } Here you can see that I'm implementing this shuffle using unordered_map. For some reason, I have a problem at this line: shuffledQueue.emplace_back(sameKeyPairVector); The IDE says: In template: no matching constructor for initialization of 'std::vector<std::pair<K2 *, V2 *>, std::allocator<std::pair<K2 *, V2 *>>>' What can be done to overcome that?
Yasas
This person called Judish Mucumit is pming me
Yasas
Help me please admins
Pavel
This person called Judish Mucumit is pming me
1. Make a screenshot 2. Write here /report and nickname (from their profile, starting with @), and then the reason for the report E.g. /report @gameraccoon PMing me 3.Then in the profile you can block them (pressing on three dots and chosing "Block user" there) 4. You can also press "Report" there, then they will be reported as spammers and eventually blocked from sending PMs to anyone
'''''''
How should i read a piece of text from a txt file? I have a txt file of questions and answers, i want to print the questions and verify the answers with the input from the user.
•‿•
Can someone explain me about function When to use void or int like that !