Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Why isn't there any implementation (in C, C++, Java or even Python...) of a fully persistent (not necessarily functional) linked list that has a constant time/space overhead in the number of modifications?
The data structure I have in mind is the one described in this paper:
http://www.cs.cmu.edu/~sleator/papers/Persistence.htm
After a long search on google I was unable to find even a partially persistent linked list implementation with the overhead sited above.
PS: The definitions of persistence I am speaking about are those described in the following Wikipedia page:
http://en.wikipedia.org/wiki/Persistent_data_structure
EDIT(after the question was put on hold):
I don't think the reason mentioned applies to my question. I am not exactly asking for recommendation among different available libraries, so there can t be "opinionated answers and spam". My question is kind of astonishment that a data structure, that is supposed to be great in theory, was not implemented by any of the known languages. So before I implement it myself I asked this question to see if there is an answer like: "It is normal, the data structure X dominates the one you re looking for and that's why it has not been implemented despite its simplicity". Another answer could be "It is not as good as you think since there is a big hidden constant" or "it doesn t do well with the way caches are built nowadays"... I am sorry if my question was not clear enough. I transformed my question making my request more explicit now.
Have you tried Functional Java library? It got some persistent data structures:
http://www.functionaljava.org/features.html
Related
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 4 years ago.
Improve this question
I need a hint on an Interview question that I came across. I tried to find a solution but I need advice from experts over here. What are the different strategies you would employ had you came across this particular situation? The question and my thoughts are as follows:
Q. You want to store a huge number of objects in a list in java. The number of objects is very huge and gradually increasing, but you have very limited memory available. How would you do that?
A. I answered by saying that, once the number of elements in the list
get over a certain threshold, I would dump them to a file. I would typically then build cache-like data-structure that would hold the most-frequently or recently added elements. I gave an analogy of page swapping employed by the OS.
Q. But this would involve disk access and it would be slower and affect the execution.
I did not know the solution for this and could not think properly during the interview. I tried to answer as:
A. In this case, I would think of horizontally scaling the system or
adding more RAM.
Immediately after I answered this, my telephonic interview ended. I felt that the interviewer was not happy with the answer. But then, what should have been the answer.
Moreover, I am not curious only about the answer, I would like to learn about different ways with which this can be handled.
Maybe I am not sure but It indicates that somewhat Flyweight Pattern. This is the same pattern which is been used in String pool and its efficient implementation is must Apart from that, we need focus on database related tasks in order to persist the data if the threshold limit is surpassed. Another technique is to serialize it but as you said, the interviewer was not satisfied and wanted some other explanation.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
This may be a silly question - It's actually been a month since I've started learning Java so I apologize beforehand.
I have started making an Android game similar to the quite famous Lifeline: text-adventure, where you make your own path after you keep choosing between 2 choices. When you click on one of the choices, then two new ones appear (and above them, the question that the protagonist asks you to keep you going).
So, lets say that every choice is unique: thinking of it as a "family tree" on paper, if we start with a question with 2 choices, then we get to 4 possible ones (for example, Yes leads to YES-NO and No leads to MAYBE-MAYBE NOT), then 8, then with the next choice there are 16 unique ones etc. Eventually, after 10 clicks, in the complete game there would be 1024 different choices.
My question is: do I have to make an activity for each different question giving you 2 choices? Creating 1000+ activities for a text-based game sounds... not fun at all. And also, do I really have to make every single text I write, questions and choices, a string?
Thanks in advance and sorry for my way of describing my problem.
Short answer: NO
How to do it?
You should plan it out at first.
Putting paths and questions in arrays.
And using the same activity but changing the data written.
I won't give you exact steps but these are hints, you can even make custom classes instead.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Looking for a high-performance String hashing functions in Java/Scala - something faster than functions from MurmurHash family, doesn't need to be cryptographically strong, only distribute well.
Any suggestions?
You can find very fast hash function implementations for Java, which BTW account internal String implementation (char[] array) to maximize speed, here: https://github.com/OpenHFT/Zero-Allocation-Hashing
The fastest hashing algorithm that fits the bill presently seems to be xxHash. The lz4-java project contains an implementation ported to Java. I don't know whether the Java implementation has been benchmarked against MurmurHash, though; performance optimizations in C++ don't always port to/from Java. (In particular, xxHash contains more array access, so there could be non-negligible bounds-checking overhead.)
Edit: it looks to me like it uses JNI to call the C++ implementation of xxHash, but JNI overhead is non-negligible, so the performance concerns remain.
However, given that Scala includes a MurmurHash function, and that Java contains a faster default hash (about 2x) that is sorta-reasonably distributed sometimes, one does wonder whether it's really necessary. For instance, scala.util.hashing.MurmurHash3 is about as fast as string creation from an array of bytes, and is twice as fast as that if you give it an array of bytes.
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.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
In Java, I have set of expressions like cond1 AND (cond2 OR cond3) AND ( cond 4 OR cond5). I would like to convert it into tree and then evaluate the final boolean answer. I tried searching a lot around java BDD but not able to get any. Any suggestion with sample code ?
A 5-second Google search returned some reasonable-looking results:
JavaBDD
Java Decision Diagram Libraries
What is the best Binary Decision Diagram library for Java?
Is this not what you're looking for?
He means Binary Decision Diagrams.
I've been tinkering with JavaBDD and JBDD/JDD. Both are based on BuDDY (a C library) -- JBDD actually uses the C DLLs for a marginal performance boost.
It looks to me like JavaBDD is more fully-featured (ex. it supports composing BDDs, which is what I need). But there is also no tutorial for it, and while the class docs aren't terrible, frankly I can't figure out how to use it for the most basic of boolean operations (like the problem you pose).
JBDD/JDD requires you to use manual garbage collection, and does weird things like store BDD objects in Java integers -- clearly carry-overs from C. But it has a set of tutorials.
If you want to run your own parser, check out JavaCC.
Here is a nice tutorial to get you started. A bit older, but still valid:
http://www.javaworld.com/jw-12-2000/jw-1229-cooltools.html