2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 package org.apache.xpath.compiler;
26 * Like IntVector, but used only for the OpMap array. Length of array
27 * is kept in the m_lengthPos position of the array. Only the required methods
28 * are in included here.
31 public class OpMapVector {
33 /** Size of blocks to allocate */
34 protected int m_blocksize;
37 protected int m_map[]; // IntStack is trying to see this directly
39 /** Position where size of array is kept */
40 protected int m_lengthPos = 0;
43 protected int m_mapSize;
46 * Construct a OpMapVector, using the given block size.
48 * @param blocksize Size of block to allocate
50 public OpMapVector(int blocksize, int increaseSize, int lengthPos)
53 m_blocksize = increaseSize;
54 m_mapSize = blocksize;
55 m_lengthPos = lengthPos;
56 m_map = new int[blocksize];
60 * Get the nth element.
62 * @param i index of object to get
64 * @return object at given index
66 public final int elementAt(int i)
72 * Sets the component at the specified index of this vector to be the
73 * specified object. The previous component at that position is discarded.
75 * The index must be a value greater than or equal to 0 and less
76 * than the current size of the vector.
78 * @param value object to set
79 * @param index Index of where to set the object
81 public final void setElementAt(int value, int index)
83 if (index >= m_mapSize)
85 int oldSize = m_mapSize;
87 m_mapSize += m_blocksize;
89 int newMap[] = new int[m_mapSize];
91 System.arraycopy(m_map, 0, newMap, 0, oldSize);
101 * Reset the array to the supplied size. No checking is done.
103 * @param size The size to trim to.
105 public final void setToSize(int size) {
107 int newMap[] = new int[size];
109 System.arraycopy(m_map, 0, newMap, 0, m_map[m_lengthPos]);