Skip to main content
Alexei Kaigorodov's user avatar
Alexei Kaigorodov's user avatar
Alexei Kaigorodov's user avatar
Alexei Kaigorodov
  • Member for 12 years, 6 months
  • Last seen more than 4 years ago
awarded
Loading…
comment
Bidirectional hash map in Java
HashMap<V, Collection<K>> maybe. Generally, different keys can be mapped on the same value. So one value corresponds to a set of keys.
answered
Loading…
comment
Optimize Conway's Game of Life
I mean that in countLiveNeighbors, if (isLiving){result++;} can be replaced with result+=isLiving, which is faster.
answered
Loading…
awarded
comment
Does this Actor implementation has synchronization problems?
When you suggest to make this.message volatile, you mean to make sure assigment to message happens before reading it. But as docs.oracle.com/javase/7/docs/api/java/util/concurrent/… reads, Actions in a thread prior to submitting a Runnable object to an Executor happen-before its execution begins, perhaps in another thread, so no need to make it volatile or put another synchronized block.
comment
Refactoring calculator expression
do google search for "recursive descent parser for arithmetic expressions".
comment
A more efficient enqueue algorithm in Java
What is the sense of doing so?
comment
Producer-Consumer using low level synchronization
For learning purposes, read more code written by qualified programmers. Sources of main java libraries, including ArrayBlockingQueue, are available. But very often that code is overoptimized, so reader can get habits of bad style. For beginners, style is more important than execution speed.
answered
Loading…
comment
Find the uncommon elements from two sets
HashSets are never ordered, even if parameter lists in their constructors are.
comment
Is this the right way to retrieve all the fields from any Object?
realFields should be of type Field[], not Set<String>.
comment
Is this the right way to retrieve all the fields from any Object?
Then what? Another method is also suboptimal, though in a different way.
Loading…
Loading…
Loading…
comment
Checking if an index is out of bounds
throw out all your checkIfAllowed stuff - you'll still get IndexOutOfBoundsException, though without message (which is not informative anyway)