package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableLongLongMapFactory;
import org.eclipse.collections.api.map.primitive.LongLongMap;

public final class MutableLongLongLinearHashMapFactory implements MutableLongLongBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableLongLongMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableLongLongLinearHashMapFactory(allocator, config);
    }

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

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

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