package at.yawk.numaec;

import org.eclipse.collections.api.factory.map.primitive.MutableByteLongMapFactory;
import org.eclipse.collections.api.map.primitive.ByteLongMap;

public final class MutableByteLongLinearHashMapFactory implements MutableByteLongBufferMapFactory {
    private final LargeByteBufferAllocator allocator;
    private final LinearHashMapConfig config;

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

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

    public static MutableByteLongMapFactory withAllocatorAndConfig(
            LargeByteBufferAllocator allocator, LinearHashMapConfig config
    ) {
        return new MutableByteLongLinearHashMapFactory(allocator, config);
    }

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

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

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