Hi,
I'm writing a form of binary search to optimise an algorhythm to build a database from its core data entities. We have to look up whether we have built an entity previously, and if not then we add it.
The entities are in an array, and I can sort the array by inserting them in alphabetical order.
I am wondering if there is a further optimisation to make: namely that if we know that the new entity name begins with, say a 'D', then we know it should be approximately 4/26s of the way into the index of existing entities. A traditional binary search would always start at half way through.
In ye olde days of 8-bit ASCII text this would clearly be easy - you'd treat the character as a byte, subtract the offset of ASCII to the first character, etc etc.
Is there an 'easy' way to do this in Swift that isn't more computationally expensive than letting the search begin at halfway?
Best wishes,
Andrew