Deterministic algorithm to find number of collisions
You could hash all of the elements of $D$, sort them, and then count duplicates.  Sorting brings all duplicates next to each other, so a linear scan lets you count the number of duplicates.  The running time will be $O(|D| \log |D|)$.

If you don't insist on a deterministic algorithm, you could place elements of $D$ into a hashtable, using $h$ as your hash, and then count the size of each hash bucket.  If the hash function is any good, then there is a sense in which the expected running time is $O(|D|)$ (e.g., if the elements of $D$ are random and the hash function is sufficiently good) -- but the worst case is $O(|D|^2)$.