"Infinite" Loops

The topic of a discussion at work turned to long running processes. Lets say you want to anonymize IP addresses (ignore IPv6 since we're not in that world yet) and decide to hash them as a way to protect the anonymity of users. That's pretty secure, right?Well, an IPv4 address is only four bytes long, 32 bits. The total combinations are a mind numbing 2^32, right?That's four billion (and change) for those playing along at home.Except four billion hasn't been a big number for a long time.Back in the days of the 80286 and 80386 my friend and I used to talk about how long an "infinite loop" would take. Infinite, in this case, is a loop who's end condition is off by one.Something like this:

for (int i = 0; i != 0; i++) {}

Assuming 32-bit ints, this would be the perfect infinite loop, looping around for all four billion integers.Back in those day it would take many minutes to run. A 25 MHz '386. Executing an instruction every few cycles would take around 10 minutes to count all the way through.It's the same number of IP addresses.All you need to do is add in a hash. Creating a dictionary of all of the IP addresses and their corresponding hash value is pretty darn trivial now. My co-worker didn't believe me.So I challenged him to write an infinite loop. He chose Java, but kept the same constraint of 32 bits instead of the native 64-bit ints.It ran in 1.4 seconds. In JITed Java.He admitted it was bloody fast.  :-)

Previous
Previous

Together

Next
Next

22 Points!!