Skip to content

Commit

Permalink
1.7.8版,修改一个bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ToolGood authored Jul 20, 2017
1 parent 02acc04 commit 52868f3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ToolGood.Words/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.7.0")]
[assembly: AssemblyFileVersion("1.7.7.0")]
[assembly: AssemblyVersion("1.7.8.0")]
[assembly: AssemblyFileVersion("1.7.8.0")]
19 changes: 13 additions & 6 deletions ToolGood.Words/WordsSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,33 @@ public void SetKeywords(IDictionary<string, int> _keywords)
}

_root = root;
}

}

private void TryLinks(TrieNode node, TrieNode node2, Dictionary<TrieNode, TrieNode> links)
{
foreach (var item in node.m_values) {
if (node2 == null) {
var nd = _first[item.Key];
if (nd == null) continue;
links[item.Value] = nd;
TryLinks(item.Value, nd, links);
if (nd != null) {
links[item.Value] = nd;
TryLinks(item.Value, nd, links);
} else {
TryLinks(item.Value, null, links);
}
} else {

TrieNode tn;
if (node2.TryGetValue(item.Key, out tn)) {
links[item.Value] = tn;
TryLinks(item.Value, tn, links);
} else {
TryLinks(item.Value, null, links);
}
}
}
}
}



#endregion

Expand Down
17 changes: 12 additions & 5 deletions ToolGood.Words/internals/BaseSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ public virtual void SetKeywords(ICollection<string> _keywords)
{
var first = new TrieNode[char.MaxValue + 1];
var root = new TrieNode();

foreach (var p in _keywords) {
if (string.IsNullOrEmpty(p)) continue;

var nd = first[p[0]];
//var nd = root;
var nd = _first[p[0]];
if (nd == null) {
nd = root.Add(p[0]);
first[p[0]] = nd;
Expand All @@ -28,7 +30,7 @@ public virtual void SetKeywords(ICollection<string> _keywords)
}
nd.SetResults(p);
}
this._first = first;
this._first = first;// root.ToArray();

Dictionary<TrieNode, TrieNode> links = new Dictionary<TrieNode, TrieNode>();
foreach (var item in root.m_values) {
Expand All @@ -47,15 +49,20 @@ private void TryLinks(TrieNode node, TrieNode node2, Dictionary<TrieNode, TrieNo
foreach (var item in node.m_values) {
if (node2 == null) {
var nd = _first[item.Key];
if (nd == null) continue;
links[item.Value] = nd;
TryLinks(item.Value, nd, links);
if (nd != null) {
links[item.Value] = nd;
TryLinks(item.Value, nd, links);
} else {
TryLinks(item.Value, null, links);
}
} else {

TrieNode tn;
if (node2.TryGetValue(item.Key, out tn)) {
links[item.Value] = tn;
TryLinks(item.Value, tn, links);
} else {
TryLinks(item.Value, null, links);
}
}
}
Expand Down
29 changes: 25 additions & 4 deletions ToolGood.Words/internals/TrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ public TrieNode Add(char c)
{
TrieNode node;

if (minflag > c) { minflag = c; }
if (maxflag < c) { maxflag = c; }
if (m_values.TryGetValue(c, out node)) {
return node;
}

if (minflag > c) { minflag = c; }
if (maxflag < c) { maxflag = c; }

node = new TrieNode();
m_values[c] = node;
//m_values.Add(c, node);
Expand All @@ -51,7 +53,7 @@ public TrieNode Add(char c)

public void SetResults(string text)
{
if (End==false) {
if (End == false) {
End = true;
}
Results.Add(text);
Expand All @@ -69,7 +71,17 @@ public void Merge(TrieNode node)
}

foreach (var item in node.m_values) {
if (m_values.ContainsKey(item.Key) == false) {
//if (minflag > (uint)item.Key) {
// minflag = (uint)item.Key;
// m_values[item.Key] = item.Value;
//} else if (maxflag < (uint)item.Key) {
// maxflag = (uint)item.Key;
// m_values[item.Key] = item.Value;
//} else if (m_values.ContainsKey(item.Key) == false) {
// m_values[item.Key] = item.Value;
//}

if ( m_values.ContainsKey(item.Key) == false) {
if (minflag > item.Key) { minflag = item.Key; }
if (maxflag < item.Key) { maxflag = item.Key; }
m_values[item.Key] = item.Value;
Expand All @@ -78,6 +90,15 @@ public void Merge(TrieNode node)
}
}

public TrieNode[] ToArray()
{
TrieNode[] first = new TrieNode[char.MaxValue + 1];
foreach (var item in m_values) {
first[item.Key] = item.Value;
}
return first;
}

}

}

0 comments on commit 52868f3

Please sign in to comment.