package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableCharDoubleMapFactory;
import org.eclipse.collections.api.map.primitive.CharDoubleMap;

public final class MutableCharDoubleLinearHashMapFactory implements MutableCharDoubleBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableCharDoubleMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableCharDoubleLinearHashMapFactory(allocator, config);
    }

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

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

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