import numpy as np
from numba import jit
from fastcache import lru_cache

# @lru_cache(maxsize=16)
def combinations_of_2(size: int):
    """Returns an array of size n*2, containing every pair of two integers
    smaller than size, but not listing twice the pairs with the same numbers
    (so 1, 2 and 2, 1 aren't both listed).
    This function is cached because it is called many times just to generate
    the same value (when using aggregate_rankings).
    """
    # return np.array([[i, j] for i in range(0, size) for j in range(0, size) if i<j])
    return __combinations_of_2(size)


@jit
def __combinations_of_2(size: int):
    """Compiled helper."""
    # return np.array(list(combinations(range(size), 2)))
    # return np.array(np.meshgrid(np.arange(size), np.arange(size))).T.reshape(-1, 2)
    return np.array([[i, j] for i in range(0, size) for j in range(0, size) if i<j])



