Click here to Skip to main content
15,880,469 members
Articles / Web Development / ASP.NET

Ternary Search Tree Dictionary in C#: Faster String Dictionary!

Rate me:
Please Sign up or sign in to vote.
4.57/5 (46 votes)
27 Jan 20043 min read 305.1K   4.9K   124  
A TST is a fast and memory efficient data structure for implementing a string dictionary.
// Ternary Search Tree Implementation for C# 
// 
// Copyright (c) 2004 Jonathan de Halleux
//
// This software is provided 'as-is', without any express or implied warranty. 
// 
// In no event will the authors be held liable for any damages arising from 
// the use of this software.
// Permission is granted to anyone to use this software for any purpose, 
// including commercial applications, and to alter it and redistribute it 
// freely, subject to the following restrictions:
//
//		1. The origin of this software must not be misrepresented; 
//		you must not claim that you wrote the original software. 
//		If you use this software in a product, an acknowledgment in the product 
//		documentation would be appreciated but is not required.
//
//		2. Altered source versions must be plainly marked as such, and must 
//		not be misrepresented as being the original software.
//
//		3. This notice may not be removed or altered from any source 
//		distribution.
//	
//	Ternary Search Tree Implementation for C# Library HomePage: 
//		http://www.dotnetwiki.org
//	Author: Jonathan de Halleux
//  Algorithm found in J. L. Bentley and R. Sedgewick, 
//      Fast algorithms for sorting and searching strings, 
//      in Proceedings of the Eighth Annual ACM-SIAM Symposium on Discrete Algorithms, 
//      New Orleans Louisiana, January 5-7, 
//      1997  

using System;

namespace Tst.Utility
{
	///<summary></summary>
	public sealed class TstUtility
	{
		private TstUtility()
		{}

		///<summary></summary>
		public static void Trace(TstDictionary dic, string fileName)
		{
			if (dic==null)
				throw new ArgumentNullException("dic");

			QuickGraphTraverserVisitor vis = new QuickGraphTraverserVisitor();
			TstTraverser trav = new TstTraverser();

			trav.TreeEntry += new TstDictionaryEntryEventHandler(vis.TreeEntry);
			trav.LowChild += new TstDictionaryEntryEventHandler(vis.LowChild);
			trav.EqChild += new TstDictionaryEntryEventHandler(vis.EqChild);
			trav.HighChild += new TstDictionaryEntryEventHandler(vis.HighChild);
			trav.Traverse(dic);

			vis.Render(fileName);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions