#what is the fastest way of sorting through thousands of objects?

21 messages · Page 1 of 1 (latest)

regal lion
#

I need to sort through thousands of objects using some sort of identifier, but im not sure what the fastest way is?
Arraylist
List
Map<string, user>?

mighty oreBOT
#

This post has been reserved for your question.

Hey @regal lion! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mighty oreBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

toxic bane
#

What do you mean by "sorting through"? Do you need it to be sorted? Do you need to find things based on some key?

mighty oreBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping.
Warning: abusing this will result in moderative actions taken against you.

regal lion
toxic bane
#

Use a HashMap then.

sinful moth
regal lion
#

I am using a hashmap, but running through it still takes around 3 minutes

sinful moth
#

lol wtf

#

show the code

toxic bane
#

Well you need to be more specific what you want to do then.

sinful moth
#

thousands of objects and 3 min to get the key

#

sounds like somethings wrong with the implementation

regal lion
#
                String searchResults = "";
                for (Map.Entry<String, String> entry : data.entrySet()) {
                    if ((entry.getKey().toLowerCase().contains(searchTerm.toLowerCase()) || entry.getValue().toLowerCase().contains(searchTerm.toLowerCase()) && !searchResults.contains(entry.getKey() + "," + entry.getValue() + "\n") && !searchTerm.contains(";"))) {
                        searchResults += entry.getKey() + "," + entry.getValue() + "\n";
                    } else if (entry.getKey().toLowerCase().contains(searchTerm.toLowerCase().split(";")[0]) && entry.getValue().toLowerCase().contains(searchTerm.toLowerCase().split(";")[1]) && searchTerm.contains(";")) {
                        searchResults += entry.getKey() + "," + entry.getValue() + "\n";
                    } else {
                        //searchResults += "no matches";
                    }
                }
                //System.out.println("Search results: " + searchResults);
#

trying to search for words that are maybe in around 50ish entries work just fine, but if i search for something thats in the majority, then it takes ages

#

it doesnt make sense to me since either way it is going through the same amount of map entries

toxic bane
#

Ok, this is not getting entries by a key. You want to find by search terms and this is a different use case.
First of all you are lowercasing a lot in your search and each lowercase is allocating new strings. An easy improvement might be to just store the lowercase strings in a separate map. That will improve the search time a lot. If you want to scale more though you need to investigate for better string-search-optimized datastructures like radix trees or similar.

sinful moth
#

cuz you are doing a lot of checking with entry and search term