Giter VIP home page Giter VIP logo

ipdatabase's Introduction

ipdatabase

二叉树快速搜索IP地址数据库

数据

数据源采用2015年广告协会制定的IP地址标准数据库,**互联网广告行业统一采用的标准IP库。

原理

利用二叉树实现IP查询,首先将10进制IPV4地址转化为二进制构建二叉树,利用二叉树搜索进行搜索,查询时间复杂度log2n,比传统IP库n的查询速度高出一个量级。

接口

根据IP查询城市或地区的接口是IpHelper类中的findRegionByIp接口,说明如下:

/**
 * 静态方法,传入ip地址,返回ip地址所在城市或地区
 * @param ip    IP地址,例:58.30.15.255
 * @return  返回IP地址所在城市或地区,例:北京市
 */
public static String findRegionByIp(String ip)

example

public void example() throws Exception {
    String ip = "58.30.15.255";
    String region = IpHelper.findRegionByIp(ip);
    System.out.println(region);
}

修改

默认的方法是只查询出省份,但是一般我们要的是省份+城市.修改代码

ipdatabase's People

Contributors

iamfbz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.