3 ms·
Skip lists. They are useful for checking in O(log(n)) if a number (or string) is in any of n ranges of numbers. You just keep a sorted list of endpoints of th
by perlgeek 4y ago
Skip lists.
They are useful for checking in O(log(n)) if a number (or string) is in any of n ranges of numbers.
You just keep a sorted list of endpoints of the ranges, and when you do a lookup, you do a binary search if the search value is in the list, and if not, between which two indexes. If it's between and even and an odd index, it's in.
Very useful if you remember that IP addresses are also integers, and with IPv6 networks become way too huge to enumerate.