package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableLongIntMapFactory;
import org.eclipse.collections.api.map.primitive.LongIntMap;

public final class MutableLongIntLinearHashMapFactory implements MutableLongIntBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableLongIntMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableLongIntLinearHashMapFactory(allocator, config);
    }

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

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

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