From 58bd1921bf10601cde6a864bbf73e0d529a689ee Mon Sep 17 00:00:00 2001 From: rec0de Date: Wed, 16 May 2018 21:37:47 +0200 Subject: [PATCH] Increase insert try cutoff to capacity squared --- HashTable/src/lab/HashTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HashTable/src/lab/HashTable.java b/HashTable/src/lab/HashTable.java index 9761d86..fe65eb4 100644 --- a/HashTable/src/lab/HashTable.java +++ b/HashTable/src/lab/HashTable.java @@ -112,7 +112,7 @@ public class HashTable { // Find a free or deleted slot to insert the entry while(this.data[address] != null && !this.data[address].isDeleted()) { // Don't insert if there is no more space (this shouldn't happen due to auto-rehashing) or if the key is already present - if(i > this.capacity || this.data[address].getKey().equals(insertEntry.getKey())) + if(i > Math.pow(this.capacity, 2) || this.data[address].getKey().equals(insertEntry.getKey())) // The try cutoff of n² is pretty much trial and error - definitely safe for linear probing, not sure about quadratic return false; i += 1; address = this.getProbingAddr(base, i);