01: /*
02: * Javassist, a Java-bytecode translator toolkit.
03: * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
04: *
05: * The contents of this file are subject to the Mozilla Public License Version
06: * 1.1 (the "License"); you may not use this file except in compliance with
07: * the License. Alternatively, the contents of this file may be used under
08: * the terms of the GNU Lesser General Public License Version 2.1 or later.
09: *
10: * Software distributed under the License is distributed on an "AS IS" basis,
11: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12: * for the specific language governing rights and limitations under the
13: * License.
14: */
15:
16: package javassist.bytecode;
17:
18: final class LongVector {
19: static final int ASIZE = 128;
20: static final int ABITS = 7; // ASIZE = 2^ABITS
21: static final int VSIZE = 8;
22: private Object[][] objects;
23: private int elements;
24:
25: public LongVector() {
26: objects = new Object[VSIZE][];
27: elements = 0;
28: }
29:
30: public LongVector(int initialSize) {
31: int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE;
32: objects = new Object[vsize][];
33: elements = 0;
34: }
35:
36: public int size() {
37: return elements;
38: }
39:
40: public int capacity() {
41: return objects.length * ASIZE;
42: }
43:
44: public Object elementAt(int i) {
45: if (i < 0 || elements <= i)
46: return null;
47:
48: return objects[i >> ABITS][i & (ASIZE - 1)];
49: }
50:
51: public void addElement(Object value) {
52: int nth = elements >> ABITS;
53: int offset = elements & (ASIZE - 1);
54: int len = objects.length;
55: if (nth >= len) {
56: Object[][] newObj = new Object[len + VSIZE][];
57: System.arraycopy(objects, 0, newObj, 0, len);
58: objects = newObj;
59: }
60:
61: if (objects[nth] == null)
62: objects[nth] = new Object[ASIZE];
63:
64: objects[nth][offset] = value;
65: elements++;
66: }
67: }
|