sboag       99/12/12 23:40:11

  Modified:    src/org/apache/xalan/xpath/xml NodeVector.java
                        StringToStringTable.java StringVector.java
  Added:       src/org/apache/xalan/xpath/xml BoolStack.java ElemDesc.java
                        IntStack.java IntVector.java
                        StringToStringTableVector.java
  Log:
  New classes for various optimizations.
  
  Revision  Changes    Path
  1.2       +4 -5      xml-xalan/src/org/apache/xalan/xpath/xml/NodeVector.java
  
  Index: NodeVector.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/NodeVector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeVector.java   1999/12/02 06:08:51     1.1
  +++ NodeVector.java   1999/12/13 07:40:11     1.2
  @@ -69,8 +69,7 @@
     private int m_mapSize;
   
     /**
  -   * Default constructor.  Note that the default 
  -   * block size is very small, for small lists.
  +   * Default constructor.
      */
     public NodeVector()
     {
  @@ -121,19 +120,19 @@
      */
     public final void insertElementAt(Node value, int at)
     {
  -    if((at+1) >= m_mapSize)
  +    if((m_firstFree+1) >= m_mapSize)
       {
         m_mapSize+=m_blocksize;
         Node newMap[] = new Node[m_mapSize];
         System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
         m_map = newMap;
       }
  -    if((at+1) < (m_firstFree-1))
  +    if(at <= (m_firstFree-1))
       {
         System.arraycopy(m_map, at, m_map, at+1, m_firstFree-at);
       }
       m_map[at] = value;
  -    m_firstFree = at+1;
  +    m_firstFree++;
     }
   
     /**
  
  
  
  1.2       +16 -0     
xml-xalan/src/org/apache/xalan/xpath/xml/StringToStringTable.java
  
  Index: StringToStringTable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/StringToStringTable.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StringToStringTable.java  1999/11/30 16:51:16     1.1
  +++ StringToStringTable.java  1999/12/13 07:40:11     1.2
  @@ -128,6 +128,22 @@
     }
   
     /**
  +   * Tell if the table contains the given string.
  +   */
  +  public final String getIgnoreCase(String key)
  +  {
  +    if(null == key)
  +      return null;
  +    
  +    for(int i = 0; i < m_firstFree; i+=2)
  +    {
  +      if(m_map[i].equalsIgnoreCase(key))
  +        return m_map[i+1];
  +    }
  +    return null;
  +  }
  +
  +  /**
      * Tell if the table contains the given string in the value.
      */
     public final String getByValue(String val)
  
  
  
  1.3       +54 -0     
xml-xalan/src/org/apache/xalan/xpath/xml/StringVector.java
  
  Index: StringVector.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/src/org/apache/xalan/xpath/xml/StringVector.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StringVector.java 1999/12/02 06:04:07     1.2
  +++ StringVector.java 1999/12/13 07:40:11     1.3
  @@ -133,6 +133,8 @@
      */
     public final boolean contains(String s)
     {
  +    if(null == s)
  +      return false;
       for(int i = 0; i < m_firstFree; i++)
       {
         if(m_map[i].equals(s))
  @@ -141,5 +143,57 @@
       return false;
     }
   
  +  /**
  +   * Tell if the table contains the given string.
  +   */
  +  public final boolean containsIgnoreCase(String s)
  +  {
  +    if(null == s)
  +      return false;
  +    for(int i = 0; i < m_firstFree; i++)
  +    {
  +      if(m_map[i].equalsIgnoreCase(s))
  +        return true;
  +    }
  +    return false;
  +  }
  +
  +  /**
  +   * Tell if the table contains the given string.
  +   */
  +  public final void push(String s)
  +  {
  +    if((m_firstFree+1) >= m_mapSize)
  +    {
  +      m_mapSize+=m_blocksize;
  +      String newMap[] = new String[m_mapSize];
  +      System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
  +      m_map = newMap;
  +    }
  +    m_map[m_firstFree] = s;
  +    m_firstFree++;
  +  }
  +
  +  /**
  +   * Tell if the table contains the given string.
  +   */
  +  public final String pop()
  +  {
  +    if(m_firstFree <= 0)
  +      return null;
  +    
  +    m_firstFree--;
  +    String s = m_map[m_firstFree];
  +    m_map[m_firstFree] = null;
  +    return s;
  +  }
  +
  +  /**
  +   * Tell if the table contains the given string.
  +   */
  +  public final String peek()
  +  {
  +    return (m_firstFree <= 0) ? null : m_map[m_firstFree-1];
  +  }
   
   }
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xpath/xml/BoolStack.java
  
  Index: BoolStack.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  import java.util.EmptyStackException;
  
  /**
   * Simple vector and stack for boolean values.
   */
  public class BoolStack
  {
    
    private int m_blocksize;
    private boolean m_map[];
    private int m_firstFree = 0;
    private int m_mapSize;
  
    /**
     * Default constructor.  Note that the default 
     * block size is very small, for small lists.
     */
    public BoolStack()
    {
      m_blocksize = 32;
      m_mapSize = m_blocksize;
      m_map = new boolean[m_blocksize]; 
    }
  
    /**
     * Construct a IntVector, using the given block size.
     */
    public BoolStack(int blocksize)
    {
      m_blocksize = blocksize;
      m_mapSize = blocksize;
      m_map = new boolean[blocksize]; 
    }
    
    /**
     * Get the length of the list.
     */
    public final int size()
    {
      return m_firstFree;
    }
  
    /**
     * Append a int onto the vector.
     */
    public final void addElement(boolean value)
    {
      if((m_firstFree+1) >= m_mapSize)
      {
        m_mapSize+=m_blocksize;
        boolean newMap[] = new boolean[m_mapSize];
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
        m_map = newMap;
      }
      m_map[m_firstFree] = value;
      m_firstFree++;
    }
  
    /**
     * Inserts the specified node in this vector at the specified index. 
     * Each component in this vector with an index greater or equal to 
     * the specified index is shifted upward to have an index one greater 
     * than the value it had previously. 
     */
    public final void insertElementAt(boolean value, int at)
    {
      if((m_firstFree+1) >= m_mapSize)
      {
        m_mapSize+=m_blocksize;
        boolean newMap[] = new boolean[m_mapSize];
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
        m_map = newMap;
      }
      if(at <= (m_firstFree-1))
      {
        System.arraycopy(m_map, at, m_map, at+1, m_firstFree-at);
      }
      m_map[at] = value;
      m_firstFree++;
    }
  
    /**
     * Inserts the specified node in this vector at the specified index. 
     * Each component in this vector with an index greater or equal to 
     * the specified index is shifted upward to have an index one greater 
     * than the value it had previously. 
     */
    public final void removeAllElements()
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        m_map[i] = false;
      }
      m_firstFree = 0;
    }
      
    /**
     * Deletes the component at the specified index. Each component in 
     * this vector with an index greater or equal to the specified 
     * index is shifted downward to have an index one smaller than 
     * the value it had previously. 
     */
    public final void removeElementAt(int i)
    {
      if(i > m_firstFree)
        System.arraycopy(m_map, i+1, m_map, i, m_firstFree);
      else
        m_map[i] = false;
      m_firstFree--;
    }
    
    /**
     * Sets the component at the specified index of this vector to be the 
     * specified object. The previous component at that position is discarded. 
     * 
     * The index must be a value greater than or equal to 0 and less 
     * than the current size of the vector. 
     */
    public final void setElementAt(boolean value, int index)
    {
      m_map[index] = value;
    }
  
    /**
     * Get the nth element.
     */
    public final boolean elementAt(int i)
    {
      return m_map[i];
    }
    
    /**
     * Searches for the first occurence of the given argument, 
     * beginning the search at index, and testing for equality 
     * using the equals method. 
     * @return the index of the first occurrence of the object 
     * argument in this vector at position index or later in the 
     * vector; returns -1 if the object is not found. 
     */
    public final int lastIndexOf(boolean elem)
    {
      for(int i = (m_firstFree - 1); i >= 0; i--)
      {
        if(m_map[i] == elem)
          return i;
      }
      return java.lang.Integer.MIN_VALUE;
    }
    
    /**
     * Pushes an item onto the top of this stack. 
     *
     * @param   i   the int to be pushed onto this stack.
     * @return  the <code>item</code> argument.
     * @since   JDK1.0
     */
    public boolean push(boolean i) 
    {
      addElement(i);
  
      return i;
    }
  
    /**
     * Removes the object at the top of this stack and returns that 
     * object as the value of this function. 
     *
     * @return     The object at the top of this stack.
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public boolean pop() 
    {
      boolean   i;
      int       len = size();
  
      i = peek();
      removeElementAt(len - 1);
  
      return i;
    }
  
    /**
     * Looks at the object at the top of this stack without removing it 
     * from the stack. 
     *
     * @return     the object at the top of this stack. 
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public boolean peek() 
    {
      int       len = size();
  
      if (len == 0)
        return false;
      return elementAt(len - 1);
    }
  
  /**
     * Looks at the object at the top of this stack without removing it 
     * from the stack. 
     *
     * @return     the object at the top of this stack. 
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public void setTop(boolean val) 
    {
      int       len = size();
      if (len == 0)
        throw new EmptyStackException();
    setElementAt(val, len - 1);
    }
  
    /**
     * Tests if this stack is empty.
     *
     * @return  <code>true</code> if this stack is empty;
     *          <code>false</code> otherwise.
     * @since   JDK1.0
     */
    public boolean isEmpty() 
    {
      return size() == 0;
    }
  
  }
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xpath/xml/ElemDesc.java
  
  Index: ElemDesc.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  import java.util.Hashtable;
  
  class ElemDesc
  {
    int m_flags;
    Hashtable m_attrs = null;
    
    static final int EMPTY = (1 << 1);
    static final int FLOW = (1 << 2);
    static final int BLOCK = (1 << 3)|FLOW;
    static final int BLOCKFORM = (1 << 4);
    static final int BLOCKFORMFIELDSET = (1 << 5);
    static final int CDATA = (1 << 6);
    static final int PCDATA = (1 << 7);
    static final int RAW = (1 << 8);
    static final int INLINE = (1 << 9)|FLOW;
    static final int INLINEA = (1 << 10);
    static final int INLINELABEL = (1 << 11);
    static final int FONTSTYLE = (1 << 12)|INLINE|INLINEA|INLINELABEL;
    static final int PHRASE = (1 << 13)|INLINE|INLINEA|INLINELABEL;
    static final int FORMCTRL = (1 << 14)|INLINE|INLINEA;
    static final int SPECIAL = (1 << 15)|INLINE|INLINELABEL;
    static final int ASPECIAL = (1 << 16)|INLINEA;
    static final int HEADMISC = (1 << 17);
    static final int HEAD = (1 << 18)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
    static final int LIST = (1 << 19)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
    static final int PREFORMATTED = (1 << 20)|BLOCK|BLOCKFORM|BLOCKFORMFIELDSET;
    static final int WHITESPACESENSITIVE = (1 << 21);
  
    static final int ATTRURL = (1 << 1);
    static final int ATTREMPTY = (1 << 2);
  
    ElemDesc(int flags)
    {
      m_flags = flags;
    }
    
    boolean is(int flags)
    {
      return (m_flags & flags) != 0;
    }
    
    void setAttr(String name, int flags)
    {
      if(null == m_attrs)
        m_attrs = new Hashtable();
      
      m_attrs.put(name, new Integer(flags));
    }
    
    boolean isAttrFlagSet(String name, int flags)
    {
      if(null != m_attrs)
      {
        Integer _flags = (Integer)m_attrs.get(name);
        if(null != _flags)
        {
          return (_flags.intValue() & flags) != 0;
        }
      }
      return false;
    }
    
    
  }
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xpath/xml/IntStack.java
  
  Index: IntStack.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  import java.util.EmptyStackException;
  
  public class IntStack extends IntVector
  {
      /**
     * Default constructor.  Note that the default 
     * block size is very small, for small lists.
     */
    public IntStack()
    {
      super(); 
    }
  
    /**
     * Construct a IntVector, using the given block size.
     */
    public IntStack(int blocksize)
    {
      super(blocksize); 
    }
    
    /**
     * Pushes an item onto the top of this stack. 
     *
     * @param   i   the int to be pushed onto this stack.
     * @return  the <code>item</code> argument.
     * @since   JDK1.0
     */
    public int push(int i) 
    {
      addElement(i);
  
      return i;
    }
  
    /**
     * Removes the object at the top of this stack and returns that 
     * object as the value of this function. 
     *
     * @return     The object at the top of this stack.
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public int pop() 
    {
      int       i;
      int       len = size();
  
      i = peek();
      removeElementAt(len - 1);
  
      return i;
    }
  
    /**
     * Looks at the object at the top of this stack without removing it 
     * from the stack. 
     *
     * @return     the object at the top of this stack. 
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public int peek() 
    {
      int       len = size();
  
      if (len == 0)
        throw new EmptyStackException();
      return elementAt(len - 1);
    }
  
  /**
     * Looks at the object at the top of this stack without removing it 
     * from the stack. 
     *
     * @return     the object at the top of this stack. 
     * @exception  EmptyStackException  if this stack is empty.
     * @since      JDK1.0
     */
    public void setTop(int val) 
    {
      int       len = size();
      if (len == 0)
        throw new EmptyStackException();
    setElementAt(val, len - 1);
    }
  
    /**
     * Tests if this stack is empty.
     *
     * @return  <code>true</code> if this stack is empty;
     *          <code>false</code> otherwise.
     * @since   JDK1.0
     */
    public boolean empty() 
    {
      return size() == 0;
    }
  
    /**
     * Returns where an object is on this stack. 
     *
     * @param   o   the desired object.
     * @return  the distance from the top of the stack where the object is]
     *          located; the return value <code>-1</code> indicates that the
     *          object is not on the stack.
     * @since   JDK1.0
     */
    public int search(int o) 
    {
      int i = lastIndexOf(o);
  
      if (i >= 0) 
      {
        return size() - i;
      }
      return -1;
    }
  
  }
  
  
  
  1.1                  xml-xalan/src/org/apache/xalan/xpath/xml/IntVector.java
  
  Index: IntVector.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  /**
   * A very simple table that stores a list of int.
   */
  public class IntVector
  {
    private int m_blocksize;
    private int m_map[];
    private int m_firstFree = 0;
    private int m_mapSize;
  
    /**
     * Default constructor.  Note that the default 
     * block size is very small, for small lists.
     */
    public IntVector()
    {
      m_blocksize = 32;
      m_mapSize = m_blocksize;
      m_map = new int[m_blocksize]; 
    }
  
    /**
     * Construct a IntVector, using the given block size.
     */
    public IntVector(int blocksize)
    {
      m_blocksize = blocksize;
      m_mapSize = blocksize;
      m_map = new int[blocksize]; 
    }
    
    /**
     * Get the length of the list.
     */
    public final int size()
    {
      return m_firstFree;
    }
  
    /**
     * Append a int onto the vector.
     */
    public final void addElement(int value)
    {
      if((m_firstFree+1) >= m_mapSize)
      {
        m_mapSize+=m_blocksize;
        int newMap[] = new int[m_mapSize];
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
        m_map = newMap;
      }
      m_map[m_firstFree] = value;
      m_firstFree++;
    }
  
    /**
     * Inserts the specified node in this vector at the specified index. 
     * Each component in this vector with an index greater or equal to 
     * the specified index is shifted upward to have an index one greater 
     * than the value it had previously. 
     */
    public final void insertElementAt(int value, int at)
    {
      if((m_firstFree+1) >= m_mapSize)
      {
        m_mapSize+=m_blocksize;
        int newMap[] = new int[m_mapSize];
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
        m_map = newMap;
      }
      if(at <= (m_firstFree-1))
      {
        System.arraycopy(m_map, at, m_map, at+1, m_firstFree-at);
      }
      m_map[at] = value;
      m_firstFree++;
    }
  
    /**
     * Inserts the specified node in this vector at the specified index. 
     * Each component in this vector with an index greater or equal to 
     * the specified index is shifted upward to have an index one greater 
     * than the value it had previously. 
     */
    public final void removeAllElements()
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        m_map[i] = java.lang.Integer.MIN_VALUE;
      }
      m_firstFree = 0;
    }
    
    /**
     * Removes the first occurrence of the argument from this vector. 
     * If the object is found in this vector, each component in the vector 
     * with an index greater or equal to the object's index is shifted 
     * downward to have an index one smaller than the value it had 
     * previously. 
     */
    public final boolean removeElement(int s)
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        if(m_map[i] == s)
        {
          if(i > m_firstFree)
            System.arraycopy(m_map, i+1, m_map, i-1, m_firstFree-i);
          else
            m_map[i] = java.lang.Integer.MIN_VALUE;
          m_firstFree--;
          return true;
        }
      }
      return false;
    }
    
    /**
     * Deletes the component at the specified index. Each component in 
     * this vector with an index greater or equal to the specified 
     * index is shifted downward to have an index one smaller than 
     * the value it had previously. 
     */
    public final void removeElementAt(int i)
    {
      if(i > m_firstFree)
        System.arraycopy(m_map, i+1, m_map, i, m_firstFree);
      else
        m_map[i] = java.lang.Integer.MIN_VALUE;
      m_firstFree--;
    }
    
    /**
     * Sets the component at the specified index of this vector to be the 
     * specified object. The previous component at that position is discarded. 
     * 
     * The index must be a value greater than or equal to 0 and less 
     * than the current size of the vector. 
     */
    public final void setElementAt(int node, int index)
    {
      m_map[index] = node;
    }
  
    /**
     * Get the nth element.
     */
    public final int elementAt(int i)
    {
      return m_map[i];
    }
    
    /**
     * Tell if the table contains the given node.
     */
    public final boolean contains(int s)
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        if(m_map[i] == s)
          return true;
      }
      return false;
    }
    
    /**
     * Searches for the first occurence of the given argument, 
     * beginning the search at index, and testing for equality 
     * using the equals method. 
     * @return the index of the first occurrence of the object 
     * argument in this vector at position index or later in the 
     * vector; returns -1 if the object is not found. 
     */
    public final int indexOf(int elem, int index)
    {
      for(int i = index; i < m_firstFree; i++)
      {
        if(m_map[i] == elem)
          return i;
      }
      return java.lang.Integer.MIN_VALUE;
    }
  
    /**
     * Searches for the first occurence of the given argument, 
     * beginning the search at index, and testing for equality 
     * using the equals method. 
     * @return the index of the first occurrence of the object 
     * argument in this vector at position index or later in the 
     * vector; returns -1 if the object is not found. 
     */
    public final int indexOf(int elem)
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        if(m_map[i] == elem)
          return i;
      }
      return java.lang.Integer.MIN_VALUE;
    }
  
    /**
     * Searches for the first occurence of the given argument, 
     * beginning the search at index, and testing for equality 
     * using the equals method. 
     * @return the index of the first occurrence of the object 
     * argument in this vector at position index or later in the 
     * vector; returns -1 if the object is not found. 
     */
    public final int lastIndexOf(int elem)
    {
      for(int i = (m_firstFree - 1); i >= 0; i--)
      {
        if(m_map[i] == elem)
          return i;
      }
      return java.lang.Integer.MIN_VALUE;
    }
  
  }
  
  
  
  1.1                  
xml-xalan/src/org/apache/xalan/xpath/xml/StringToStringTableVector.java
  
  Index: StringToStringTableVector.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "XSLT4J" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.xalan.xpath.xml;
  
  /**
   * A very simple table that stores a list of StringToStringTables, optimized 
   * for small lists.
   */
  public class StringToStringTableVector
  {
    private int m_blocksize;
    private StringToStringTable m_map[];
    private int m_firstFree = 0;
    private int m_mapSize;
  
    /**
     * Default constructor.  Note that the default 
     * block size is very small, for small lists.
     */
    public StringToStringTableVector()
    {
      m_blocksize = 8;
      m_mapSize = m_blocksize;
      m_map = new StringToStringTable[m_blocksize]; 
    }
  
    /**
     * Construct a StringToStringTableVector, using the given block size.
     */
    public StringToStringTableVector(int blocksize)
    {
      m_blocksize = blocksize;
      m_mapSize = blocksize;
      m_map = new StringToStringTable[blocksize]; 
    }
    
    /**
     * Get the length of the list.
     */
    public final int getLength()
    {
      return m_firstFree;
    }
  
    /**
     * Get the length of the list.
     */
    public final int size()
    {
      return m_firstFree;
    }
  
    /**
     * Append a string onto the vector.
     */
    public final void addElement(StringToStringTable value)
    {
      if((m_firstFree+1) >= m_mapSize)
      {
        m_mapSize+=m_blocksize;
        StringToStringTable newMap[] = new StringToStringTable[m_mapSize];
        System.arraycopy(m_map, 0, newMap, 0, m_firstFree+1);
        m_map = newMap;
      }
      m_map[m_firstFree] = value;
      m_firstFree++;
    }
    
    /**
     * Given a string, find the last added occurance value
     * that matches the key.
     */
    public final String get(String key)
    {
      for(int i=m_firstFree-1; i >= 0; --i)
      {
        String nsuri = m_map[i].get(key);
        if (nsuri != null)
          return nsuri;
      }
      return null;
    }
  
    /**
     * Given a string, find the last added occurance value
     * that matches the key.
     */
    public final boolean containsKey(String key)
    {
      for(int i=m_firstFree-1; i >= 0; --i)
      {
        if (m_map[i].get(key) != null)
          return true;
      }
      return false;
    }
  
    /**
     * Remove the last element.
     */
    public final void removeLastElem()
    {
      if(m_firstFree > 0)
      {
        m_map[m_firstFree] = null;
        m_firstFree--;
      }
    }
    
    /**
     * Get the nth element.
     */
    public final StringToStringTable elementAt(int i)
    {
      return m_map[i];
    }
    
    /**
     * Tell if the table contains the given string.
     */
    public final boolean contains(StringToStringTable s)
    {
      for(int i = 0; i < m_firstFree; i++)
      {
        if(m_map[i].equals(s))
          return true;
      }
      return false;
    }
  
  
  }
  
  
  

Reply via email to