doc: 文档统一格式化

This commit is contained in:
Argo Zhang 2025-11-21 09:03:37 +08:00
parent 75d944eaf7
commit 002c482db3
10 changed files with 47 additions and 17 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2023 The Ip2Region Authors. All rights reserved. // Copyright 2023 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style // Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// @Author Alan <lzh.shap@gmail.com> // @Author Alan <lzh.shap@gmail.com>

View File

@ -10,11 +10,6 @@ namespace IP2Region.Net.Internal.Abstractions;
internal abstract class AbstractCacheStrategy internal abstract class AbstractCacheStrategy
{ {
protected const int HeaderInfoLength = 256;
protected const int VectorIndexRows = 256;
protected const int VectorIndexCols = 256;
protected const int VectorIndexSize = 8;
protected readonly FileStream XdbFileStream; protected readonly FileStream XdbFileStream;
private const int BufferSize = 4096; private const int BufferSize = 4096;

View File

@ -8,9 +8,9 @@ using IP2Region.Net.Internal.Abstractions;
namespace IP2Region.Net.Internal; namespace IP2Region.Net.Internal;
internal class ContentCacheStrategy : AbstractCacheStrategy class ContentCacheStrategy : AbstractCacheStrategy
{ {
private readonly ReadOnlyMemory<byte> _cacheData; readonly ReadOnlyMemory<byte> _cacheData;
public ContentCacheStrategy(string xdbPath) : base(xdbPath) public ContentCacheStrategy(string xdbPath) : base(xdbPath)
{ {

View File

@ -8,6 +8,7 @@ using IP2Region.Net.Internal.Abstractions;
namespace IP2Region.Net.Internal; namespace IP2Region.Net.Internal;
internal class FileCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath) class FileCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath)
{ {
} }

View File

@ -10,7 +10,12 @@ namespace IP2Region.Net.Internal;
internal class VectorIndexCacheStrategy : AbstractCacheStrategy internal class VectorIndexCacheStrategy : AbstractCacheStrategy
{ {
private readonly ReadOnlyMemory<byte> _vectorIndex; const int HeaderInfoLength = 256;
const int VectorIndexRows = 256;
const int VectorIndexCols = 256;
const int VectorIndexSize = 8;
readonly ReadOnlyMemory<byte> _vectorIndex;
public VectorIndexCacheStrategy(string xdbPath) : base(xdbPath) public VectorIndexCacheStrategy(string xdbPath) : base(xdbPath)
{ {

View File

@ -1,15 +1,20 @@
namespace IP2Region.Net.XDB; namespace IP2Region.Net.XDB;
/// <summary>
/// 缓存策略枚举
/// </summary>
public enum CachePolicy public enum CachePolicy
{ {
/// <summary> /// <summary>
/// no cache /// no cache
/// </summary> /// </summary>
File, File,
/// <summary> /// <summary>
/// cache vector index , reduce the number of IO operations /// cache vector index , reduce the number of IO operations
/// </summary> /// </summary>
VectorIndex, VectorIndex,
/// <summary> /// <summary>
/// default cache policy , cache whole xdb file /// default cache policy , cache whole xdb file
/// </summary> /// </summary>

View File

@ -13,29 +13,47 @@ using System.Text;
namespace IP2Region.Net.XDB; namespace IP2Region.Net.XDB;
/// <summary>
/// <see cref="ISearcher"/> 实现类
/// </summary>
public class Searcher : ISearcher public class Searcher : ISearcher
{ {
private readonly AbstractCacheStrategy _cacheStrategy; private readonly AbstractCacheStrategy _cacheStrategy;
/// <summary>
/// <inheritdoc/>
/// </summary>
public int IoCount => _cacheStrategy.IoCount; public int IoCount => _cacheStrategy.IoCount;
/// <summary>
/// <inheritdoc/>
/// </summary>
public Searcher(CachePolicy cachePolicy, string dbPath) public Searcher(CachePolicy cachePolicy, string dbPath)
{ {
var factory = new CacheStrategyFactory(dbPath); var factory = new CacheStrategyFactory(dbPath);
_cacheStrategy = factory.CreateCacheStrategy(cachePolicy); _cacheStrategy = factory.CreateCacheStrategy(cachePolicy);
} }
/// <summary>
/// <inheritdoc/>
/// </summary>
public string? Search(string ipStr) public string? Search(string ipStr)
{ {
var ipAddress = IPAddress.Parse(ipStr); var ipAddress = IPAddress.Parse(ipStr);
return Search(ipAddress); return Search(ipAddress);
} }
/// <summary>
/// <inheritdoc/>
/// </summary>
public string? Search(IPAddress ipAddress) public string? Search(IPAddress ipAddress)
{ {
return SearchCore(ipAddress.GetAddressBytes()); return SearchCore(ipAddress.GetAddressBytes());
} }
/// <summary>
/// <inheritdoc/>
/// </summary>
public string? Search(uint ipAddress) public string? Search(uint ipAddress)
{ {
var bytes = BitConverter.GetBytes(ipAddress); var bytes = BitConverter.GetBytes(ipAddress);

View File

@ -5,6 +5,9 @@ using System.Runtime.InteropServices;
namespace IP2Region.Net.XDB; namespace IP2Region.Net.XDB;
/// <summary>
/// 工具类
/// </summary>
public static class Util public static class Util
{ {
public static uint IpAddressToUInt32(string ipAddress) public static uint IpAddressToUInt32(string ipAddress)

View File

@ -1,5 +1,8 @@
namespace IP2Region.Net.XDB; namespace IP2Region.Net.XDB;
/// <summary>
/// XdbVersion 结构体
/// </summary>
public struct XdbVersion public struct XdbVersion
{ {
/// <summary> /// <summary>