#Help with hash maps

3 messages · Page 1 of 1 (latest)

marble spruce
#

Hi, can someone help me with an implementation of a hash map, I tried to do the TODO this way, but it shows an error.


    // DEFAULT_CAPACITY has to be a prime number
    private static final int DEFAULT_CAPACITY = 23;
    private static final float DEFAULT_LOAD_FACTOR = 0.5f;
    private static final int CAPACITY_INCREASE_FACTOR = 2;
    private Node<KeyType, DataType>[] map;
    private int size = 0;
    private int capacity;
    private final float loadFactor; // Compression factor

    public HashMap() { this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); }

    public HashMap(int initialCapacity) {
        this(initialCapacity, DEFAULT_LOAD_FACTOR);
    }

    /** TODO
     * Define capacity, loadFactor and map
     */
    public HashMap(int initialCapacity, float loadFactor) {
        this.loadFactor = Math.abs(loadFactor);
        return new HashMap<Integer, Integer>(initialCapacity, loadFactor); --> ERROR
    }```
pine ravineBOT
#

This post has been reserved for your question.

Hey @marble spruce! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.