本文整理汇总了C#中HashTable类的典型用法代码示例。如果您正苦于以下问题:C# HashTable类的具体用法?C# HashTable怎么用?C# HashTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashTable类属于命名空间,在下文中一共展示了HashTable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Add_OneItem
public void Add_OneItem()
{
HashTable<string, int> hashTable = new HashTable<string, int>();
hashTable.Add("Pesho", 6);
Assert.IsTrue(hashTable.Count == 1);
}
开发者ID:elibk,项目名称:DSA,代码行数:7,代码来源:HashTableTest.cs
示例2: Main
private static void Main()
{
const int elementsCount = 30000;
var rand = new Random();
var beforeHash = GC.GetTotalMemory(true);
var hashTest = new HashTable<int, int>();
var stopWatch = new Stopwatch();
stopWatch.Start();
for (var i = 0; i < elementsCount; i++)
{
var currentNum = rand.Next();
hashTest.Add(currentNum, currentNum);
hashTest.Contains(currentNum);
}
stopWatch.Stop();
var afterHash = GC.GetTotalMemory(true);
Console.WriteLine(
"The time needed to add {0} items in the HashTalbe was {1}",
hashTest.Count,
stopWatch.Elapsed);
Console.WriteLine("Current capacity is {0} items", hashTest.Capacity);
Console.WriteLine("{0} kb used", (afterHash - beforeHash) / 1024);
}
开发者ID:hrist0stoichev,项目名称:Telerik-Homeworks,代码行数:28,代码来源:HashTableImplementation.cs
示例3: Main
public static void Main()
{
var table = new HashTable<int, int>();
table.Add(1, 11);
table.Add(2, 12);
table.Add(3, 13);
table.Add(4, 14);
table.Add(5, 15);
table.Add(6, 16);
table.Add(7, 17);
table.Add(8, 18);
//var four = table.Find(4);
Console.WriteLine();
Console.WriteLine(table.Count);
table.Remove(4);
table.Remove(4);
Console.WriteLine();
Console.WriteLine(table.Count);
Console.WriteLine();
var secondfour = table.Find(4);
Console.WriteLine(table.Count);
Console.WriteLine(secondfour);
Console.WriteLine(table[1]);
table[1] = 15;
Console.WriteLine(table[1]);
Console.WriteLine(string.Join(", ", table.Keys));
}
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:28,代码来源:Startup.cs
示例4: RemoveShouldReturnFalseIfTheKeyIsNotFound
public void RemoveShouldReturnFalseIfTheKeyIsNotFound()
{
var testHashTable = new HashTable<int, int>();
testHashTable.Set(1, 1);
var removed = testHashTable.Remove(2);
Assert.AreEqual(false, removed);
}
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs
示例5: Main
static void Main()
{
string input = Console.ReadLine();
var phonebook = new HashTable<string, string>();
while (input != "search")
{
string[] record = input.Split( new char[] {'-'}, StringSplitOptions.RemoveEmptyEntries);
phonebook.AddOrReplace(record[0], record[1]);
input = Console.ReadLine();
}
input = Console.ReadLine();
while (input != "")
{
if (phonebook.ContainsKey(input))
{
Console.WriteLine("{0} -> {1}", input, phonebook[input]);
}
else
{
Console.WriteLine("Contact {0} does not exist.", input);
}
input = Console.ReadLine();
}
}
开发者ID:pkanev,项目名称:Data.Structures,代码行数:28,代码来源:PhonebookMain.cs
示例6: SetShouldReplaceTheExistingValueWithTheNewOneWhenKeyExists
public void SetShouldReplaceTheExistingValueWithTheNewOneWhenKeyExists()
{
var testHashTable = new HashTable<int, int>();
testHashTable.Set(1, 1);
testHashTable.Set(1, 2);
Assert.AreEqual(2, testHashTable[1]);
}
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs
示例7: HashTableShouldWorkProperlyWithCollectionValues
public void HashTableShouldWorkProperlyWithCollectionValues()
{
var testHashTable = new HashTable<int, List<int>>();
testHashTable.Set(1, new List<int> {1, 2, 3});
Assert.AreEqual(3, testHashTable[1][2]);
}
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs
示例8: AddingByIndexShouldAddCorrectly
public void AddingByIndexShouldAddCorrectly()
{
var table = new HashTable<string, int>();
table["pesho"] = 2;
Assert.AreEqual(2, table["pesho"]);
}
开发者ID:NikitoG,项目名称:TelerikAcademyHomeworks,代码行数:7,代码来源:HashTableTests.cs
示例9: Main
static void Main()
{
HashTable<string, int> hash = new HashTable<string, int>(32);
hash.Add("Pesho", 6);
hash.Add("Pesho", 6);
hash.Add("Pesho", 3);
hash.Add("Gosho", 9);
hash.Add("Tosho", 4);
hash.Add("Viko", 7);
hash.Add("Viko", 7);
hash.Add("high 5", 7);
hash["Johnatan"] = 3333;
hash["viko"] = 1111111;
hash.Remove("Tosho");
foreach (var item in hash)
{
Console.WriteLine("{0} -> {1}", item.Key, item.Value);
}
hash.Clear();
foreach (var item in hash)
{
Console.WriteLine("{0} -> {1}", item.Key, item.Value);
}
}
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:28,代码来源:Program.cs
示例10: Main
public static void Main()
{
var hashtable = new HashTable<int, string>();
hashtable.Add(5, "five");
hashtable.Add(3, "tree");
hashtable.Add(-6, "minus six");
Console.WriteLine(hashtable.Find(-6));
Console.WriteLine("All elements");
foreach (var item in hashtable)
{
Console.WriteLine("Key: {0} => Value: {1}", item.Key, item.Value);
}
hashtable.Remove(3);
Console.WriteLine("3 removed from table");
try
{
Console.WriteLine("Searching for 3 in table");
hashtable.Find(3);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.WriteLine("Hash table has {0} elements", hashtable.Count);
}
开发者ID:Moiraines,项目名称:TelerikAcademy,代码行数:27,代码来源:StartUp.cs
示例11: Main
/* Task 4:
* Implement the data structure "hash table" in a class HashTable<K,T>.
* Keep the data in array of lists of key-value pairs (LinkedList<KeyValuePair<K,T>>[])
* with initial capacity of 16. When the hash table load runs over 75%, perform resizing to 2
* times larger capacity. Implement the following methods and properties: Add(key, value), Find(key)value,
* Remove( key), Count, Clear(), this[], Keys. Try to make the hash table to support iterating over its elements
* with foreach.
*/
//Few functionalities are missing. If I have time I will add them as well.
static void Main(string[] args)
{
var hashTable = new HashTable<string, int>();
for (int i = 0; i < 100; i++)
{
hashTable.Add("Entri" + i, i);
}
Console.WriteLine(hashTable.Count());
Console.WriteLine(hashTable.Find("Entri50"));
for (int i = 50; i < 100; i++)
{
hashTable.Remove("Entri" + i);
}
//Will throw an exception
//Console.WriteLine(hashTable.Find("Entri50"));
var keys = hashTable.Keys();
foreach (var key in keys)
{
Console.WriteLine(key);
}
hashTable.Clear();
Console.WriteLine(hashTable.Count());
}
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:41,代码来源:ImplementingHashTable.cs
示例12: DeleteTest
public void DeleteTest()
{
HashTable ht = new HashTable(35);
ht.AddToHashTable("GUITAR");
ht.DeleteFromHashTable("GUITAR");
Assert.IsFalse(ht.Search("GUITAR"));
}
开发者ID:Gosed,项目名称:HomeWorks,代码行数:7,代码来源:HashTest.cs
示例13: Initialize
public void Initialize()
{
hashFunction1 = new HashFunction1();
hashFunction2 = new HashFunction2();
hashTable1 = new HashTable(5, hashFunction1);
hashTable2 = new HashTable(5, hashFunction2);
}
开发者ID:Kirill-Andreev,项目名称:University,代码行数:7,代码来源:HashTableTest.cs
示例14: Main
static void Main(string[] args)
{
HashTable<int, string> table = new HashTable<int, string>();
for (int i = 0; i < 17; i++)
{
table.Add(i, (i + 1).ToString());
}
Console.WriteLine(table[15]);
table.Clear();
for (int i = 0; i < 3000; i++)
{
table.Add(i, (i + 1).ToString());
}
Console.WriteLine(table[1457]);
//table.Add(1, "test");
//table.Add(2, "test");
////table.Remove(1);
//Console.WriteLine(table[1]);
}
开发者ID:Jarolim,项目名称:AllMyHomeworkForTelerikAcademy,代码行数:25,代码来源:Sample.cs
示例15: Main
public static void Main()
{
HashTable<int, string> table = new HashTable<int, string>();
table.Add(2, "Pesho");
table.Add(3, "Jhon");
table.Add(67, "Evlogi");
table.Add(23, "Jhon");
table.Add(27, "Pesho");
table.Add(35, "Jhon");
table.Add(66, "Evlogi");
table.Add(11, "Jhon");
table.Add(32, "Pesho");
table.Add(19, "Jhon");
table.Add(12, "Evlogi");
table.Add(13, "Jhon");
table.Add(14, "Pesho");
table.Add(30, "Jhon");
table.Add(44, "Evlogi");
foreach (var item in table)
{
Console.WriteLine(item.Value);
}
}
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:25,代码来源:Startup.cs
示例16: Main
static void Main()
{
HashTable<string, string> hashTable = new HashTable<string, string>();
string input = Console.ReadLine();
while (input != "search")
{
string[] parameters = input.Split('-');
string contact = parameters[0];
string number = parameters[1];
hashTable[contact] = number;
input = Console.ReadLine();
}
input = Console.ReadLine();
while (input != "end")
{
if (hashTable.ContainsKey(input))
{
Console.WriteLine("{0} -> {1}", input, hashTable[input]);
}
else
{
Console.WriteLine("Contact {0} does not exist", input);
}
input = Console.ReadLine();
}
}
开发者ID:dev-velkov,项目名称:Software-University-Courses,代码行数:33,代码来源:Program.cs
示例17: ClearShouldEmptyTheTableAndKeepTheCurrentCapacity
public void ClearShouldEmptyTheTableAndKeepTheCurrentCapacity()
{
var table = new HashTable<string, List<int>>();
for (int i = 0; i < 50; i++)
{
table[i.ToString()] = new List<int>();
for (int j = 0; j < 5; j++)
{
table[i.ToString()].Add(j);
}
Assert.IsTrue(table[i.ToString()].Count > 0);
}
int finalCapacity = table.Capacity;
table.Clear();
Assert.IsTrue(finalCapacity >= 50);
Assert.AreEqual(finalCapacity, table.Capacity);
Assert.AreEqual(0, table.Count);
for (int i = 0; i < 50; i++)
{
Assert.IsFalse(table.ContainsKey(i.ToString()));
}
}
开发者ID:kidroca,项目名称:Data-Structures-And-Algorithms-2015,代码行数:26,代码来源:HashTableFunctionallity.cs
示例18: Main
static void Main()
{
var grades = new HashTable<string, int>();
Console.WriteLine("Grades:" + string.Join(",", grades));
Console.WriteLine("--------------------");
grades.Add("Peter", 3);
grades.Add("Maria", 6);
grades["George"] = 5;
Console.WriteLine("Grades:" + string.Join(",", grades));
Console.WriteLine("--------------------");
grades.AddOrReplace("Peter", 33);
grades.AddOrReplace("Tanya", 4);
grades["George"] = 55;
Console.WriteLine("Grades:" + string.Join(",", grades));
Console.WriteLine("--------------------");
Console.WriteLine("Keys: " + string.Join(", ", grades.Keys));
Console.WriteLine("Values: " + string.Join(", ", grades.Values));
Console.WriteLine("Count = " + string.Join(", ", grades.Count));
Console.WriteLine("--------------------");
grades.Remove("Peter");
grades.Remove("George");
grades.Remove("George");
Console.WriteLine("Grades:" + string.Join(",", grades));
Console.WriteLine("--------------------");
Console.WriteLine("ContainsKey[\"Tanya\"] = " + grades.ContainsKey("Tanya"));
Console.WriteLine("ContainsKey[\"George\"] = " + grades.ContainsKey("George"));
Console.WriteLine("Grades[\"Tanya\"] = " + grades["Tanya"]);
Console.WriteLine("--------------------");
}
开发者ID:bobosam,项目名称:DataStructures,代码行数:34,代码来源:HashTableExample.cs
示例19: IndexerShouldSetThePassedValueToThePassedKey
public void IndexerShouldSetThePassedValueToThePassedKey()
{
var testHashTable = new HashTable<int, int>();
testHashTable.Set(1, 1);
testHashTable[1] = 2;
Assert.AreEqual(2, testHashTable[1]);
}
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs
示例20: Main
static void Main(string[] args)
{
HashTable<string, string> phoneBook = new HashTable<string, string>();
while (true)
{
var line = Console.ReadLine();
if (line == "search")
{
while (true)
{
line = Console.ReadLine();
if (line == "break")
{
break;
}
var entry = phoneBook.Find(line);
if (entry != null)
{
Console.WriteLine("{0} -> {1}", entry.Key, entry.Value);
}
else
{
Console.WriteLine("Contact {0} does not exist!", line);
}
}
}
else
{
string[] phoneEntries = line.Split(new string[] { DELIMITER }, StringSplitOptions.RemoveEmptyEntries).ToArray();
phoneBook.Add(phoneEntries[0], phoneEntries[1]);
}
}
}
开发者ID:flyer87,项目名称:Data_structures,代码行数:35,代码来源:Program.cs
注:本文中的HashTable类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论