You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LongVector.java 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. Alternatively, the contents of this file may be used under
  8. * the terms of the GNU Lesser General Public License Version 2.1 or later.
  9. *
  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. package javassist.bytecode;
  16. final class LongVector {
  17. static final int ASIZE = 128;
  18. static final int ABITS = 7; // ASIZE = 2^ABITS
  19. static final int VSIZE = 8;
  20. private Object[][] objects;
  21. private int elements;
  22. public LongVector() {
  23. objects = new Object[VSIZE][];
  24. elements = 0;
  25. }
  26. public LongVector(int initialSize) {
  27. int vsize = ((initialSize >> ABITS) & ~(VSIZE - 1)) + VSIZE;
  28. objects = new Object[vsize][];
  29. elements = 0;
  30. }
  31. public int size() { return elements; }
  32. public int capacity() { return objects.length * ASIZE; }
  33. public Object elementAt(int i) {
  34. if (i < 0 || elements <= i)
  35. return null;
  36. return objects[i >> ABITS][i & (ASIZE - 1)];
  37. }
  38. public void addElement(Object value) {
  39. int nth = elements >> ABITS;
  40. int offset = elements & (ASIZE - 1);
  41. int len = objects.length;
  42. if (nth >= len) {
  43. Object[][] newObj = new Object[len + VSIZE][];
  44. System.arraycopy(objects, 0, newObj, 0, len);
  45. objects = newObj;
  46. }
  47. if (objects[nth] == null)
  48. objects[nth] = new Object[ASIZE];
  49. objects[nth][offset] = value;
  50. elements++;
  51. }
  52. }