package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableIntDoubleMapFactory;
import org.eclipse.collections.api.map.primitive.IntDoubleMap;

public final class MutableIntDoubleLinearHashMapFactory implements MutableIntDoubleBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableIntDoubleMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableIntDoubleLinearHashMapFactory(allocator, config);
    }

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

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

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