IntVector.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // This file is generated from PrimVector.template. DO NOT EDIT!
  2. // Copyright (c) 2001, 2002, 2015 Per M.A. Bothner and Brainfood Inc.
  3. // This is free software; for terms and warranty disclaimer see ./COPYING.
  4. package gnu.lists;
  5. import java.io.*;
  6. /** Simple adjustable-length vector of signed or unsigned 32-bit integers (ints). */
  7. public abstract class IntVector<E> extends PrimIntegerVector<E>
  8. {
  9. int[] data;
  10. protected static int[] empty = new int[0];
  11. /** Get the allocated length of the data buffer. */
  12. public int getBufferLength() {
  13. return data.length;
  14. }
  15. public void copyBuffer(int length) {
  16. int oldLength = data.length;
  17. if (length == -1)
  18. length = oldLength;
  19. if (oldLength != length) {
  20. int[] tmp = new int[length];
  21. System.arraycopy(data, 0, tmp, 0,
  22. oldLength < length ? oldLength : length);
  23. data = tmp;
  24. }
  25. }
  26. public int[] getBuffer() { return data; }
  27. protected void setBuffer(Object buffer) { data = (int[]) buffer; }
  28. public final int getInt(int index) {
  29. return data[effectiveIndex(index)];
  30. }
  31. public final int getIntRaw(int index) {
  32. return data[index];
  33. }
  34. public final void setInt(int index, int value) {
  35. checkCanWrite(); // FIXME maybe inline and fold into following
  36. data[effectiveIndex(index)] = value;
  37. }
  38. public final void setIntRaw(int index, int value) {
  39. data[index] = value;
  40. }
  41. public void add(int v) {
  42. int sz = size();
  43. addSpace(sz, 1);
  44. setInt(sz, v);
  45. }
  46. protected void clearBuffer(int start, int count) {
  47. int[] d = data;
  48. while (--count >= 0)
  49. d[start++] = 0;
  50. }
  51. }