Git Product home page Git Product logo

ipq's Introduction

ipq: a ip location query toy

how to build

mkdir build
cd build
cmake ..
make

how to use

first, download the csv file here https://pan.baidu.com/s/1DMxqf8GvzP7G7x9k4P5zrA (originally from: https://lite.ip2location.com/download?id=3), then

cd build
src/stl_ipq path/to/your/IP2LOCATION-LITE-DB3.CSV

ipq has three commands, type the commands at stdin, one command per line.

query ip
delete ip1 ip2
update ip1 ip2 country_code country_name province city

Ip could be a decimal number, or something like 127.0.0.1(no verification of the ip address given is performed, so...). Query command queries the location of the ip address. Delete command deletes the information of the ip range, both ip1 and ip2 included. Update command updates data base for the ip range, both ip1 and ip2 included

implementation details

To support range update and point query, ipq uses three kinds of datastructures:

interval-tree: include/interval_tree.hpp
segment-tree: include/segment_tree.hpp
btree: include/btree_{map, set, impl}.hpp

The interval tree counld be implemented on std::map or ipq::BTreeMap. The segment-tree is simple in that it only supports non-incremental range update and point-query, also it need two special value in the value space to represents non-existing value and that range not marked as the same. The btree algorithm is from chapter 18 of CLRS, it supports insert/delte/find and find next/prev node of a iterator. One important fact about btree is that , in contrast to rb-tree, any operations that modifies the btree (for example, insert/delete, or reform the btree during find) will invalidate all existing iterator.

You can find the test cases for btree/interval-tree/segment-tree at test/ directories, run them with:

cd build
ninja test

You can benchmark the btree and stl rbtree with files in the benchmark directory. You need to compile it yourself with google benchmark. On my laptop pc, btree starts to out-perform std rb-tree when there are around 65536 node in the tree.

TODO

  1. more corner-case test for btree
  2. implement empalce for btree_map
  3. more comments

ipq's People

Contributors

lijinpei avatar

Watchers

James Cloos 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.