src/org/gel/mauve/tree/TreeStore.java

Go to the documentation of this file.
00001 package org.gel.mauve.tree;
00002 
00003 import java.io.Serializable;
00004 import java.util.Arrays;
00005 
00006 public class TreeStore implements Serializable {
00007         final static int NULL_REF = -1;
00008 
00009         private final static int INITIAL_SIZE = 10;
00010 
00011         private final static float SCALE_FACTOR = 1.1f;
00012 
00013         private int nodeCount = 0;
00014 
00015         public int [] parent = new int [INITIAL_SIZE];
00016 
00017         public int [] left = new int [INITIAL_SIZE];
00018 
00019         public int [] right = new int [INITIAL_SIZE];
00020 
00021         public long [] length = new long [INITIAL_SIZE];
00022 
00023         public long [] seqLength = new long [INITIAL_SIZE];
00024 
00025         public Key [] key = new Key [INITIAL_SIZE];
00026 
00027         public TreeStore () {
00028                 Arrays.fill (parent, NULL_REF);
00029                 Arrays.fill (left, NULL_REF);
00030                 Arrays.fill (right, NULL_REF);
00031         }
00032 
00033         public int createGistNode () {
00034                 if (nodeCount >= parent.length) {
00035                         resizeArrays ();
00036                 }
00037                 int val = nodeCount;
00038                 nodeCount++;
00039                 return val;
00040         }
00041 
00042         private void resizeArrays () {
00043                 int newSize = (int) (parent.length * SCALE_FACTOR);
00044 
00045                 int [] new_parent = new int [newSize];
00046                 Arrays.fill (new_parent, TreeStore.NULL_REF);
00047                 System.arraycopy (parent, 0, new_parent, 0, parent.length);
00048                 parent = new_parent;
00049 
00050                 int [] new_left = new int [newSize];
00051                 Arrays.fill (new_left, TreeStore.NULL_REF);
00052                 System.arraycopy (left, 0, new_left, 0, left.length);
00053                 left = new_left;
00054 
00055                 int [] new_right = new int [newSize];
00056                 Arrays.fill (new_right, TreeStore.NULL_REF);
00057                 System.arraycopy (right, 0, new_right, 0, right.length);
00058                 right = new_right;
00059 
00060                 long [] new_length = new long [newSize];
00061                 System.arraycopy (length, 0, new_length, 0, length.length);
00062                 length = new_length;
00063 
00064                 long [] new_seq_length = new long [newSize];
00065                 System.arraycopy (seqLength, 0, new_seq_length, 0, seqLength.length);
00066                 seqLength = new_seq_length;
00067 
00068                 Key [] new_key = new Key [newSize];
00069                 System.arraycopy (key, 0, new_key, 0, key.length);
00070                 key = new_key;
00071         }
00072 
00073         public void pruneArrays () {
00074                 int [] new_parent = new int [nodeCount];
00075                 System.arraycopy (parent, 0, new_parent, 0, nodeCount);
00076                 parent = new_parent;
00077 
00078                 int [] new_left = new int [nodeCount];
00079                 System.arraycopy (left, 0, new_left, 0, nodeCount);
00080                 left = new_left;
00081 
00082                 int [] new_right = new int [nodeCount];
00083                 System.arraycopy (right, 0, new_right, 0, nodeCount);
00084                 right = new_right;
00085 
00086                 long [] new_length = new long [nodeCount];
00087                 System.arraycopy (length, 0, new_length, 0, nodeCount);
00088                 length = new_length;
00089 
00090                 long [] new_seq_length = new long [nodeCount];
00091                 System.arraycopy (seqLength, 0, new_seq_length, 0, nodeCount);
00092                 seqLength = new_seq_length;
00093 
00094                 Key [] new_key = new Key [nodeCount];
00095                 System.arraycopy (key, 0, new_key, 0, nodeCount);
00096                 key = new_key;
00097         }
00098 }

Generated on Mon Aug 19 06:03:44 2013 for Mauve by doxygen 1.3.6