LongVector.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 64-bit integers (longs). */
  7. public abstract class LongVector<E> extends PrimIntegerVector<E>
  8. {
  9. long[] data;
  10. protected static long[] empty = new long[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. long[] tmp = new long[length];
  21. System.arraycopy(data, 0, tmp, 0,
  22. oldLength < length ? oldLength : length);
  23. data = tmp;
  24. }
  25. }
  26. public long[] getBuffer() { return data; }
  27. protected void setBuffer(Object buffer) { data = (long[]) buffer; }
  28. public final long getLong(int index) {
  29. return data[effectiveIndex(index)];
  30. }
  31. public final long getLongRaw(int index) {
  32. return data[index];
  33. }
  34. public final int getIntRaw(int index) {
  35. return (int) data[index];
  36. }
  37. public final void setLong(int index, long value) {
  38. checkCanWrite(); // FIXME maybe inline and fold into following
  39. data[effectiveIndex(index)] = value;
  40. }
  41. public final void setLongRaw(int index, long value) {
  42. data[index] = value;
  43. }
  44. public void add(long v) {
  45. int sz = size();
  46. addSpace(sz, 1);
  47. setLong(sz, v);
  48. }
  49. protected void clearBuffer(int start, int count) {
  50. long[] d = data;
  51. while (--count >= 0)
  52. d[start++] = 0;
  53. }
  54. }