library Votings {

    struct Voting {
        mapping(bytes32 => address[]) process;
    }

    /**
     * @dev Votes and check if voting is completed. If vote is completed - deletes it
     * @param voting Storage
     * @param index Of voting process
     * @param issuer Voter
     * @param required Amount of votes for this process to be successful
     * @return (is voting completed?)
     */
    function voteAndCheck(Voting storage voting,
        bytes32 index, address issuer, uint required) internal returns (bool)
    {
        vote(voting, index, issuer);
        return isComplete(voting, index, required);
    }

    /**
     * @dev Check if voting is completed. If vote is completed - deletes it
     * @param voting Storage
     * @param index Of voting process
     * @param required Amount of votes for this process to be successful
     * @return (is voting completed?)
     */
    function isComplete(Voting storage voting,
        bytes32 index, uint required) internal returns (bool)
    {
        if (voting.process[index].length < required) {
            return false;
        }

        delete voting.process[index];
        return true;
    }



    /**
     * @dev Vote
     * @param voting Storage
     * @param index Of voting process
     * @param issuer Voter
     */
    function vote(Voting storage voting,
        bytes32 index, address issuer) internal
    {
        require(!hadVoted(voting, index, issuer));
        voting.process[index].push(issuer);
    }

    /**
     * @dev Check of issuer had voted on this process
     * @param voting Storage
     * @param index Of voting process
     * @param issuer Voter
     * @return bool
     */
    function hadVoted(Voting storage voting,
        bytes32 index, address issuer) internal view returns (bool)
    {
        address[] storage _process = voting.process[index];

        for (uint ind = 0; ind < _process.length; ind++) {
            if (_process[ind] == issuer) {
                return true;
            }
        }

        return false;
    }
}
function vote(Voting storage voting,
    bytes32 index, address issuer) internal
{
    require(!hadVoted(voting, index, issuer));
    voting.process[index].push(issuer);
}

/**
 * @dev Vote
 * @param voting Storage
 * @param index Of voting process
 * @param issuer Voter
 */