def charset_to_int(s, charset):
    """ Turn a string into a non-negative integer.
    """
    if not isinstance(s, (str)):
        raise ValueError("s must be a string.")
    if (set(s) - set(charset)):
        raise ValueError("s has chars that aren't in the charset.")
    return sum(len(charset)**i * charset.index(char) for i, char in enumerate(s))