Get value's reference with Hashmap


Hi Jules,

What do you think of making the hashmap behave, quite conveniently, like std::map in this regard? That is, default-initialising an entry if it’s not found in the map, so that the operator[] may return a reference. This change makes it easier to use non-primitive value types with the hashmap.

It would look something like this:

    inline const ValueType& operator[] (KeyTypeParameter keyToLookFor) const
        const ScopedLockType sl (getLock());

        const int hashIndex = generateHashFor (keyToLookFor);
        for (const HashEntry* entry = slots.getUnchecked (hashIndex); entry != nullptr; entry = entry->nextEntry)
            if (entry->key == keyToLookFor)
                return entry->value;

        HashEntry* const firstEntry = slots.getUnchecked (hashIndex);
        HashEntry* newEntry = new HashEntry (keyToLookFor, ValueType(), firstEntry);
        slots.set (hashIndex, newEntry);

        if (totalNumItems > (getNumSlots() * 3) / 2)
            remapTable (getNumSlots() * 2);

        return newEntry->value;