mirror of
https://github.com/lionsoul2014/ip2region.git
synced 2025-12-08 19:25:22 +00:00
Merge branch 'master' of gitee.com:lionsoul/ip2region
This commit is contained in:
commit
f8f5f687e6
@ -1,10 +1,10 @@
|
||||
all: xdb_searcher util_test
|
||||
|
||||
xdb_searcher: xdb_searcher.h xdb_searcher.c main.c
|
||||
gcc -g -O2 -I./ xdb_searcher.c main.c -o xdb_searcher
|
||||
gcc -O2 -I./ xdb_searcher.c main.c -o xdb_searcher
|
||||
|
||||
util_test: xdb_searcher.h xdb_searcher.c util_test.c
|
||||
gcc -g -O2 -I./ xdb_searcher.c util_test.c -o util_test
|
||||
gcc -O2 -I./ xdb_searcher.c util_test.c -o util_test
|
||||
|
||||
xdb_searcher.o: xdb_searcher.c
|
||||
gcc -c -o xdb_searcher.o xdb_searcher.c
|
||||
@ -21,4 +21,4 @@ clean:
|
||||
find ./ -name xdb_searcher | xargs rm -f
|
||||
rm -rf build
|
||||
|
||||
.PHONY: all clean xdb_searcher util_test
|
||||
.PHONY: all clean xdb_searcher util_test
|
||||
|
||||
@ -6,9 +6,36 @@
|
||||
// @Author Lion <chenxin619315@gmail.com>
|
||||
// @Date 2022/06/27
|
||||
|
||||
#include "sys/time.h"
|
||||
#include "xdb_searcher.h"
|
||||
|
||||
// for Linux
|
||||
#ifdef XDB_LINUX
|
||||
#include "sys/time.h"
|
||||
#endif
|
||||
|
||||
// @Note: since 2023/10/13 to compatible with the windows system
|
||||
#ifdef XDB_WINDOWS
|
||||
#include <windows.h>
|
||||
XDB_PRIVATE(int) gettimeofday(struct timeval* tp, void* tzp) {
|
||||
time_t clock;
|
||||
struct tm tm;
|
||||
SYSTEMTIME wtm;
|
||||
GetLocalTime(&wtm);
|
||||
tm.tm_year = wtm.wYear - 1900;
|
||||
tm.tm_mon = wtm.wMonth - 1;
|
||||
tm.tm_mday = wtm.wDay;
|
||||
tm.tm_hour = wtm.wHour;
|
||||
tm.tm_min = wtm.wMinute;
|
||||
tm.tm_sec = wtm.wSecond;
|
||||
tm.tm_isdst = -1;
|
||||
clock = mktime(&tm);
|
||||
tp->tv_sec = clock;
|
||||
tp->tv_usec = wtm.wMilliseconds * 1000;
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// internal function prototype define
|
||||
XDB_PRIVATE(int) read(xdb_searcher_t *, long offset, char *, size_t length);
|
||||
|
||||
|
||||
@ -9,6 +9,8 @@ package org.lionsoul.ip2region;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SearchTest {
|
||||
@ -145,7 +147,9 @@ public class SearchTest {
|
||||
Searcher searcher = createSearcher(dbPath, cachePolicy);
|
||||
long count = 0, costs = 0, tStart = System.nanoTime();
|
||||
String line;
|
||||
final BufferedReader reader = new BufferedReader(new FileReader(srcPath));
|
||||
final Charset charset = Charset.forName("utf-8");
|
||||
final FileInputStream fis = new FileInputStream(srcPath);
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(fis, charset));
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String l = line.trim();
|
||||
String[] ps = l.split("\\|", 3);
|
||||
|
||||
Binary file not shown.
@ -37,13 +37,13 @@
|
||||
//
|
||||
// data entry structure:
|
||||
// +--------------------+-----------------------+
|
||||
// | 2bytes (for desc) | dynamic length |
|
||||
// | 2bytes (for desc) | dynamic length |
|
||||
// +--------------------+-----------------------+
|
||||
// data length whatever in bytes
|
||||
//
|
||||
// index entry structure
|
||||
// +------------+-----------+---------------+------------+
|
||||
// | 4bytes | 4bytes | 2bytes | 4 bytes |
|
||||
// | 4bytes | 4bytes | 2bytes | 4 bytes |
|
||||
// +------------+-----------+---------------+------------+
|
||||
// start ip end ip data length data ptr
|
||||
|
||||
|
||||
@ -39,13 +39,13 @@
|
||||
//
|
||||
// data entry structure:
|
||||
// +--------------------+-----------------------+
|
||||
// | 2bytes (for desc) | dynamic length |
|
||||
// | 2bytes (for desc) | dynamic length |
|
||||
// +--------------------+-----------------------+
|
||||
// data length whatever in bytes
|
||||
//
|
||||
// index entry structure
|
||||
// +------------+-----------+---------------+------------+
|
||||
// | 4bytes | 4bytes | 2bytes | 4 bytes |
|
||||
// | 4bytes | 4bytes | 2bytes | 4 bytes |
|
||||
// +------------+-----------+---------------+------------+
|
||||
// start ip end ip data length data ptr
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user