package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableCharIntMapFactory;
import org.eclipse.collections.api.map.primitive.CharIntMap;

public final class MutableCharIntLinearHashMapFactory implements MutableCharIntBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableCharIntMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableCharIntLinearHashMapFactory(allocator, config);
    }

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

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

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