clear for lnElementCount = 1000 to 65000 step 1000 lnKeyCount = 1000 dimension laElements[lnElementCount] dimension laKeys[lnKeyCount] for j = 1 to lnElementCount laElements[j] = j endfor for j = 1 to lnKeyCount laKeys[j] = int(rand() * lnElementCount) endfor lnSeconds = seconds() for j = 1 to lnKeyCount =ascan(laElements, laKeys[j]) endfor lnSeconds = seconds() - lnSeconds ? "ASCAN()" ?? "Total Elements = " ?? lnElementCount ?? " : Keys Sought = " ?? lnKeyCount ?? " : Time = " ?? lnSeconds lnSeconds = seconds() for j = 1 to lnKeyCount =aBinScan(@laElements, laKeys[j]) endfor lnSeconds = seconds() - lnSeconds ? "aBinScan()" ?? "Total Elements = " ?? lnElementCount ?? " : Keys Sought = " ?? lnKeyCount ?? " : Time = " ?? lnSeconds ? endfor ** ** aBinScan (taArray, tKey) ** author: Albert Ballinger ** parameters: ** taArray as sorted array ** tKey as sought for element ** returns: ** -1 if tKey less than all elements ** (1, alen(taArray)) if tKey found, index of element ** (-1, -alen(taArray)) if tKey not found, index of first ** element greater than tKey ** -(alen(taArray) + 1) if tKey not found, no elements greater ** than tKey ** function aBinScan (taArray, tKey) return aBinRecurse(@taArray, tKey, 1, alen(taArray)) endfunc ** ** aBinScan (taArray, tKey) ** author: Albert Ballinger ** see aBinScan (taArray, tKey) ** function aBinRecurse (taArray, tKey, tnLPartition, tnRPartition) local lnMidPoint lnMidPoint = int(tnLPartition + (tnRPartition - tnLPartition) / 2) if taArray[lnMidPoint] = tKey return lnMidPoint && found it endif if lnMidPoint = tnLPartition * not found if alen(taArray) = lnMidPoint && at upper boundary? if taArray[lnMidPoint] < tKey return -(lnMidPoint + 1) && out of range else return -lnMidPoint && less than last element endif else return -lnMidPoint endif endif if tKey < taArray[lnMidPoint] return aBinRecurse(@taArray, tKey, tnLPartition, lnMidPoint) else return aBinRecurse(@taArray, tKey, lnMidPoint + 1, tnRPartition) endif endfunc