Python HashCode 分库分表逻辑

来源:互联网 发布:大数据 维基百科 编辑:程序博客网 时间:2024/06/05 23:58
def longToInt(value):        assert isinstance(value, (int, long))        return int(value & sys.maxint)#4294967295             int unsigned#18446744073709551615   bigint unsigneddef int_overflow(val):    maxint = 4294967295    if not -maxint-1 <= val <= maxint:        val = (val + (maxint + 1)) % (2 * (maxint + 1)) - maxint - 1    return val# get the database no, table nodef get_db_no(val):        no=abs(int_overflow(longToInt(val ^ (val >> 32)))) % 64        if no < 10:                no='0'+str(no)        else:                no=str(no)        return nodef get_table_no(val):        no= abs(int_overflow(longToInt(val ^ (val >> 32)))) % 63        #no=str(no)        return no
原创粉丝点击