package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableIntShortMapFactory;
import org.eclipse.collections.api.map.primitive.IntShortMap;

public final class MutableIntShortLinearHashMapFactory implements MutableIntShortBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableIntShortMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableIntShortLinearHashMapFactory(allocator, config);
    }

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

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

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