Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Ip2region
提交
fdd3b2c7
I
Ip2region
项目概览
int
/
Ip2region
上一次同步 12 个月
通知
19
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Ip2region
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
fdd3b2c7
编写于
12月 28, 2022
作者:
G
gongzhengyang
提交者:
GitHub
12月 28, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2 from gongzhengyang/feature-2xdb
feat: change the ip2region2 -> xdb
上级
dcb4bb09
9983e12e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
19 addition
and
24 deletion
+19
-24
binding/rust/Cargo.toml
binding/rust/Cargo.toml
+1
-1
binding/rust/ReadMe.md
binding/rust/ReadMe.md
+7
-7
binding/rust/example/Cargo.toml
binding/rust/example/Cargo.toml
+1
-1
binding/rust/example/src/main.rs
binding/rust/example/src/main.rs
+1
-1
binding/rust/xdb/Cargo.toml
binding/rust/xdb/Cargo.toml
+1
-1
binding/rust/xdb/benches/search.rs
binding/rust/xdb/benches/search.rs
+1
-1
binding/rust/xdb/src/ip_value.rs
binding/rust/xdb/src/ip_value.rs
+0
-0
binding/rust/xdb/src/lib.rs
binding/rust/xdb/src/lib.rs
+0
-0
binding/rust/xdb/src/searcher.rs
binding/rust/xdb/src/searcher.rs
+7
-12
未找到文件。
binding/rust/Cargo.toml
浏览文件 @
fdd3b2c7
[workspace]
members
=
[
"example"
,
"
ip2region2
"
]
members
=
[
"example"
,
"
xdb
"
]
binding/rust/ReadMe.md
浏览文件 @
fdd3b2c7
...
...
@@ -23,7 +23,7 @@
```
toml
[dependencies]
ip2region2
=
{
git
=
"https://github.com/lionsoul2014/ip2region.git"
,
branch
=
"master"
}
xdb
=
{
git
=
"https://github.com/lionsoul2014/ip2region.git"
,
branch
=
"master"
}
# 用于生成随机数
rand
=
"0.8"
# 用于初始化日志打印
...
...
@@ -42,7 +42,7 @@ use std::net::Ipv4Addr;
use
std
::
thread
;
use
std
::
time
::{
Duration
,
Instant
};
use
ip2region2
::{
search_by_ip
,
searcher_init
};
use
xdb
::{
search_by_ip
,
searcher_init
};
fn
main
()
{
// 配置输出日志信息
...
...
@@ -103,7 +103,7 @@ fn main() {
Compiling ip-test v0.1.0
(
/home/gong/rust-work/ip-test
)
Finished release
[
optimized] target
(
s
)
in
0.27s
Running
`
target/release/ip-test
`
2022-12-24T03:31:22.921958Z DEBUG
ip2region2
::searcher: load xdb searcher file at ./ip2region.xdb
2022-12-24T03:31:22.921958Z DEBUG
xdb
::searcher: load xdb searcher file at ./ip2region.xdb
测试多类型查询
0|0|0|内网IP|内网IP
...
...
@@ -131,7 +131,7 @@ use std::time::Instant;
use
tokio
::
sync
::
mpsc
;
use
ip2region2
::{
search_by_ip
,
searcher_init
};
use
xdb
::{
search_by_ip
,
searcher_init
};
#[tokio::main]
async
fn
main
()
{
...
...
@@ -171,7 +171,7 @@ $ RUST_LOG=debug cargo run -r
Compiling ip-test v0.1.0
(
/home/gong/rust-work/ip-test
)
Finished release
[
optimized] target
(
s
)
in
0.51s
Running
`
target/release/ip-test
`
2022-12-24T04:05:32.876664Z DEBUG
ip2region2
::searcher: load xdb searcher file at ./ip2region.xdb
2022-12-24T04:05:32.876664Z DEBUG
xdb
::searcher: load xdb searcher file at ./ip2region.xdb
tokio spawn 4 over cost: 1.133448675s, ave: 113ns
tokio spawn 2 over cost: 1.133938619s, ave: 113ns
tokio spawn 1 over cost: 1.136872027s, ave: 113ns
...
...
@@ -183,7 +183,7 @@ tokio spawn 3 over cost: 1.26446099s, ave: 126ns
# `binding/rust`路径下面的结构说明
`
ip2region2
`
`
xdb
`
-
封装了
`ip`
到
`region`
的函数
-
里面包含单元测试和
`benchmark`
测试
...
...
@@ -311,7 +311,7 @@ $ cargo test
需要保证查询速度不会有大幅降低,希望有朝一日,远方的朋友可以再深度优化一下,实现几十纳秒级别的查询速度
下面是
`
ip2region2
`
库的第一版
`benchmark`
结果
下面是
`
rust/xdb
`
库的第一版
`benchmark`
结果
重点关注如下
...
...
binding/rust/example/Cargo.toml
浏览文件 @
fdd3b2c7
...
...
@@ -10,7 +10,7 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ip2region2
=
{
path
=
"../ip2region2
"
}
xdb
=
{
path
=
"../xdb
"
}
clap
=
{
version
=
"4.0"
}
tracing
=
"0.1"
tracing-subscriber
=
"0.3.14"
binding/rust/example/src/main.rs
浏览文件 @
fdd3b2c7
...
...
@@ -9,7 +9,7 @@ use std::time::Instant;
use
clap
::
ArgMatches
;
use
ip2region2
::{
search_by_ip
,
searcher_init
};
use
xdb
::{
search_by_ip
,
searcher_init
};
mod
cmd
;
...
...
binding/rust/
ip2region2
/Cargo.toml
→
binding/rust/
xdb
/Cargo.toml
浏览文件 @
fdd3b2c7
[package]
name
=
"
ip2region2
"
name
=
"
xdb
"
version
=
"0.1.0"
edition
=
"2021"
rust-version
=
"1.66.0"
...
...
binding/rust/
ip2region2
/benches/search.rs
→
binding/rust/
xdb
/benches/search.rs
浏览文件 @
fdd3b2c7
use
criterion
::{
black_box
,
criterion_group
,
criterion_main
,
Criterion
};
use
rand
;
use
ip2region2
::
searcher
::{
use
xdb
::
searcher
::{
get_block_by_size
,
get_full_cache
,
get_vector_index_cache
,
search_by_ip
,
searcher_init
,
};
...
...
binding/rust/
ip2region2
/src/ip_value.rs
→
binding/rust/
xdb
/src/ip_value.rs
浏览文件 @
fdd3b2c7
文件已移动
binding/rust/
ip2region2
/src/lib.rs
→
binding/rust/
xdb
/src/lib.rs
浏览文件 @
fdd3b2c7
文件已移动
binding/rust/
ip2region2
/src/searcher.rs
→
binding/rust/
xdb
/src/searcher.rs
浏览文件 @
fdd3b2c7
...
...
@@ -24,7 +24,13 @@ where
T
:
ToUIntIP
+
Display
,
{
let
ip
=
ip
.to_u32_ip
()
?
;
let
(
start_ptr
,
end_ptr
)
=
get_start_end_ptr
(
ip
);
let
il0
=
((
ip
>>
24
)
&
0xFF
)
as
usize
;
let
il1
=
((
ip
>>
16
)
&
0xFF
)
as
usize
;
let
idx
=
VECTOR_INDEX_SIZE
*
(
il0
*
VECTOR_INDEX_COLS
+
il1
);
let
start_point
=
idx
;
let
vector_cache
=
get_vector_index_cache
();
let
start_ptr
=
get_block_by_size
(
vector_cache
,
start_point
,
4
);
let
end_ptr
=
get_block_by_size
(
vector_cache
,
start_point
+
4
,
4
);
let
mut
left
:
usize
=
0
;
let
mut
right
:
usize
=
(
end_ptr
-
start_ptr
)
/
SEGMENT_INDEX_SIZE
;
...
...
@@ -49,17 +55,6 @@ where
Err
(
"not matched"
.into
())
}
pub
fn
get_start_end_ptr
(
ip
:
u32
)
->
(
usize
,
usize
)
{
let
il0
=
((
ip
>>
24
)
&
0xFF
)
as
usize
;
let
il1
=
((
ip
>>
16
)
&
0xFF
)
as
usize
;
let
idx
=
VECTOR_INDEX_SIZE
*
(
il0
*
VECTOR_INDEX_COLS
+
il1
);
let
start_point
=
idx
;
let
vector_cache
=
get_vector_index_cache
();
let
start_ptr
=
get_block_by_size
(
vector_cache
,
start_point
,
4
);
let
end_ptr
=
get_block_by_size
(
vector_cache
,
start_point
+
4
,
4
);
(
start_ptr
,
end_ptr
)
}
/// it will check ../data/ip2region.xdb, ../../data/ip2region.xdb, ../../../data/ip2region.xdb
fn
default_detect_xdb_file
()
->
Result
<
String
,
Box
<
dyn
Error
>>
{
let
prefix
=
"../"
.to_owned
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录