Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What are some good data structures for keeping track of agents in a two-dimensional, spatial simulation?
I've seen some references to quadtrees (which I understand) and kd-trees (which I don't understand very well).
I'm looking for something through which an agent can efficiently say, "I know my location, and I would like to know which agents are near me (within a certain radius of myself)."
Examples (pseudo-code is fine) would be greatly appreciated.
I'm working in Java.
Well, I'm not sure exactly how it is implemented, but the MASON toolkit uses a discretization algorithm that places agents that are close to one another in the same "bucket" of a hash table. It makes for very fast lookups, as only a few of these buckets have to be checked for each query.
The best thing for you is probably to take a look at the source code here:
http://code.google.com/p/mason/source/browse/trunk/mason/sim/field/continuous/Continuous2D.java?r=529
I have found something called a Bucket PR Quadtree.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I would like to know which is the right collection to be used in Java to store and search string/data from millions of data?
Assume you want it for String.
Assume you want it for objects, and search for multiple values.
Please note that I am looking for the best performance to quickly get the search result. I am looking for Java collection which can do this. Want to know the right collection that can be used. Input is an arbitrary string and not necessarily sorted.
Actually if you want to search in such large data structure, none of the available collections in java would be sufficient as you would need to store all the data in memory which would require really powerfull computer to work.
However there are existing solutions to you problem, which is called Full Text Search.
Take a look at Apache Lucene or Elasticsearch (which uses Apache Lucene under the hood)
For more simple solution you could also use any relational database which should also do the trick.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Currently my program is filled with many ugly references that often make field or method access look like this: weakReference1.get().weakReference2.get().field1.getSomeCustomObject().field2. I want to move to shorter and faster strong references like field1.field2. But my program design is such that I will also have to go for an ArrayList element-by-element search (in a for-loop) instead of accessing a WeakHashMap by get() method.
Thus, I'd like to understand, can moving to simpler references compensate for rejecting HashMap performance wise. Herewith I presume that WeakHashMap.get() is much faster than a loop-search of ArrayList.
Can someone, please, give me a rough estimate? Or maybe there's even an appropriate comparison table like this one. I'd appreciate that.
Thank you.
Currently my program is filled with many ugly references that often make field or method access look like this:
weakReference1.get().weakReference2.get().field1.getSomeCustomObject().field2
Given that the objects involved are not Data Transfer Objects
this is a violation of the law of Demeter aka Don't talk to Strangers / Tell, don't ask!
Following this LoD principle you should move the operations working with the data in field2 to a new method in the class SomeCustomObject.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
In Data Structures and Algorithms in Java, the advantages of ordered arrays are stated. One of the advantages, I wish I had some kind of real example for. This is not for homework, but just self-clarification. What are some real cases for when insertion/deletion is not frequent, but searches are frequent? Anything would help even if you can point me in the direction of some github repository. Thank you.
An example would be a dictionary. After it is built, it can be looked up millions of time. Like your paper dictionary, the words in it better be sorted.
While I like leeyuiwah's answer, a more common domain which you can see in commercial context is a data base of some entity, for example the customers or employees, for which normally you create a view. That's why we index them (make the retrieval faster). Indeed, after inserting some records most of the operations will be retrieval which includes a search (based on complicated conditions or a simple identifier).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to store a list of (Object, int) in a data structure such that the int field can be easily sorted (ascending or descending).
I'm looking at Hashtables and TreeMaps but i'm unsure which, if either, of these are good for this purpose.
The priority is the sort speed. Any suggestions?
Given what you've told us, it's hard to say what'd be best.
If you're concerned with sorting performance alone, a HashTable or TreeMap (actually a red-black binary tree) have great sorting performance, but they're slower than some other data structures when adding (and in TreeMap's case, deleting) items.
You should probably provide more details regarding what you're doing with the data.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have near about 1 million entries in my database table and
I need to use some logic by which I can search within minimum time,
is there any algorithms or logic by which i can get result within less time.
I tried sorting table alphabetically but till it is taking much more time.
If you have any algorithm or logic then please suggest code in Java.
Looks like you need to ad in index to your database table.
If you tell what database you are using, people can give more specific help.
It dosent matter how much records you have as long as your databse is properly normalised and is having proper index. Having said that, the only difference that will make is how you are using indexes. You cannot do much in java, but your db and its design will play a significant role.