I took one project and I'm getting really hard to continue. No comments, undocumented code, inconsistent naming variables ect.
But, at some point I expired slow execution of search. To be honest, I've never earlier expired slowness on mobile apps I developed because there wasn't much data to process.
Ok, there is a class A with following fields:
- ID integer
- Info 1 string
- Info 2 string
- ... string
During the session, Collection of class A is filling with new instances. At some point user ask for instance information selecting the instance ID (collection is not sorted by ID in any order). In average, there is about 2500 instances On some older devices it takes over long to find it. What is best practice to do this as fast as possible? (with time complexity explanation)
The genie who left me his code put it all in one collection and searched by linear search.
- Heapsort, so can search multiple times by binary search?
- Adding it in sorted order, then use binary search?
- Putting data in SQLite temp table (getting sense on more data) and search by query
- HashSet or TreeSet
- Something else..