parent
398c8d85cc
commit
c640109d43
@ -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" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -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" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
@ -1,7 +1,7 @@ |
|||||||
using System; |
using System; |
||||||
using System.Collections; |
using System.Collections; |
||||||
|
|
||||||
namespace treeStructure.Structure |
namespace hashTableStructure.Client |
||||||
{ |
{ |
||||||
public class UseDictionary |
public class UseDictionary |
||||||
{ |
{ |
@ -1,7 +1,7 @@ |
|||||||
using System; |
using System; |
||||||
using System.Collections; |
using System.Collections; |
||||||
|
|
||||||
namespace treeStructure.Structure |
namespace hashTableStructure.Client |
||||||
{ |
{ |
||||||
public class UseHashTable |
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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue