Skip to content

Commit 918981f

Browse files
committed
Improvements
1 parent 574e1a3 commit 918981f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/4.ResizableHashTable/Program.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ public void Add(TKey key, TValue value)
7171
else
7272
{
7373
var current = _buckets[index];
74-
while(current.Next is not null)
74+
if(current.Key.Equals(key))
7575
{
76-
current = current.Next;
76+
throw new InvalidOperationException("Key already exists");
7777
}
7878

79-
if(current.Key.Equals(key))
79+
while(current.Next is not null)
8080
{
81-
throw new InvalidOperationException("Key already exists");
81+
current = current.Next;
82+
83+
if(current.Key.Equals(key))
84+
{
85+
throw new InvalidOperationException("Key already exists");
86+
}
8287
}
8388

8489
current.Next = node;

0 commit comments

Comments
 (0)