def binary_search(haystack, needle, returnIndex=False, onlyURI=False):
lBound = 0
uBound = None
surtURIsAndDatetimes = []
cdxjObj = objectifyCDXJData(haystack, onlyURI)
surtURIsAndDatetimes = cdxjObj['data']
metaLineCount = len(cdxjObj['metadata'])
if uBound is not None:
uBound = uBound
else:
uBound = len(surtURIsAndDatetimes)
pos = bisect_left(surtURIsAndDatetimes, needle, lBound, uBound)
if pos != uBound and surtURIsAndDatetimes[pos] == needle:
if returnIndex: # Index useful for adjacent line searching
return pos + metaLineCount
return haystack[pos + metaLineCount]
else:
return None
评论列表
文章目录