< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMStringPool.java

Print this page


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * @LastModified: Oct 2017
   4  */
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *      http://www.apache.org/licenses/LICENSE-2.0
  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xml.internal.dtm.ref;
  23 


  36  * <li>Index-to-String lookup speed is slightly less so.</li>
  37  * <li>Threadsafety is not guaranteed at this level.
  38  * Enforce that in the application if needed.</li>
  39  * <li>Storage efficiency is an issue but not a huge one.
  40  * It is expected that string pools won't exceed about 2000 entries.</li>
  41  * </ul>
  42  * </p>
  43  *
  44  * <p>Implementation detail: A standard Hashtable is relatively
  45  * inefficient when looking up primitive int values, especially when
  46  * we're already maintaining an int-to-string vector.  So I'm
  47  * maintaining a simple hash chain within this class.</p>
  48  *
  49  * <p>NOTE: There is nothing in the code that has a real dependency upon
  50  * String. It would work with any object type that implements reliable
  51  * .hashCode() and .equals() operations. The API enforces Strings because
  52  * it's safer that way, but this could trivially be turned into a general
  53  * ObjectPool if one was needed.</p>
  54  *
  55  * <p>Status: Passed basic test in main().</p>
  56  * */


  57 public class DTMStringPool
  58 {
  59   List<String> m_intToString;
  60   static final int HASHPRIME=101;
  61   int[] m_hashStart=new int[HASHPRIME];
  62   IntVector m_hashChain;
  63   public static final int NULL=-1;
  64 
  65   /**
  66    * Create a DTMStringPool using the given chain size
  67    *
  68    * @param chainSize The size of the hash chain vector
  69    */
  70   public DTMStringPool(int chainSize)
  71     {
  72       m_intToString = new ArrayList<>();
  73       m_hashChain= new IntVector(chainSize);
  74       removeAllElements();
  75 
  76       // -sb Add this to force empty strings to be index 0.


   1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.

   3  */
   4 /*
   5  * Licensed to the Apache Software Foundation (ASF) under one or more
   6  * contributor license agreements.  See the NOTICE file distributed with
   7  * this work for additional information regarding copyright ownership.
   8  * The ASF licenses this file to You under the Apache License, Version 2.0
   9  * (the "License"); you may not use this file except in compliance with
  10  * the License.  You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xml.internal.dtm.ref;
  22 


  35  * <li>Index-to-String lookup speed is slightly less so.</li>
  36  * <li>Threadsafety is not guaranteed at this level.
  37  * Enforce that in the application if needed.</li>
  38  * <li>Storage efficiency is an issue but not a huge one.
  39  * It is expected that string pools won't exceed about 2000 entries.</li>
  40  * </ul>
  41  * </p>
  42  *
  43  * <p>Implementation detail: A standard Hashtable is relatively
  44  * inefficient when looking up primitive int values, especially when
  45  * we're already maintaining an int-to-string vector.  So I'm
  46  * maintaining a simple hash chain within this class.</p>
  47  *
  48  * <p>NOTE: There is nothing in the code that has a real dependency upon
  49  * String. It would work with any object type that implements reliable
  50  * .hashCode() and .equals() operations. The API enforces Strings because
  51  * it's safer that way, but this could trivially be turned into a general
  52  * ObjectPool if one was needed.</p>
  53  *
  54  * <p>Status: Passed basic test in main().</p>
  55  *
  56  * @LastModified: Oct 2017
  57  */
  58 public class DTMStringPool
  59 {
  60   List<String> m_intToString;
  61   static final int HASHPRIME=101;
  62   int[] m_hashStart=new int[HASHPRIME];
  63   IntVector m_hashChain;
  64   public static final int NULL=-1;
  65 
  66   /**
  67    * Create a DTMStringPool using the given chain size
  68    *
  69    * @param chainSize The size of the hash chain vector
  70    */
  71   public DTMStringPool(int chainSize)
  72     {
  73       m_intToString = new ArrayList<>();
  74       m_hashChain= new IntVector(chainSize);
  75       removeAllElements();
  76 
  77       // -sb Add this to force empty strings to be index 0.


< prev index next >