Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gp.vm.instructions.InstructionCache.java

Here you can find all the information about the file org.dgpf.gp.vm.instructions.InstructionCache.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Thomas Weise
 * 
 * E-Mail           : tweise@gmx.de
 * Creation Date    : 2006-06-26 10:47:12
 * Original Filename: org.dgpf.gp.vm.instructions.caches.InstructionArrayCache.java
 * Version          : 1.0.0
 * Last modification: 2006-06-26
 *                by: Thomas Weise
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */

 
package org.dgpf.gp.vm.instructions;

import org.dgpf.gp.vm.base.Instruction;
import org.sfc.utils.Typesafe;

/**
 * An instruction cache basing on an array.
 * @param <Type> The sort of instruction stored.
 *
 * @author Thomas Weise
 */

public abstract class   InstructionCache<Type extends Instruction>
  {
/**
 * The instruction data.
 */

  private       Object[]  m_data ;
  
/**
 * Create a new instruction array cache.
 * @param p_init    The initial count of instructions stored.
 */

  public  InstructionCache(int p_init)
    {
    super();
    
    Object[] l_o;
    
    l_o = new Object[p_init];
    for(--p_init; p_init >= 0; p_init--)
      {
      l_o[p_init] = this.create(p_init);
      }
    
    this.m_data   = l_o;
    }
  
/**
 * Internally create a new instruction.
 * @param p_index The index property.
 * @return  The new instruction.
 */

  protected abstract  Type create(final int p_index);
  

/**
 * Obtain the instruction fitting to the given index.
 * @param p_index The index of the instruction to obtain.
 * @return  The instruction wanted or <code>null</code> if no such
 *          instruction is cached,
 */

  public  final Type  get (final int p_index)
    {
    Object[]  l_o;
    Type      l_t;
       
    l_o = this.m_data;
    
    if((p_index >= 0) && (p_index < l_o.length))
      {
      l_t = Typesafe.cast(l_o[p_index]);
      if(l_t != null) return l_t;
      l_t = this.create(p_index);
      l_o[p_index] = l_t;      
      return l_t;
      }
    
    l_t = this.create(p_index);
    if(l_t == null) return null;
    
    l_o = new Object[p_index << 1];
    System.arraycopy(this.m_data, 0, l_o, 0, this.m_data.length);    
    l_o[p_index] = l_t;
    return l_t;
    }
  }

File Information:

file name:InstructionCache.java
package:org.dgpf.gp.vm.instructions
qualified name:org.dgpf.gp.vm.instructions.InstructionCache.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gp/vm/instructions/InstructionCache.java
size:2.872 KB (2941 B)
uploaded: 2015-07-22 04:10:56 GMT+0000
last update: 2006-06-26 08:53:01 GMT+0000
last access: 2017-11-18 23:15:25 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-18 23:15:25 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo