
import java.util.ArrayList;
import java.util.List;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Simple HashMap implementation in Java
 *
 * @author: Dimitar
 * @keywords: Data Structures, Map, Hashing
 * @modified:
 *
 * Implement an unordered map with String keys. Use load factor ((number of
 * elements + 1) / number of buckets) of at least 0.25.
 *
 * (optional): Make it also work for integers (int) as keys. (optional): Make it
 * also work for arbitrary objects as keys.
 */
public class HashMap<V> {

    private final float LOAD_FACTOR = 0.75f;
    private long maxElementsAlowed;
    private List<MapEntry> buckets;

    public HashMap() {
        maxElementsAlowed = 1 << 4;
        buckets = new ArrayList<>(1 << 4);
    }

    private class MapEntry {

        final int hash;
        String key;
        V value;

        public MapEntry(int hash, String key, V value) {
            this.hash = hash;
            this.key = key;
            this.value = value;
        }

        public String getKey() {
            return key;
        }

        public V getValue() {
            return value;
        }

        public void setValue(V value) {
            this.value = value;
        }

        public int getHash() {
            return this.hash;
        }
    }

    /**
     * Resizes the HashMap so it has at least numBuckets slots (buckets).
     * Re-hashes the current values if needed. Expected time complexity: O(N +
     * numBuckets)
     */
    public void resize(int numBuckets) {
        // TODO: implement
    }

    /**
     * Removes all existing values from the HashMap and leaves it empty.
     * Expected complexity: O(N + B)
     */
    public void clear() {
        // TODO: implement
    }

    /**
     * Returns the number of elements in the HashMap. Expected complexity: O(1)
     */
    public int size() {
        // TODO: implement
        return -1;
    }

    /**
     * Returns the number of allocated buckets in the HashMap. Expected
     * complexity: O(1)
     */
    public int capacity() {
        // TODO: implement
        return -1;
    }

    /**
     * Checks if a value is already associated with a certain key. Expected
     * complexity: O(H + 1), where O(H) is needed to hash the key.
     */
    public boolean contains(String key) {
        // TODO: implement
        return false;
    }

    /**
     * Inserts a new (key, value) pair or replaces the current value with
     * another one, if the key is already present. Expected complexity: O(H +
     * 1), where O(H) is needed to hash the key.
     */
    public void insert(String key, V value) {
        // TODO: implement
    }

    /**
     * Removes a key and the associated with it value from the HashMap. Expected
     * complexity: O(H + 1), where O(H) is needed to hash the key.
     */
    public void erase(String key) {
        // TODO: implement
    }

    /**
     * Returns a reference to the value, associated with a certain key. If the
     * key is not present in the HashMap, throw an error or fail by assertion.
     * Expected complexity: O(H + 1), where O(H) is needed to hash the key.
     */
    public V get(String key) {
        // TODO: implement
        return null;
    }
}

@@ -647,24 +647,79 @@
 shMap%3CV%3E %7B%0A%0A
+    private final int BASE = 257;%0A    private int MOD;%0A
     private 
@@ -767,12 +767,11 @@
 ate 
-long
+int
  max
@@ -970,16 +970,24 @@
         
+private 
 final in
@@ -1002,16 +1002,24 @@
         
+private 
 String k
@@ -1030,16 +1030,24 @@
         
+private 
 V value;
@@ -1494,32 +1494,683 @@
        %7D%0A    %7D%0A%0A
+    private int generateHash(String str) %7B%0A        int ret = 1;%0A        for (int i = 0; i %3C (int) str.length(); i++) %7B%0A            ret = (ret * BASE + str.charAt(i)) %25 MOD;%0A        %7D%0A        return ret;%0A    %7D%0A%0A    boolean isPrime(int n) %7B%0A        if (n %25 2 == 0) %7B%0A            return false;%0A        %7D%0A        for (int i = 3; i * i %3C= n; i += 2) %7B%0A            if (n %25 i == 0) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A%0A    private int getNextPrime(int n) %7B%0A        int i = n;%0A        for (; i %3C 2 * n; ++i) %7B%0A            if (isPrime(i)) %7B%0A                break;%0A            %7D%0A        %7D%0A        return i;%0A    %7D%0A%0A
     /**%0A     * R
@@ -3507,32 +3507,211 @@
 TODO: implement%0A
+        // ...%0A        //after insertion check the load%0A        if (this.buckets.size() / maxElementsAlowed %3E= LOAD_FACTOR) %7B%0A            resize(maxElementsAlowed * 2);%0A        %7D%0A
     %7D%0A%0A    /**%0A 
@@ -3893,32 +3893,32 @@
 e(String key) %7B%0A
-
         // TODO:
@@ -3920,32 +3920,220 @@
 TODO: implement%0A
+        // ...%0A        //after deletion check the load%0A//        if (this.buckets.size() / maxElementsAlowed %3C= 1 - LOAD_FACTOR) %7B%0A//            resize(maxElementsAlowed / 2);%0A//        %7D%0A
     %7D%0A%0A    /**%0A 

add a couple of private functions