Skip to content

Commit

Permalink
Added constants BISECT_BLOCK_SIZE and BISECT_LIMIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrocholl committed Mar 8, 2010
1 parent f9331fd commit 04d58e9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tools/update_dns.py
Expand Up @@ -35,6 +35,9 @@
logfile.setLevel(logging.WARNING)
logging.getLogger().addHandler(logfile)

BISECT_BLOCK_SIZE = 30
BISECT_LIMIT = BISECT_BLOCK_SIZE / 2
PASSWORD_FILENAME = '.passwd'
NAMESERVERS = """
208.67.222.222
208.67.220.220
Expand All @@ -56,8 +59,6 @@
205.171.3.65
""".split()

PASSWORD_FILENAME = '.passwd'


def auth_func():
if os.path.exists(PASSWORD_FILENAME):
Expand Down Expand Up @@ -289,20 +290,26 @@ def count_existing(names):

def bisect(names):
# Check the end of the list.
if count_existing(names[-20:]) > 5:
count = count_existing(names[-BISECT_BLOCK_SIZE:])
if count > BISECT_LIMIT:
print "bisect end count=%d" % count
return []
# Check the beginning of the list.
if count_existing(names[:20]) <= 5:
count = count_existing(names[:BISECT_BLOCK_SIZE])
if count <= BISECT_LIMIT:
print "bisect start count=%d" % count
return names
# Bisect the list to find the crash point.
left = 0
right = len(names) - 1
while right - left > 20:
while right - left > BISECT_BLOCK_SIZE:
middle = (left + right) / 2
count = count_existing(names[middle:middle + 20])
start = middle - BISECT_BLOCK_SIZE / 2
stop = start + BISECT_BLOCK_SIZE
count = count_existing(names[start:stop])
print "bisect left=%s right=%s middle=%s count=%d" % (
names[left], names[right], names[middle], count)
if count <= 5:
if count <= BISECT_LIMIT:
right = middle
else:
left = middle
Expand Down

0 comments on commit 04d58e9

Please sign in to comment.