package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableCharByteMapFactory;
import org.eclipse.collections.api.map.primitive.CharByteMap;

public final class MutableCharByteLinearHashMapFactory implements MutableCharByteBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableCharByteMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableCharByteLinearHashMapFactory(allocator, config);
    }

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

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

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