169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal/*
269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Javassist, a Java-bytecode translator toolkit.
369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Copyright (C) 1999-2007 Shigeru Chiba. All Rights Reserved.
469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * The contents of this file are subject to the Mozilla Public License Version
669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * 1.1 (the "License"); you may not use this file except in compliance with
769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the License.  Alternatively, the contents of this file may be used under
869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * the terms of the GNU Lesser General Public License Version 2.1 or later.
969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal *
1069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * Software distributed under the License is distributed on an "AS IS" basis,
1169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
1269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * for the specific language governing rights and limitations under the
1369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal * License.
1469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal */
1569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalpackage javassist.bytecode;
1769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
1869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigalfinal class LongVector {
1969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    static final int ASIZE = 128;
2069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    static final int ABITS = 7;  // ASIZE = 2^ABITS
2169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    static final int VSIZE = 8;
2269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private ConstInfo[][] objects;
2369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    private int elements;
2469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
2569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public LongVector() {
2669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        objects = new ConstInfo[VSIZE][];
2769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        elements = 0;
2869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
2969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public LongVector(int initialSize) {
3169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE;
3269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        objects = new ConstInfo[vsize][];
3369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        elements = 0;
3469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
3569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int size() { return elements; }
3769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
3869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public int capacity() { return objects.length * ASIZE; }
3969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public ConstInfo elementAt(int i) {
4169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (i < 0 || elements <= i)
4269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            return null;
4369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        return objects[i >> ABITS][i & (ASIZE - 1)];
4569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
4669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
4769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    public void addElement(ConstInfo value) {
4869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int nth = elements >> ABITS;
4969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int offset = elements & (ASIZE - 1);
5069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        int len = objects.length;
5169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (nth >= len) {
5269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            ConstInfo[][] newObj = new ConstInfo[len + VSIZE][];
5369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            System.arraycopy(objects, 0, newObj, 0, len);
5469e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            objects = newObj;
5569e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        }
5669e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
5769e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        if (objects[nth] == null)
5869e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal            objects[nth] = new ConstInfo[ASIZE];
5969e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal
6069e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        objects[nth][offset] = value;
6169e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal        elements++;
6269e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal    }
6369e17611504376e4d4603925f8528dfc890fd2c6Luis Sigal}
64