package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableShortDoubleMapFactory;
import org.eclipse.collections.api.map.primitive.ShortDoubleMap;

public final class MutableShortDoubleLinearHashMapFactory implements MutableShortDoubleBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableShortDoubleMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableShortDoubleLinearHashMapFactory(allocator, config);
    }

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

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

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