2015-06-01 22:15:17 +03:00
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mihalkovich (for details please see \doc\copyright.txt)
|
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
2015-05-14 22:35:07 +03:00
|
|
|
using System;
|
2017-10-07 14:01:51 +03:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Collections.Generic;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
|
|
|
|
namespace SymbolTable
|
|
|
|
|
{
|
|
|
|
|
|
2015-09-28 22:28:12 +03:00
|
|
|
/// <summary>
|
2015-12-28 14:25:15 +03:00
|
|
|
/// Динамическая хеш таблица строк
|
2015-09-28 22:28:12 +03:00
|
|
|
/// </summary>
|
2018-04-16 16:17:43 +03:00
|
|
|
public class SymbolsDictionary
|
2015-09-28 22:28:12 +03:00
|
|
|
{
|
2018-04-16 16:17:43 +03:00
|
|
|
public override string ToString() => dict.SkipWhile(x => x.Key != "").Skip(1).JoinIntoString(Environment.NewLine);
|
2017-10-07 14:01:51 +03:00
|
|
|
|
2018-04-16 16:17:43 +03:00
|
|
|
public Dictionary<string, HashTableNode> dict;
|
2015-09-28 22:28:12 +03:00
|
|
|
|
2018-04-16 16:17:43 +03:00
|
|
|
public SymbolsDictionary()
|
2015-09-28 22:28:12 +03:00
|
|
|
{
|
2018-04-16 16:17:43 +03:00
|
|
|
dict = new Dictionary<string, HashTableNode>();
|
2015-09-28 22:28:12 +03:00
|
|
|
}
|
|
|
|
|
|
2018-04-16 16:17:43 +03:00
|
|
|
public SymbolsDictionary(int start_size)
|
2015-09-28 22:28:12 +03:00
|
|
|
{
|
2018-04-16 16:17:43 +03:00
|
|
|
dict = new Dictionary<string, HashTableNode>(start_size);
|
2015-09-28 22:28:12 +03:00
|
|
|
}
|
2015-05-14 22:35:07 +03:00
|
|
|
|
2015-09-28 22:28:12 +03:00
|
|
|
public void ClearTable()
|
|
|
|
|
{
|
2017-10-07 14:01:51 +03:00
|
|
|
dict.Clear();
|
2015-09-28 22:28:12 +03:00
|
|
|
}
|
2015-05-14 22:35:07 +03:00
|
|
|
|
2017-10-07 14:01:51 +03:00
|
|
|
public HashTableNode Add(string name)
|
2015-09-28 22:28:12 +03:00
|
|
|
{
|
2017-10-07 14:01:51 +03:00
|
|
|
HashTableNode node = null;
|
|
|
|
|
var b = dict.TryGetValue(name, out node);
|
|
|
|
|
if (!b)
|
|
|
|
|
{
|
|
|
|
|
node = new HashTableNode(name);
|
|
|
|
|
dict[name] = node;
|
|
|
|
|
}
|
|
|
|
|
return node;
|
2015-09-28 22:28:12 +03:00
|
|
|
}
|
2015-05-14 22:35:07 +03:00
|
|
|
|
2017-10-07 14:01:51 +03:00
|
|
|
public HashTableNode Find(string name)
|
2015-09-28 22:28:12 +03:00
|
|
|
{
|
2017-10-07 14:01:51 +03:00
|
|
|
HashTableNode node = null;
|
|
|
|
|
dict.TryGetValue(name, out node);
|
|
|
|
|
return node;
|
2015-09-28 22:28:12 +03:00
|
|
|
}
|
|
|
|
|
}
|
2015-05-14 22:35:07 +03:00
|
|
|
}
|