package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableShortLongMapFactory;
import org.eclipse.collections.api.map.primitive.ShortLongMap;

public final class MutableShortLongLinearHashMapFactory implements MutableShortLongBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableShortLongMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableShortLongLinearHashMapFactory(allocator, config);
    }

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

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

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