main
syneffort 2 years ago
parent 398c8d85cc
commit c640109d43
  1. 29
      .vscode/launch.json
  2. 41
      .vscode/tasks.json
  3. 4
      DataStructure/hashTableStructure/Client/UseConcurrentDictionary.cs
  4. 2
      DataStructure/hashTableStructure/Client/UseDictionary.cs
  5. 2
      DataStructure/hashTableStructure/Client/UseHashTable.cs
  6. 21
      DataStructure/hashTableStructure/Client/UseSimpleHashTable.cs
  7. 16
      DataStructure/hashTableStructure/HashTable/Node.cs
  8. 65
      DataStructure/hashTableStructure/HashTable/SimpleHashTable.cs
  9. 20
      DataStructure/hashTableStructure/Program.cs
  10. 16
      DataStructure/treeStructure/Program.cs

@ -0,0 +1,29 @@
{
// IntelliSense .
// .
// https://go.microsoft.com/fwlink/?linkid=830387() .
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/DataStructure/hashTableStructure/bin/Debug/net7.0/hashTableStructure.dll",
"args": [],
"cwd": "${workspaceFolder}/DataStructure/hashTableStructure",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

41
.vscode/tasks.json vendored

@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/DataStructure/hashTableStructure/hashTableStructure.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

@ -4,7 +4,7 @@ using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
namespace treeStructure.Structure
namespace hashTableStructure.Client
{
public class UseConcurrentDictionary
{
@ -27,7 +27,7 @@ namespace treeStructure.Structure
Task t2 = Task.Factory.StartNew(() =>
{
int key = 1;
string val;
string val = string.Empty;
while (key <= 100)
{
if (dict.TryGetValue(key, out val))

@ -1,7 +1,7 @@
using System;
using System.Collections;
namespace treeStructure.Structure
namespace hashTableStructure.Client
{
public class UseDictionary
{

@ -1,7 +1,7 @@
using System;
using System.Collections;
namespace treeStructure.Structure
namespace hashTableStructure.Client
{
public class UseHashTable
{

@ -0,0 +1,21 @@
using System;
using hashTableStructure.HashTable;
namespace hashTableStructure.Client
{
class UseSimpleHashTable
{
public static void DoWork()
{
SimpleHashTable ht = new SimpleHashTable();
ht.Put("Lim S", "Sales 01");
ht.Put("Bea H", "Sales 02");
ht.Put("Kim P", "SW 01");
ht.Put("Lee C", "SW 02");
System.Console.WriteLine(ht.Get("Lee C"));
System.Console.WriteLine(ht.Get("Lim S"));
System.Console.WriteLine(ht.Contains("Unknown"));
}
}
}

@ -0,0 +1,16 @@
namespace hashTableStructure.HashTable
{
class Node
{
public object Key { get; set; }
public object Value { get; set; }
public Node Next { get; set; }
public Node(object key, object value)
{
this.Key = key;
this.Value = value;
this.Next = null;
}
}
}

@ -0,0 +1,65 @@
namespace hashTableStructure.HashTable
{
class SimpleHashTable
{
private const int INITIAL_SIZE = 16;
private int _size;
private Node[] _buckets;
public SimpleHashTable()
{
_size = INITIAL_SIZE;
_buckets = new Node[_size];
}
public void Put(object key, object value)
{
int index = HashFunction(key);
if (_buckets[index] == null)
{
_buckets[index] = new Node(key, value);
}
else
{
Node newNode = new Node(key, value);
newNode.Next = _buckets[index];
_buckets[index] = newNode;
}
}
public object Get(object key)
{
int index = HashFunction(key);
if (_buckets[index] != null)
{
for (Node n = _buckets[index]; n != null; n = n.Next)
{
if (n.Key == key)
return n.Value;
}
}
return null;
}
public bool Contains(object key)
{
int index = HashFunction(key);
if (_buckets[index] != null)
{
for (Node n = _buckets[index]; n != null; n = n.Next)
{
if (n.Key == key)
return true;
}
}
return false;
}
protected virtual int HashFunction(object key)
{
return Math.Abs(key.GetHashCode() + 1 + ((key.GetHashCode() >> 5) + 1) % _size) % _size;
}
}
}

@ -1,2 +1,18 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using hashTableStructure.Client;
namespace hashTableStructure
{
static class Program
{
static void Main(string[] args)
{
//UseHashTable.DoWork();
// UseDictionary.DoWork();
// UseConcurrentDictionary.DoWork();
UseSimpleHashTable.DoWork();
}
}
}

@ -1,16 +0,0 @@
using treeStructure.Structure;
namespace treeStructure
{
static class Program
{
static void Main(string[] args)
{
//UseHashTable.DoWork();
// UseDictionary.DoWork();
UseConcurrentDictionary.DoWork();
}
}
}
Loading…
Cancel
Save