def contains(begin, end, node):
    """Check node is contained between begin and end in a ring."""
    if not end:
        return False
    if not begin:
        return False

    if begin > end: # circle around
        #   [begin ,1024[   or  [0 , end]
        if (node > begin and node < 1024) or (node >= 0 and node <= end):
            return True
        else:
            return False
    else:
        # simplest case
        if node <= end and node > begin:
            return True
        else:
            return False
    return False