int max = ~0;
What does it mean?
~ means bitwise not, it inverts all the bits in the given integer. In a signed int this will give you -1 (since all the bits in the int will be flipped from 0 to 1.) Look up two's complement for more information on this one.
In an unsigned int (uint) this would give you the maximum value of an integer (since the most significant bit in an unsigned int doesn't determine the sign.)