|
|
|
|
|
by milkshakes
5010 days ago
|
|
O(1) means constant time.
Redis sets are interesting, because there are a few possible implementations under the hood, but the typical case winds up implementing it as a hash table. Hash tables have constant time lookup. Think of it this way (this isn't literally what happens, but it's close). 1) Take the url you're looking for. Run it through a hash function. This takes an (amortized) constant amount of time. 2) Now you have an index to check. (the return value from the hash function). So index into your actual table, and check to see what's stored there. If there's a value stored there, then the url is a member of the set. This also takes a constant amount of time. Does this help? |
|
But that check isn't a constant time lookup. The lookup time can vary. (Analogously, a lookup in a phone book can vary in time; we can't necessarily go to the exact spot the first time.) So the total time for both steps must vary as well. I think.