New answers tagged

0

I can't say the code is very readable in general, although it is probably better than average. This function is way too long and should be separated into several functions according to logic. And the way you use the standard library facilities doesn't seem optimal. Here are some suggestions on the code: IOperation* pFileReader = new McFileReader(); No, ...


3

Rreplace the inner for loop of rehashing with a call to put. put has an average runtime of \$\mathcal{O}(1)\$ . So, rehashing has an average runtime of \$\mathcal{O}(n)\$ since it is \$n\$ put operations. It would look something like this: void rehashing() { int oldCap = cap; sze = 0; cap = NextPrime(cap * 2); HashNode** oldArr = arr; arr = new ...


3

Most of this has already been discussed here: https://stackoverflow.com/questions/57441479/avoiding-deadlock-in-concurrent-waiting-object Issue 1 Mutex are owned by a thread so it is undefined behavior to call done() from a different thread that the one that create the Ticket. Issue 2 If a mutex is locked by a thread that already own the lock the ...


3

I won't comment on the things you already mentioned you are planning to implement in the future, except that as Ilya Popov already said, you can use SDL_RENDERER_PRESENTVSYNC to have SDL limit the frame rate for you. Don't abbreviate names too much Computers have enough RAM and storage space nowadays that you don't have to skimp on characters for variable ...


3

In general, the code looks nice. It is structured and well-formatted. It is probably a bad idea to have more than 80 characters in each line, because this may happen: Also, put the body of a control statement on a separate line. For example, instead of for(size_t i=0; i < bytes_read; i++) std::cout << (int)bd[i] << " "; do for (size_t i=...


0

This part looks ripe for refactoring: top_k = Tuple(argmin()).as_vector(); // Insert a single element into a sorted list without actually branching top_k.push_back(next_val); top_k.push_back(next_x); top_k.push_back(next_y); for (int i = k; i > 0; i--) { Expr prev_val = top_k[(i-1)*3]; ...


1

/* can we do better than this? */ In a circular buffer context, the standard way to avoid busy waiting is to have two semaphores. First to block a producer when a buffer is full, and second to block a consumer when the buffer is empty. Once a process passes its semaphore, and does its job, it should signal the peer. The circular buffer is good when the ...


Top 50 recent answers are included