def impurity_decrease(y, membership, membership_true, membership_false, criterion):
    """
    A general function that calculates decrease in impurity.

    Parameters
    ----------
    y : array-like of shape (n_samples,)
        An array of labels.
    membership : array-like of shape (n_samples,)
        The old membership of each label.
    membership_true : array-like of shape (n_samples,)
        The new membership of each label.
    membership_false : array-like of shape (n_samples,)
        The complement of new membership of each label.
    criterion: callable
        The impurity function

    Returns
    -------
    float : decrease of impurity measured by given criterion
    """
    information_gain_ = criterion(y, membership) \
                        - (membership_true.sum() / membership.sum()) * criterion(y, membership_true) \
                        - (membership_false.sum() / membership.sum()) * criterion(y, membership_false)

    return information_gain_