Skip to content

Instantly share code, notes, and snippets.

@isi-mfurer
Created November 25, 2015 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isi-mfurer/bbc8580295b6c4dc45d3 to your computer and use it in GitHub Desktop.
Save isi-mfurer/bbc8580295b6c4dc45d3 to your computer and use it in GitHub Desktop.
def buffer_equal_1(buf1, buf2):
if len(buf1) != len(buf2):
raise AssertionError("Buffers are not the same size")
low = 0
high = len(buf1)
while high - low > 1:
chunk_1 = (low, low+(high-low)/2)
chunk_2 = (low+(high-low)/2, high)
if buf1[chunk_1[0]:chunk_1[1]] != buf2[chunk_1[0]:chunk_1[1]]:
low, high = chunk_1
elif buf1[chunk_2[0]:chunk_2[1]] != buf2[chunk_2[0]:chunk_2[1]]:
low, high = chunk_2
else:
break
if high - low <= 1:
raise AssertionError("Block mismatch at byte {0}: "
"{1} != {2}".format(low, buf1[low], buf2[low]))
def buffer_equal_3(buf1, buf2):
if buf1 != buf2:
for ix in xrange(len(buf1)):
if buf1[ix] != buf2[ix]:
raise AssertionError("Block mismatch at byte {0}".format(ix))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment