package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableIntByteMapFactory;
import org.eclipse.collections.api.map.primitive.IntByteMap;

public final class MutableIntByteLinearHashMapFactory implements MutableIntByteBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableIntByteMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableIntByteLinearHashMapFactory(allocator, config);
    }

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

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

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