Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
#!/usr/bin/env python # Python implementation of cdb # calc hash value with a given key def calc_hash(s): return reduce(lambda h,c: (((h << 5) + h) ^ ord(c)) & 0xffffffffL, s, 5381) # cdbget(fp, basepos, key) def cdbget(fp, pos_header, k): from struct import unpack r = [] h = calc_hash(k) fp.seek(pos_header + (h % 256)*(4+4)) (pos_bucket, ncells) = unpack('> 8) % ncells for i in range(ncells): fp.seek(pos_bucket + ((start+i) % ncells)*(4+4)) (h1, p1) = unpack('> 8) % ncells while cell[i][1]: # is call[i] already occupied? i = (i+1) % ncells cell[i] = (h,p) for (h,p) in cell: fp.write(pack('