Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
/Users/gmamaladze/github/trienet/SampleConsoleApp/obj/Debug/SampleConsoleApp.csprojResolveAssemblyReference.cache
/Users/gmamaladze/github/trienet/SampleConsoleApp/obj/Debug/SampleConsoleApp.csproj.CoreCompileInputs.cache
/Users/gmamaladze/github/trienet/SampleConsoleApp/obj/Debug/Gma.DataStructures.StringSearch.SampleConsoleApp.exe
/Users/gmamaladze/github/trienet/SampleConsoleApp/obj/Debug/Gma.DataStructures.StringSearch.SampleConsoleApp.pdb
/Users/gmamaladze/github/trienet/SampleConsoleApp/obj/Debug/Gma.DataStructures.StringSearch.SampleConsoleApp.pdb
Binary file not shown.
73 changes: 71 additions & 2 deletions TrieNet.Test/BaseTrieTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using NUnit.Framework;

using System.Linq;
namespace Gma.DataStructures.StringSearch.Test
{
[TestFixture]
Expand Down Expand Up @@ -64,7 +64,7 @@ public virtual void Setup()
"comolecule",
"comodato",
"comodato",
"cognoscibility"
"cognoscibility",
};

[TestCase("d", new[] { 0, 1, 2 })]
Expand Down Expand Up @@ -460,6 +460,75 @@ public void Test(string query, IEnumerable<int> expected)
CollectionAssert.AreEquivalent(expected, actual);
}

/// <summary>
/// test when a key is a part of a longer key
/// this test make sure that after the shorter key deletion
/// the longer key remain unchanged
/// while the shorter key instance is removed
/// </summary>
/// <param name="shorterKey"></param>
/// <param name="LongerKey">it takes the longer key to validates if the longer key remained with no change</param>
///
[TestCase("procreate", "procreation")]
[TestCase("protest", "protestant")]
public void TestShorterKeyRemove(string shorterKey, string longerKey)
{
Trie.Add(shorterKey, 1000);
Trie.Add(longerKey, 1001);
int[] shorterKeyBeforeRemoveValues = Trie.Retrieve(shorterKey).ToArray();
int[] longerKeyBeforeRemoveValues = Trie.Retrieve(longerKey).ToArray();
Trie.Remove(shorterKey);
int[] shorterKeyAfterRemoveValues = Trie.Retrieve(shorterKey).ToArray();
int[] longerKeyAfterRemoveValues = Trie.Retrieve(longerKey).ToArray();
Assert.Less(shorterKeyAfterRemoveValues.Length , shorterKeyBeforeRemoveValues.Length);
Assert.AreEqual(longerKeyAfterRemoveValues.Length, longerKeyBeforeRemoveValues.Length);
}

[TestCase("testability", "test")]
[TestCase("robber", "rob")]
[TestCase("rejoiceful", "rejoice")]
public void TestLongerKeyRemove(string longerKey, string shorterKey)
{
Trie.Add(shorterKey, 1002);
Trie.Add(longerKey, 1003);
int[] shorterKeyBeforeRemoveValues = Trie.Retrieve(shorterKey).ToArray();
int[] longerKeyBeforeRemoveValues = Trie.Retrieve(longerKey).ToArray();
Trie.Remove(longerKey);
int[] shorterKeyAfterRemoveValues = Trie.Retrieve(shorterKey).ToArray();
int[] longerKeyAfterRemoveValues = Trie.Retrieve(longerKey).ToArray();
Assert.Less(shorterKeyAfterRemoveValues.Length, shorterKeyBeforeRemoveValues.Length);
Assert.Less(longerKeyAfterRemoveValues.Length, longerKeyBeforeRemoveValues.Length);
}

[TestCase("zoo")]
[TestCase("z")]
public void TestUniqueKeyRemove(string key)
{
Trie.Add(key, 1004);
Trie.Remove(key);
int[] keyAfterRemoveValues = Trie.Retrieve(key).ToArray();
Assert.AreEqual(keyAfterRemoveValues.Length, 0);

}

[TestCase("unexistedkey1")]
[TestCase("unexistedkey2")]
public void TestUnExistedKeyRemove(string key)
{
Trie.Remove(key);
}

[TestCase("protest", new int[] { 1005, 1006 })]
[TestCase("probablility", new int[] { 1007, 1008 })]
[TestCase("prepare", new int[] { 1009, 1010 })]
public void TestUpdate(string key, int[] values)
{
Trie.Add(key, 1011);
Trie.Update(key, values);
foreach(int value in values)
Assert.Contains(value, Trie.Retrieve(key).ToArray());
}

[Test]
public void ExhaustiveAddTimeMeasurement()
{
Expand Down
11 changes: 11 additions & 0 deletions TrieNet.Test/Performance/FakeTrie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code is distributed under MIT license. Copyright (c) 2013 George Mamaladze
// See license.txt or http://opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;

namespace Gma.DataStructures.StringSearch.Test
Expand Down Expand Up @@ -28,5 +29,15 @@ public void Add(string key, T value)
var keyValPair = new KeyValuePair<string, T>(key, value);
m_Stack.Push(keyValPair);
}

public void Remove(string key)
{
throw new NotImplementedException();
}

public void Update(string key, T[] values)
{
throw new NotImplementedException();
}
}
}
3 changes: 3 additions & 0 deletions TrieNet.Test/TrieNet.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
<Name>TrieNet</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 2 additions & 0 deletions TrieNet/ITrie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public interface ITrie<TValue>
{
IEnumerable<TValue> Retrieve(string query);
void Add(string key, TValue value);
void Remove(string key);
void Update(string key, TValue[] values);
}
}
3 changes: 2 additions & 1 deletion TrieNet/TrieNet.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
Expand All @@ -16,6 +16,7 @@
<PackageIconUrl>https://raw.githubusercontent.com/gmamaladze/trienet/master/img/trienet.png</PackageIconUrl>
<PackageTags>ata-structures dotnet algorithms search</PackageTags>
<Version>1.0.4</Version>
<NetStandardImplicitPackageVersion>2.0.0</NetStandardImplicitPackageVersion>
</PropertyGroup>

</Project>
11 changes: 11 additions & 0 deletions TrieNet/_PatriciaTrie/PatriciaSuffixTrie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code is distributed under MIT license. Copyright (c) 2013 George Mamaladze
// See license.txt or http://opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -51,5 +52,15 @@ private static IEnumerable<StringPartition> GetAllSuffixes(int minSuffixLength,
yield return new StringPartition(word, i);
}
}

public void Remove(string key)
{
throw new NotImplementedException();
}

public void Update(string key, TValue[] values)
{
throw new NotImplementedException();
}
}
}
10 changes: 10 additions & 0 deletions TrieNet/_PatriciaTrie/PatriciaTrie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,15 @@ internal override void Add(StringPartition keyRest, TValue value)
{
GetOrCreateChild(keyRest, value);
}

public void Remove(string key)
{
throw new NotImplementedException();
}

public void Update(string key, TValue[] values)
{
throw new NotImplementedException();
}
}
}
25 changes: 25 additions & 0 deletions TrieNet/_PatriciaTrie/PatriciaTrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,30 @@ public override string ToString()
Values().Count(),
String.Join(";", m_Children.Keys));
}

protected override void RemoveValue()
{
throw new NotImplementedException();
}

protected override bool BelongsToLongerKey()
{
throw new NotImplementedException();
}

protected override bool HasValue()
{
throw new NotImplementedException();
}

protected override void RemoveChild(string key, int childPosition)
{
throw new NotImplementedException();
}

public override void UpdateValues(TValue[] values)
{
throw new NotImplementedException();
}
}
}
11 changes: 11 additions & 0 deletions TrieNet/_Trie/ConcurrentTrie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code is distributed under MIT license. Copyright (c) 2013 George Mamaladze
// See license.txt or http://opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;

namespace Gma.DataStructures.StringSearch
Expand All @@ -15,5 +16,15 @@ public void Add(string key, TValue value)
{
Add(key, 0, value);
}

public void Remove(string key)
{
throw new NotImplementedException();
}

public void Update(string key, TValue[] values)
{
throw new NotImplementedException();
}
}
}
25 changes: 25 additions & 0 deletions TrieNet/_Trie/ConcurrentTrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,30 @@ protected override TrieNodeBase<TValue> GetChildOrNull(string query, int positio
? childNode
: null;
}

protected override void RemoveValue()
{
throw new NotImplementedException();
}

protected override bool BelongsToLongerKey()
{
throw new NotImplementedException();
}

protected override bool HasValue()
{
throw new NotImplementedException();
}

protected override void RemoveChild(string key, int childPosition)
{
throw new NotImplementedException();
}

public override void UpdateValues(TValue[] values)
{
throw new NotImplementedException();
}
}
}
11 changes: 11 additions & 0 deletions TrieNet/_Trie/SuffixTrie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code is distributed under MIT license. Copyright (c) 2013 George Mamaladze
// See license.txt or http://opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -45,5 +46,15 @@ private static IEnumerable<string> GetAllSuffixes(int minSuffixLength, string wo
yield return partition.ToString();
}
}

public void Remove(string key)
{
throw new NotImplementedException();
}

public void Update(string key, T[] values)
{
throw new NotImplementedException();
}
}
}
11 changes: 11 additions & 0 deletions TrieNet/_Trie/Trie.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This code is distributed under MIT license. Copyright (c) 2013 George Mamaladze
// See license.txt or http://opensource.org/licenses/mit-license.php
using System;
using System.Collections.Generic;

namespace Gma.DataStructures.StringSearch
Expand All @@ -15,5 +16,15 @@ public void Add(string key, TValue value)
{
Add(key, 0, value);
}

public void Remove(string key)
{
Remove(key, 0);
}

public void Update(string key, TValue[] values)
{
Update(key, 0, values);
}
}
}
27 changes: 27 additions & 0 deletions TrieNet/_Trie/TrieNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,32 @@ protected override void AddValue(TValue value)
{
m_Values.Enqueue(value);
}

protected override void RemoveValue()
{
m_Values.Clear();
}

protected override bool BelongsToLongerKey()
{
return m_Children.Count > 0;
}

protected override bool HasValue()
{
return m_Values.Count > 0;
}

protected override void RemoveChild(string key, int childPosition)
{
m_Children.Remove(key[childPosition]);
}

public override void UpdateValues(TValue[] values)
{
m_Values.Clear();
foreach (TValue value in values)
AddValue(value);
}
}
}
Loading