'Returns the length of this integer set as an integer. In case the
length is infinite, returns -1. This function exists because of a
limitation of the builtin len() function which expects values in
the range 0 <= len < 2**31. Use this function in case your integer
set might be larger.'

def len(self):

    if (not self._ranges):
        return 0
    if ((self._ranges[0][0] is _MININF) or (self._ranges[(-1)][1] is _MAXINF)):
        return (-1)
    rlen = 0
    for r in self._ranges:
        rlen += (r[1] - r[0])
    return rlen
