def _next_k_combination(x):
    """
    Find the next k-combination, as described by an integer in binary
    representation with the k set bits, by "Gosper's hack".

    Copy-paste from en.wikipedia.org/wiki/Combinatorial_number_system

    Parameters
    ----------
    x : int
        Integer with k set bits.

    Returns
    -------
    int
        Smallest integer > x with k set bits.

    """
    u = x & -x
    v = u + x
    return v + (((v ^ x) // u) >> 2)