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 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Javassist, a Java-bytecode translator toolkit.
  3. * Copyright (C) 1999-2004 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 SIZE = 128;
  18. private int num;
  19. private Object[] objects;
  20. private LongVector next;
  21. public LongVector() {
  22. this(SIZE);
  23. }
  24. public LongVector(int initialSize) {
  25. num = 0;
  26. objects = new Object[initialSize];
  27. next = null;
  28. }
  29. public void addElement(Object obj) {
  30. LongVector p = this;
  31. while (p.next != null)
  32. p = p.next;
  33. if (p.num < p.objects.length)
  34. p.objects[p.num++] = obj;
  35. else {
  36. LongVector q = p.next = new LongVector(SIZE);
  37. q.objects[q.num++] = obj;
  38. }
  39. }
  40. public int size() {
  41. LongVector p = this;
  42. int s = 0;
  43. while (p != null) {
  44. s += p.num;
  45. p = p.next;
  46. }
  47. return s;
  48. }
  49. public Object elementAt(int i) {
  50. LongVector p = this;
  51. while (p != null)
  52. if (i < p.num)
  53. return p.objects[i];
  54. else {
  55. i -= p.num;
  56. p = p.next;
  57. }
  58. return null;
  59. }
  60. /*
  61. public static void main(String [] args) {
  62. LongVector v = new LongVector(4);
  63. int i;
  64. for (i = 0; i < 128; ++i)
  65. v.addElement(new Integer(i));
  66. System.out.println(v.size());
  67. for (i = 0; i < v.size(); ++i) {
  68. System.out.print(v.elementAt(i));
  69. System.out.print(", ");
  70. }
  71. }
  72. */
  73. }