2
// <copyright see="prj:///doc/copyright.txt"/>
3
// <license see="prj:///doc/license.txt"/>
4
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
5
// <version>$Revision: 4482 $</version>
9
using System.Globalization;
11
namespace ICSharpCode.OldNRefactory.Parser
14
/// This class implements a keyword map. It implements a digital search trees (tries) to find
17
internal class LookupTable
19
Node root = new Node(-1, null);
24
/// The number of elements in the table
33
/// Inserts an int in the tree, under keyword
35
public int this[string keyword] {
40
keyword = keyword.ToUpper(CultureInfo.InvariantCulture);
43
for (int i = 0; i < keyword.Length; ++i) {
44
int index = ((int)keyword[i]) % 256;
45
next = next.leaf[index];
51
if (keyword == next.word) {
62
keyword = keyword.ToUpper(CultureInfo.InvariantCulture);
67
// insert word into the tree
68
for (int i = 0; i < keyword.Length; ++i) {
69
int index = ((int)keyword[i]) % 256; // index of curchar
70
bool d = keyword[i] == '\\';
72
next = next.leaf[index]; // get node to this index
74
if (next == null) { // no node created -> insert word here
75
node.leaf[index] = new Node(value, keyword);
79
if (next.word != null && next.word.Length != i) { // node there, take node content and insert them again
80
string tmpword = next.word; // this word will be inserted 1 level deeper (better, don't need too much
81
int tmpval = next.val; // string comparisons for finding.)
84
this[tmpword] = tmpval;
87
if (i == keyword.Length - 1) { // end of keyword reached, insert node there, if a node was here it was
88
next.word = keyword; // reinserted, if it has the same length (keyword EQUALS this word) it will be overwritten
99
/// Creates a new instance of <see cref="LookupTable"/>
101
public LookupTable(bool casesensitive)
103
this.casesensitive = casesensitive;
108
public Node(int val, string word)
117
public Node[] leaf = new Node[256];