lib/ip_locator_cn/qqwry.rb
# b-tree search ip from qqwry.dat
b-tree search ip from qqwry.dat
b - tree search ip from qqwry . dat
def locate_ip_pos(ip)
      x = ip2long(ip)
      min = 0
      max = total_ips
      while min <= max
        i = ((min + max) / 2).floor
        pos = first_ip_pos + i * IP_ENTRY_BYTES
        seek(pos)
        y = read_ip
        if x < y
          max = i - 1
        else
          read(3)
          y = read_ip
          if x > y
            min = i + 1
          else
            return pos
          end
        end
      end
      -1
    end
def locate_ip_pos ( ip ) x = ip2long ( ip ) min = 0 max = total_ips while min <= max i = ( ( min + max ) / 2 ) . floor pos = first_ip_pos + i * IP_ENTRY_BYTES seek ( pos ) y = read_ip if x < y max = i - 1 else read ( 3 ) y = read_ip if x > y min = i + 1 else return pos end end end - 1 end
b-tree search ip from qqwry.dat
b - tree search ip from qqwry . dat
# b-tree search # get middle ip # user ip < middle ip # user ip > middle ip, read next ip entry # user ip > next ip
ip
<not_specific>