package meerkat.mixer.network;

/**
 * A generic permutation network composed of 2-input switches.
 */
public interface PermutationNetwork {
    /**
     * Return the number of inputs supported by the network.
     * @return
     */
    int getNumInputs();

    /**
     * Return the number of layers supported by the network.
     * @return
     */
    int getNumLayers();

    /**
     * Return the index of the switch output in the previous layer that connects to a specified input in the current layer.
     * Each consecutive pair of outputs is from the same switch, and each consecutive pair of inputs goes to the same switch.
     * (that is, switch j has inputs/outputs  2j and 2j+1)
     *
     * @param layer current layer index. Must be in the range [0, numLayers)  (layer 0's previous layer consists of the inputs themselves)
     * @param inputIdx the input Idx for the current layer. Must be in the range [0, numInputs)
     *
     * @return the requested index
     */
    int getOutputIdxInPreviousLayer(int layer, int inputIdx);

    /**
     * The inverse of {@link }#getOutputIdxInPreviousLayer(int,int)}.
     * @param layer
     * @param inputIdx
     * @return
     */
    int getInputIdxInNextLayer(int layer, int inputIdx);

    /**
     * Initialize switches to generate a specific permutation.
     * @param permutation
     */
    void setPermutation(int[] permutation);


    /**
     * Returns true iff the switch is crossed
     * @param layer
     * @return
     */
    boolean isCrossed(int layer, int switchIdx);

}
