Move Flat3Map to map subpackage

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131351 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2003-11-18 23:23:05 +00:00
parent 92450f8141
commit 473cba8ee3
5 changed files with 26 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/Attic/Flat3Map.java,v 1.3 2003/11/14 22:58:27 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/map/Flat3Map.java,v 1.1 2003/11/18 23:23:05 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -55,7 +55,7 @@
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.commons.collections; package org.apache.commons.collections.map;
import java.util.AbstractCollection; import java.util.AbstractCollection;
import java.util.AbstractSet; import java.util.AbstractSet;
@ -66,6 +66,7 @@ import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.IteratorUtils;
import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.commons.collections.iterators.EntrySetMapIterator;
import org.apache.commons.collections.iterators.MapIterator; import org.apache.commons.collections.iterators.MapIterator;
import org.apache.commons.collections.iterators.ResettableIterator; import org.apache.commons.collections.iterators.ResettableIterator;
@ -86,18 +87,19 @@ import org.apache.commons.collections.iterators.ResettableIterator;
* The design uses two distinct modes of operation - flat and delegate. * The design uses two distinct modes of operation - flat and delegate.
* While the map is size 3 or less, operations map straight onto fields using * While the map is size 3 or less, operations map straight onto fields using
* switch statements. Once size 4 is reached, the map switches to delegate mode * switch statements. Once size 4 is reached, the map switches to delegate mode
* and never switches back. In delegate mode, all operations are forwarded * and only switches back when cleared. In delegate mode, all operations are
* straight to a HashMap resulting in the 5% performance loss. * forwarded straight to a HashMap resulting in the 5% performance loss.
* <p> * <p>
* The performance gains on puts are due to not needing to create a Map Entry * The performance gains on puts are due to not needing to create a Map Entry
* object. This is a large saving not only in performance but in garbage collection. * object. This is a large saving not only in performance but in garbage collection.
* <p> * <p>
* Whilst in flat mode this map is also easy for the garbage collector to dispatch. * Whilst in flat mode this map is also easy for the garbage collector to dispatch.
* This is because it contains no complex objects or arrays which slow the progress. * This is because it contains no complex objects or arrays which slow the progress.
* (Note that the impact of this has not actually been tested!) * <p>
* Do not use <code>Flat3Map</code> if the size is likely to grow beyond 3.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.3 $ $Date: 2003/11/14 22:58:27 $ * @version $Revision: 1.1 $ $Date: 2003/11/18 23:23:05 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -556,11 +558,14 @@ public class Flat3Map implements Map {
*/ */
public void clear() { public void clear() {
if (iMap != null) { if (iMap != null) {
iMap.clear(); iMap.clear(); // should aid gc
} iMap = null; // switch back to flat mode
} else {
iSize = 0; iSize = 0;
iHash1 = iHash2 = iHash3 = 0; iHash1 = iHash2 = iHash3 = 0;
iKey1 = iKey2 = iKey3 = iValue1 = iValue2 = iValue3 = null; iKey1 = iKey2 = iKey3 = null;
iValue1 = iValue2 = iValue3 = null;
}
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------

View File

@ -16,6 +16,7 @@ The following implementations are provided in the package:
<li>FixedSize - ensures that the size of the map cannot change <li>FixedSize - ensures that the size of the map cannot change
<li>Lazy - creates objects in the map on demand <li>Lazy - creates objects in the map on demand
<li>ListOrdered - ensures that insertion order is retained <li>ListOrdered - ensures that insertion order is retained
<li>Flat3 - designed for good performance at size 3 or less
</ul> </ul>
</pre> </pre>
</BODY> </BODY>

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/MapPerformance.java,v 1.1 2003/11/02 23:43:00 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/MapPerformance.java,v 1.2 2003/11/18 23:23:05 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -65,6 +65,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.commons.collections.map.Flat3Map;
/** /**
* <code>TestMapPerformance</code> is designed to perform basic Map performance tests. * <code>TestMapPerformance</code> is designed to perform basic Map performance tests.
* *

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/TestAll.java,v 1.1 2003/11/16 00:05:46 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/TestAll.java,v 1.2 2003/11/18 23:23:05 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -65,7 +65,7 @@ import junit.framework.TestSuite;
* Entry point for tests. * Entry point for tests.
* *
* @since Commons Collections 3.0 * @since Commons Collections 3.0
* @version $Revision: 1.1 $ $Date: 2003/11/16 00:05:46 $ * @version $Revision: 1.2 $ $Date: 2003/11/18 23:23:05 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */
@ -85,6 +85,7 @@ public class TestAll extends TestCase {
suite.addTest(TestFixedSizeMap.suite()); suite.addTest(TestFixedSizeMap.suite());
suite.addTest(TestFixedSizeSortedMap.suite()); suite.addTest(TestFixedSizeSortedMap.suite());
suite.addTest(TestFlat3Map.suite());
suite.addTest(TestLazyMap.suite()); suite.addTest(TestLazyMap.suite());
suite.addTest(TestLazySortedMap.suite()); suite.addTest(TestLazySortedMap.suite());
suite.addTest(TestListOrderedMap.suite()); suite.addTest(TestListOrderedMap.suite());

View File

@ -1,5 +1,5 @@
/* /*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/Attic/TestFlat3Map.java,v 1.4 2003/11/18 22:37:16 scolebourne Exp $ * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/map/TestFlat3Map.java,v 1.1 2003/11/18 23:23:05 scolebourne Exp $
* ==================================================================== * ====================================================================
* *
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
@ -55,21 +55,21 @@
* <http://www.apache.org/>. * <http://www.apache.org/>.
* *
*/ */
package org.apache.commons.collections; package org.apache.commons.collections.map;
import java.util.Map; import java.util.Map;
import junit.framework.Test; import junit.framework.Test;
import junit.textui.TestRunner; import junit.textui.TestRunner;
import org.apache.commons.collections.BulkTest;
import org.apache.commons.collections.iterators.AbstractTestMapIterator; import org.apache.commons.collections.iterators.AbstractTestMapIterator;
import org.apache.commons.collections.iterators.MapIterator; import org.apache.commons.collections.iterators.MapIterator;
import org.apache.commons.collections.map.AbstractTestMap;
/** /**
* JUnit tests. * JUnit tests.
* *
* @version $Revision: 1.4 $ $Date: 2003/11/18 22:37:16 $ * @version $Revision: 1.1 $ $Date: 2003/11/18 23:23:05 $
* *
* @author Stephen Colebourne * @author Stephen Colebourne
*/ */