math - Good Java Class to use for collection of mathematical Vectors -


i'm implementing graph (as in vertices, edges, not cartesian). i'm modelling graph physical collection of nodes (a class i've made).

i want have collection of forces, vectors (in maths sense), represent forces acting upon each node, , ideally able perform lookup node key, sounds me kind of hash lookup table.

what's collection use, or have make own?

if needs clarifying, ask.

thanks

if have understood needs correctly, want one-to-many mapping of node->vector.

provided node implements hashcode() , equals(), use multimap google guava. provides map<node,collection<vector>> mapping automatically.

the benefit of using multimap don't need this:

collection<vector> vectors = nodetovectormapping.get(node); if (vectors == null) {     vectors = new hashset<vector>();     nodetovectormapping.put(node, vectors); } vectors.add(vector); 

instead, need this:

nodetovectormapping.put(node,vector); 

the multimap takes care of checking whether inner collection exists or not. if find going multithreaded environment, 'do hand' approach involve synchronising ensure 2 threads didn't create collection @ same time, , so-on. google's guava helps lot of that, , lot more besides.

as big fan of google collections (the original home of multimap before absorbed larger guava project), should point in direction of mapmaker, has sorts of amazing goodness in perhaps find useful - size limitations, concurrency levels, lazy initialisation of values based upon keys, sort of thing. i've used these in highly-concurrent application , they've saved life on many occasion! :)


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -