Hacker News new | past | comments | ask | show | jobs | submit login

I mean, compared to sequentially comparing thousands of IP addresses (really???), anything would be fast.



People here dismiss the linear search, but for a small number of items (and yes, even thousands can be a small number), I wouldn't be so fast without testing it. Cache locality also has a say here, and depending on the exact circumstances, a linear search might make sense (even more so as a first version).


I think the only time it makes sense to use a linear search is if you think the number of items on your list is low enough that it doesn't even matter what data structure you are using. But I would probably use a set rather than a list anyway if only because that more accurately reflects the nature of the data.


IIRC MySQL just skips using indices and does a linear search when a table size is small enough.


Probably a lot of DB Servers do that - which is why the plan for a query can change as the amount of data per table increases.


I think with AVX2 you could compare 10000 IP addresses in maybe 500 nanoseconds. Assuming they're cached. Uncached maybe 2 microseconds.

It'd still not be the greatest idea... but don't underestimate linear scan on a modern CPU.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: