1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id$
  18. */
  19. package com.sun.org.apache.xpath.internal.compiler;
  20. /**
  21. *
  22. * Like IntVector, but used only for the OpMap array. Length of array
  23. * is kept in the m_lengthPos position of the array. Only the required methods
  24. * are in included here.
  25. * @xsl.usage internal
  26. */
  27. public class OpMapVector {
  28. /** Size of blocks to allocate */
  29. protected int m_blocksize;
  30. /** Array of ints */
  31. protected int m_map[]; // IntStack is trying to see this directly
  32. /** Position where size of array is kept */
  33. protected int m_lengthPos = 0;
  34. /** Size of array */
  35. protected int m_mapSize;
  36. /**
  37. * Construct a OpMapVector, using the given block size.
  38. *
  39. * @param blocksize Size of block to allocate
  40. */
  41. public OpMapVector(int blocksize, int increaseSize, int lengthPos)
  42. {
  43. m_blocksize = increaseSize;
  44. m_mapSize = blocksize;
  45. m_lengthPos = lengthPos;
  46. m_map = new int[blocksize];
  47. }
  48. /**
  49. * Get the nth element.
  50. *
  51. * @param i index of object to get
  52. *
  53. * @return object at given index
  54. */
  55. public final int elementAt(int i)
  56. {
  57. return m_map[i];
  58. }
  59. /**
  60. * Sets the component at the specified index of this vector to be the
  61. * specified object. The previous component at that position is discarded.
  62. *
  63. * The index must be a value greater than or equal to 0 and less
  64. * than the current size of the vector.
  65. *
  66. * @param node object to set
  67. * @param index Index of where to set the object
  68. */
  69. public final void setElementAt(int value, int index)
  70. {
  71. if (index >= m_mapSize)
  72. {
  73. int oldSize = m_mapSize;
  74. m_mapSize += m_blocksize;
  75. int newMap[] = new int[m_mapSize];
  76. System.arraycopy(m_map, 0, newMap, 0, oldSize);
  77. m_map = newMap;
  78. }
  79. m_map[index] = value;
  80. }
  81. /*
  82. * Reset the array to the supplied size. No checking is done.
  83. *
  84. * @param size The size to trim to.
  85. */
  86. public final void setToSize(int size) {
  87. int newMap[] = new int[size];
  88. System.arraycopy(m_map, 0, newMap, 0, m_map[m_lengthPos]);
  89. m_mapSize = size;
  90. m_map = newMap;
  91. }
  92. }