
Data structure and algorithms problems in C++ - mandliya
https://github.com/mandliya/algorithms_and_data_structures
======
brian-armstrong
The bit twiddling in this looks fairly naive/slow.

There's some really great, fantastically fast methods in
[https://graphics.stanford.edu/~seander/bithacks.html](https://graphics.stanford.edu/~seander/bithacks.html)
that require some interesting insights in finite fields. These are usually the
sorts of techniques you'd want to turn to for bit twiddles

~~~
djmips
And the fine book, which may cover a lot of the same ground.
[http://www.hackersdelight.org/](http://www.hackersdelight.org/)

------
neosavvy
Sick job, that's nearly 4 years of hard work there.

------
DominikD
Some of the solutions are not safe (and should be indicated as such). For
example MIN/MAX in generic.h are macros so shouldn't be used with functions
(and mustn't be used with functions that have side-effects). Macro parameters
aren't bracketed either so operator precedence can bite there too.

There's also potential for undefined or implementation-defined behavior (e.g.
multiply_by_7() is left shifting signed int). Author's heart is in the right
place it's just that his skills aren't necessarily up to the task, I'm afraid.

~~~
mandliya
edit: Spellings.

Thank you for the feedback. Some of the programs here are coded 4 years ago,
when I had just started learning C++ and I never revisited them. At that time,
I was in university, and this repo was to attract recruiters for internship. I
got the job later, and kind of ignored to correct problems. I am sure if these
are ran with strict compiler flags there would be many more issues. I will get
around and fix it sometime soon.

~~~
DominikD
Sure thing, reading through the repo I understood it was used to learn stuff.
But it may not be immediately understood by a novice. And thing with the
Internet is: people will start using code from your repo and get into all
sorts of issues. It's unlikely you'll smooth this code up. Nobody's got the
time, let's be honest here. ;) So I'd recommend that you at least state
explicitly that these functions shouldn't be lifted directly unless someone
knows what he/she is doing.

~~~
mandliya
Thanks again for the response, I understand it might be better to put a
warning note at the top of readme. Thank you again for the advice.

------
maccam912
Are these from somewhere? I might try to recreate this in Rust as a way to
learn more of that language.

~~~
steveklabnik
Just to caution you, data structures aren't a great way to learn Rust. See
this recent discussion, for example:
[https://news.ycombinator.com/item?id=16072630](https://news.ycombinator.com/item?id=16072630)

Algorithms are fine, though.

