avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/collections/src/java/org/apache/avalon/excalibur/collections BucketMap.java
Date Tue, 25 Jun 2002 20:54:47 GMT
bloritsch    2002/06/25 13:54:47

  Modified:    collections/src/java/org/apache/avalon/excalibur/collections
                        BucketMap.java
  Log:
  remove extra locking array--reduces weight of BucketMap
  
  Revision  Changes    Path
  1.18      +23 -26    jakarta-avalon-excalibur/collections/src/java/org/apache/avalon/excalibur/collections/BucketMap.java
  
  Index: BucketMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/collections/src/java/org/apache/avalon/excalibur/collections/BucketMap.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BucketMap.java	3 Jun 2002 12:12:17 -0000	1.17
  +++ BucketMap.java	25 Jun 2002 20:54:47 -0000	1.18
  @@ -29,7 +29,6 @@
   {
       private static final int DEFAULT_BUCKETS = 255;
       private final Node[] m_buckets;
  -    private final Object[] m_locks;
   
       /**
        * Initializes the map with the default number of buckets (255).
  @@ -58,11 +57,10 @@
           }
   
           m_buckets = new Node[ size ];
  -        m_locks = new Object[ size ];
   
           for( int i = 0; i < size; i++ )
           {
  -            m_locks[ i ] = new Object();
  +            m_buckets[ i ] = new Node();
           }
       }
   
  @@ -96,11 +94,11 @@
   
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            synchronized( m_locks[ i ] )
  +            synchronized( m_buckets[ i ] )
               {
                   Node n = m_buckets[ i ];
   
  -                while( n != null )
  +                while( n != null && n.key != null )
                   {
                       keySet.add( n.key );
                       n = n.next;
  @@ -120,11 +118,11 @@
   
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            synchronized( m_locks[ i ] )
  +            synchronized( m_buckets[ i ] )
               {
                   Node n = m_buckets[ i ];
   
  -                while( n != null )
  +                while( n != null && n.key != null )
                   {
                       cnt++;
                       n = n.next;
  @@ -147,16 +145,14 @@
   
           int hash = getHash( key );
   
  -        synchronized( m_locks[ hash ] )
  +        synchronized( m_buckets[ hash ] )
           {
               Node n = m_buckets[ hash ];
   
  -            if( n == null )
  +            if( n.key == null )
               {
  -                n = new Node();
                   n.key = key;
                   n.value = value;
  -                m_buckets[ hash ] = n;
                   return value;
               }
   
  @@ -198,11 +194,11 @@
   
           int hash = getHash( key );
   
  -        synchronized( m_locks[ hash ] )
  +        synchronized( m_buckets[ hash ] )
           {
               Node n = m_buckets[ hash ];
   
  -            while( n != null )
  +            while( n != null && n.key != null )
               {
                   if( n.key.equals( key ) )
                   {
  @@ -228,11 +224,11 @@
   
           int hash = getHash( key );
   
  -        synchronized( m_locks[ hash ] )
  +        synchronized( m_buckets[ hash ] )
           {
               Node n = m_buckets[ hash ];
   
  -            while( n != null )
  +            while( n != null && n.key != null )
               {
                   if( n.key.equals( key ) )
                   {
  @@ -260,11 +256,11 @@
   
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            synchronized( m_locks[ i ] )
  +            synchronized( m_buckets[ i ] )
               {
                   Node n = m_buckets[ i ];
   
  -                while( n != null )
  +                while( n != null && n.key != null )
                   {
                       if( n.value.equals( value ) )
                       {
  @@ -290,11 +286,11 @@
   
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            synchronized( m_locks[ i ] )
  +            synchronized( m_buckets[ i ] )
               {
                   Node n = m_buckets[ i ];
   
  -                while( n != null )
  +                while( n != null && n.key != null )
                   {
                       valueSet.add( n.value );
                       n = n.next;
  @@ -316,11 +312,11 @@
   
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            synchronized( m_locks[ i ] )
  +            synchronized( m_buckets[ i ] )
               {
                   Node n = m_buckets[ i ];
   
  -                while( n != null )
  +                while( n != null && n.key != null )
                   {
                       entrySet.add( n );
                       n = n.next;
  @@ -357,12 +353,12 @@
   
           int hash = getHash( key );
   
  -        synchronized( m_locks[ hash ] )
  +        synchronized( m_buckets[ hash ] )
           {
               Node n = m_buckets[ hash ];
               Node prev = null;
   
  -            while( n != null )
  +            while( n != null && n.key != null )
               {
                   if( n.key.equals( key ) )
                   {
  @@ -396,7 +392,7 @@
       {
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            if( m_buckets[ i ] != null )
  +            if( m_buckets[ i ].key != null )
               {
                   return false;
               }
  @@ -412,7 +408,8 @@
       {
           for( int i = 0; i < m_buckets.length; i++ )
           {
  -            m_buckets[ i ] = null;
  +            m_buckets[ i ] = null; // be explicit
  +            m_buckets[ i ] = new Node();
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message