Skip to content
Permalink
Browse files

StrTrie - use ReadBlock instead of ReadLine in Load

  • Loading branch information...
bobbymcr committed Apr 4, 2019
1 parent c2c8fa3 commit 8c8255fdca447d12919fb5296454e4ce05ff3541
Showing with 36 additions and 9 deletions.
  1. +33 −9 src/Words.Core/StrTrie.cs
  2. +3 −0 src/Words.Core/Words.Core.csproj
@@ -31,22 +31,46 @@ public static StrTrie Load(Stream stream)
using (StreamReader reader = new StreamReader(stream))
{
StrTrie trie = new StrTrie();
string line;
char[] buffer = new char[1024];
Str value = default(Str);
bool skip = false;
int length;
do
{
line = reader.ReadLine();
if ((line != null) && (line.Length > 2) && (line.Length < 13))
length = reader.ReadBlock(buffer, 0, buffer.Length);
for (int i = 0; i < length; ++i)
{
Str value = default(Str);
foreach (char c in line)
char c = buffer[i];
switch (c)
{
value = value.Append((Ch)(c - 'A' + 1));
}
case '\r':
case '\n':
if (!skip && (value.Length > 2))
{
trie.Add(value);
}

value = default(Str);
skip = false;
break;
default:
if (!skip)
{
if (value.Length == 12)
{
skip = true;
}
else
{
value = value.Append((Ch)(c - 'A' + 1));
}
}

trie.Add(value);
break;
}
}
}
while (line != null);
while (length > 0);

return trie;
}
@@ -2,4 +2,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.2" />
</ItemGroup>
</Project>

0 comments on commit 8c8255f

Please sign in to comment.
You can’t perform that action at this time.