package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableFloatFloatMapFactory;
import org.eclipse.collections.api.map.primitive.FloatFloatMap;

public final class MutableFloatFloatLinearHashMapFactory implements MutableFloatFloatBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

    private MutableFloatFloatLinearHashMapFactory(LargeByteBufferAllocator allocator, LinearHashMapConfig config) {
        this.allocator = allocator;
        this.config = config;
    }

    public static MutableFloatFloatMapFactory withAllocator(LargeByteBufferAllocator allocator) {
        return withAllocatorAndConfig(allocator, LinearHashMapConfig.builder().build());
    }

    public static MutableFloatFloatMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableFloatFloatLinearHashMapFactory(allocator, config);
    }

    @Override
    public MutableFloatFloatBufferMap empty() {
        return new FloatFloatLinearHashMap.Mutable(allocator, config);
    }

    @Override
    public MutableFloatFloatBufferMap ofInitialCapacity(int capacity) {
        FloatFloatLinearHashMap.Mutable map = new FloatFloatLinearHashMap.Mutable(allocator, config);
        map.ensureCapacity(capacity);
        return map;
    }

    @Override
    public MutableFloatFloatBufferMap ofAll(FloatFloatMap map) {
        MutableFloatFloatBufferMap n = ofInitialCapacity(map.size());
        n.putAll(map);
        return n;
    }
}