doc: 文档统一格式化
This commit is contained in:
parent
75d944eaf7
commit
002c482db3
|
|
@ -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
|
||||
// license that can be found in the LICENSE file.
|
||||
// @Author Alan <lzh.shap@gmail.com>
|
||||
|
|
|
|||
|
|
@ -10,11 +10,6 @@ namespace IP2Region.Net.Internal.Abstractions;
|
|||
|
||||
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;
|
||||
private const int BufferSize = 4096;
|
||||
|
||||
|
|
@ -51,4 +46,4 @@ internal abstract class AbstractCacheStrategy
|
|||
|
||||
return new ReadOnlyMemory<byte>(buffer, 0, totalBytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,4 @@ internal class CacheStrategyFactory(string xdbPath)
|
|||
CachePolicy.VectorIndex => new VectorIndexCacheStrategy(xdbPath),
|
||||
_ => new FileCacheStrategy(xdbPath),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ using IP2Region.Net.Internal.Abstractions;
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -23,4 +23,4 @@ internal class ContentCacheStrategy : AbstractCacheStrategy
|
|||
{
|
||||
return _cacheData.Slice(offset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using IP2Region.Net.Internal.Abstractions;
|
|||
|
||||
namespace IP2Region.Net.Internal;
|
||||
|
||||
internal class FileCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath)
|
||||
class FileCacheStrategy(string xdbPath) : AbstractCacheStrategy(xdbPath)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,16 @@ namespace IP2Region.Net.Internal;
|
|||
|
||||
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)
|
||||
{
|
||||
var vectorLength = VectorIndexRows * VectorIndexCols * VectorIndexSize;
|
||||
_vectorIndex = base.GetData(HeaderInfoLength, vectorLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,22 @@
|
|||
namespace IP2Region.Net.XDB;
|
||||
|
||||
/// <summary>
|
||||
/// 缓存策略枚举
|
||||
/// </summary>
|
||||
public enum CachePolicy
|
||||
{
|
||||
/// <summary>
|
||||
/// no cache
|
||||
/// </summary>
|
||||
File,
|
||||
|
||||
/// <summary>
|
||||
/// cache vector index , reduce the number of IO operations
|
||||
/// </summary>
|
||||
VectorIndex,
|
||||
|
||||
/// <summary>
|
||||
/// default cache policy , cache whole xdb file
|
||||
/// </summary>
|
||||
Content
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,29 +13,47 @@ using System.Text;
|
|||
|
||||
namespace IP2Region.Net.XDB;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="ISearcher"/> 实现类
|
||||
/// </summary>
|
||||
public class Searcher : ISearcher
|
||||
{
|
||||
private readonly AbstractCacheStrategy _cacheStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public int IoCount => _cacheStrategy.IoCount;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public Searcher(CachePolicy cachePolicy, string dbPath)
|
||||
{
|
||||
var factory = new CacheStrategyFactory(dbPath);
|
||||
_cacheStrategy = factory.CreateCacheStrategy(cachePolicy);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public string? Search(string ipStr)
|
||||
{
|
||||
var ipAddress = IPAddress.Parse(ipStr);
|
||||
return Search(ipAddress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public string? Search(IPAddress ipAddress)
|
||||
{
|
||||
return SearchCore(ipAddress.GetAddressBytes());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc/>
|
||||
/// </summary>
|
||||
public string? Search(uint ipAddress)
|
||||
{
|
||||
var bytes = BitConverter.GetBytes(ipAddress);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ using System.Runtime.InteropServices;
|
|||
|
||||
namespace IP2Region.Net.XDB;
|
||||
|
||||
/// <summary>
|
||||
/// 工具类
|
||||
/// </summary>
|
||||
public static class Util
|
||||
{
|
||||
public static uint IpAddressToUInt32(string ipAddress)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
namespace IP2Region.Net.XDB;
|
||||
namespace IP2Region.Net.XDB;
|
||||
|
||||
/// <summary>
|
||||
/// XdbVersion 结构体
|
||||
/// </summary>
|
||||
public struct XdbVersion
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Reference in New Issue