package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableByteDoubleMapFactory;
import org.eclipse.collections.api.map.primitive.ByteDoubleMap;

public final class MutableByteDoubleLinearHashMapFactory implements MutableByteDoubleBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableByteDoubleMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableByteDoubleLinearHashMapFactory(allocator, config);
    }

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

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

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