diff --git a/build/version.props b/build/version.props
index ef8645d..f799351 100644
--- a/build/version.props
+++ b/build/version.props
@@ -2,7 +2,7 @@
0.6.0
- 0.7.5
+ 0.8.0
\ No newline at end of file
diff --git a/src/RDBCli/Commands/MemoryCommand.cs b/src/RDBCli/Commands/MemoryCommand.cs
index 17cd3fa..231e788 100644
--- a/src/RDBCli/Commands/MemoryCommand.cs
+++ b/src/RDBCli/Commands/MemoryCommand.cs
@@ -22,6 +22,7 @@ internal class MemoryCommand : Command
private static Option _sepPrefixCountOption = CommonCLIOptions.SepPrefixCountOption();
private static Option _isPermanentOption = CommonCLIOptions.IsPermanentOption();
private static Option _isIgnoreFieldOfLargestElemOption = CommonCLIOptions.IsIgnoreFieldOfLargestElemOption();
+ private static Option _keySuffixEnableOption = CommonCLIOptions.KeySuffixEnableOption();
private static Argument _fileArg = CommonCLIArguments.FileArgument();
public MemoryCommand()
@@ -38,6 +39,7 @@ public MemoryCommand()
this.AddOption(_sepPrefixCountOption);
this.AddOption(_isPermanentOption);
this.AddOption(_isIgnoreFieldOfLargestElemOption);
+ this.AddOption(_keySuffixEnableOption);
this.AddArgument(_fileArg);
this.SetHandler((InvocationContext context) =>
@@ -54,7 +56,7 @@ private void Do(InvocationContext context, CommandOptions options)
var cb = new CliCB.MemoryCallback(options.IsIgnoreFole ?? false);
var rdbDataInfo = cb.GetRdbDataInfo();
- var counter = new RdbDataCounter(rdbDataInfo.Records, options.Separators, options.SepPrefixCount);
+ var counter = new RdbDataCounter(rdbDataInfo.Records, options.Separators, options.SepPrefixCount, options.keySuffixEnable ?? false);
var task = counter.Count();
console.WriteLine($"");
@@ -159,6 +161,7 @@ private class CommandOptions
public string Separators { get; set; }
public int SepPrefixCount { get; set; }
public bool? IsIgnoreFole { get; set; }
+ public bool? keySuffixEnable { get; set; }
public static CommandOptions FromContext(InvocationContext context)
@@ -175,6 +178,7 @@ public static CommandOptions FromContext(InvocationContext context)
var sepPrefixCount = context.ParseResult.GetValueForOption(_sepPrefixCountOption);
var isPermanent = context.ParseResult.GetValueForOption(_isPermanentOption);
var isIgnoreFole = context.ParseResult.GetValueForOption(_isIgnoreFieldOfLargestElemOption);
+ var keySuffixEnable = context.ParseResult.GetValueForOption(_keySuffixEnableOption);
var parseFilter = new RDBParser.ParserFilter()
{
@@ -195,6 +199,7 @@ public static CommandOptions FromContext(InvocationContext context)
Separators = sep,
SepPrefixCount = sepPrefixCount,
IsIgnoreFole = isIgnoreFole,
+ keySuffixEnable = keySuffixEnable,
};
}
}
@@ -338,6 +343,16 @@ public static Option> KeyPrefixesOption()
return option;
}
+ public static Option KeySuffixEnableOption()
+ {
+ Option option =
+ new Option(
+ aliases: new string[] { "--key-suffix-enable" },
+ description: "Use the key suffix as the key prefix.");
+
+ return option;
+ }
+
public static Option SeparatorsOption()
{
Option option =
diff --git a/src/RDBCli/Stats/RdbDataCounter.cs b/src/RDBCli/Stats/RdbDataCounter.cs
index 2cd7b6f..97a64a9 100644
--- a/src/RDBCli/Stats/RdbDataCounter.cs
+++ b/src/RDBCli/Stats/RdbDataCounter.cs
@@ -19,8 +19,9 @@ internal class RdbDataCounter
private readonly BlockingCollection _records;
private readonly int _sepCount;
+ private readonly bool _keySuffixEnable;
- public RdbDataCounter(BlockingCollection records, string separators = "", int sepCount = -1)
+ public RdbDataCounter(BlockingCollection records, string separators = "", int sepCount = -1, bool keySuffixEnable = false)
{
this._records = records;
this._largestRecords = new PriorityQueue();
@@ -36,11 +37,12 @@ public RdbDataCounter(BlockingCollection records, string separat
}
_sepCount = sepCount > 0 ? sepCount : 1;
+ _keySuffixEnable = keySuffixEnable;
}
public Task Count()
{
- System.Threading.CancellationTokenSource cts = new System.Threading.CancellationTokenSource();
+ System.Threading.CancellationTokenSource cts = new();
var task = Task.Factory.StartNew(() =>
{
while (!_records.IsCompleted)
@@ -192,23 +194,47 @@ private List GetPrefixes(string s)
var span = s.AsSpan();
- var sepIdx = span.IndexOfAny(_separators);
+ if (!_keySuffixEnable)
+ {
+ var sepIdx = span.IndexOfAny(_separators);
+
+ if (sepIdx < 0) res.Add(s);
+
+ while (sepIdx > -1)
+ {
+ var str = new string(span[..(sepIdx + 1)]);
- if (sepIdx < 0) res.Add(s);
+ if (res.Any())
+ {
+ str = string.Concat(res[^1], str);
+ }
- while (sepIdx > -1)
+ res.Add(str);
+
+ span = span[(sepIdx + 1)..];
+ sepIdx = span.IndexOfAny(_separators);
+ }
+ }
+ else
{
- var str = new string(span[..(sepIdx + 1)]);
+ var sepIdx = span.LastIndexOfAny(_separators);
- if (res.Any())
+ if (sepIdx < 0) res.Add(s);
+
+ while (sepIdx > -1)
{
- str = string.Concat(res[^1], str);
- }
+ var str = new string(span[(sepIdx + 1)..]) + span[sepIdx];
- res.Add(str);
+ if (res.Any())
+ {
+ str = string.Concat(res[^1], str);
+ }
- span = span[(sepIdx + 1)..];
- sepIdx = span.IndexOfAny(_separators);
+ res.Add(str);
+
+ span = span[..sepIdx];
+ sepIdx = span.LastIndexOfAny(_separators);
+ }
}
for (int i = 0; i < res.Count; i++)