Reputation: 3
I have 1,000,000 objects. I need to match them with 4 different properties within a specified range .
A simple for loop does it but certainly isnt the most efficient way to go about it. What type of collections should i be looking to implement? How should I've approached this problem.
Upvotes: 0
Views: 352
Reputation: 8394
A collection would have to load all the data into memory, which is horribly inefficient for a data set that big. You should be using a database - that's what they're designed for.
Upvotes: 3
Reputation: 20442
A NavigableSet might work for you. You would need to define a different Comparator for each of the properties. Basically, start with the set sorted by one property and get the subset that fits the range. Place the subset into another NavigableSet
sorted by the Comparator
for the second property... repeat.
But I don't think any of that beats O(n) time :P since the sort is O(nlogn). At the very least it is interesting.
Upvotes: 0