4 ms·
while True: fd = open(log-$timestamp-$pid-$randomhex, O_CREAT|O_EXCL) if fd: break Hypothetically unbounded runtime, O(1) in practice.
by blattimwind 8y ago
while True:
fd = open(log-$timestamp-$pid-$randomhex, O_CREAT|O_EXCL)
if fd:
break
Hypothetically unbounded runtime, O(1) in practice.
- WorldMaker 8y agoDon't even bother with the while True. If you get a bucket collision with a random number, just don't log anything, or just fatally crash because you can't trust the platform's PRNG or don't have enough available entropy or are just plain unlucky. Keep it proper O(1).