RLPark 1.0.0
Reinforcement Learning Framework in Java

VectorPools.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.math.vector.pool;
00002 
00003 import java.util.Collections;
00004 import java.util.HashMap;
00005 import java.util.Map;
00006 
00007 import rlpark.plugin.rltoys.math.vector.RealVector;
00008 
00009 public class VectorPools {
00010   static public Map<Thread, Map<Class<?>, Map<Integer, ThreadVectorPool>>> pools = Collections
00011       .synchronizedMap(new HashMap<Thread, Map<Class<?>, Map<Integer, ThreadVectorPool>>>());
00012 
00013   public static VectorPool pool(RealVector prototype) {
00014     return pool(prototype, prototype.getDimension());
00015   }
00016 
00017   public static VectorPool pool(RealVector prototype, int dimension) {
00018     final Thread thread = Thread.currentThread();
00019     Map<Class<?>, Map<Integer, ThreadVectorPool>> threadPool = pools.get(thread);
00020     if (threadPool == null) {
00021       threadPool = Collections.synchronizedMap(new HashMap<Class<?>, Map<Integer, ThreadVectorPool>>());
00022       pools.put(thread, threadPool);
00023     }
00024     Map<Integer, ThreadVectorPool> classPool = threadPool.get(prototype.getClass());
00025     if (classPool == null) {
00026       classPool = Collections.synchronizedMap(new HashMap<Integer, ThreadVectorPool>());
00027       threadPool.put(prototype.getClass(), classPool);
00028     }
00029     ThreadVectorPool pool = classPool.get(dimension);
00030     if (pool == null) {
00031       pool = new ThreadVectorPool(prototype, dimension);
00032       classPool.put(dimension, pool);
00033     }
00034     pool.allocate();
00035     return pool;
00036   }
00037 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark