commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From morg...@apache.org
Subject cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections LRUMap.java
Date Wed, 13 Feb 2002 23:07:31 GMT
morgand     02/02/13 15:07:31

  Modified:    collections/src/java/org/apache/commons/collections
                        LRUMap.java
  Log:
  fixed bubble sort, so that the number of elements in the bubble sort
  will always equal the size of the LRUMap
  
  Revision  Changes    Path
  1.5       +8 -11     jakarta-commons/collections/src/java/org/apache/commons/collections/LRUMap.java
  
  Index: LRUMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/LRUMap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LRUMap.java	13 Feb 2002 21:03:20 -0000	1.4
  +++ LRUMap.java	13 Feb 2002 23:07:31 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/LRUMap.java,v
1.4 2002/02/13 21:03:20 morgand Exp $
  - * $Revision: 1.4 $
  - * $Date: 2002/02/13 21:03:20 $
  + * $Header: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/LRUMap.java,v
1.5 2002/02/13 23:07:31 morgand Exp $
  + * $Revision: 1.5 $
  + * $Date: 2002/02/13 23:07:31 $
    *
    * ====================================================================
    *
  @@ -178,19 +178,16 @@
           return pair.value;
       }
   
  -    public Object put( Object key, Object value ) {
  -        int i = size();
  -        ValuePositionPair pair = new ValuePositionPair( value );
  -        if ( i >= maximumSize ) {
  +    public Object put( Object key, Object value ) {

         ValuePositionPair pair =
new ValuePositionPair( value );
         int mapSize = size();

         // check to see if
the object already exists in
         // our LRUMap, if it does then the position in the
        // bubble sort is OK
  +        int keyIndex = bubbleList.indexOf(key);
         if (keyIndex != -1) {

      
      pair.position = keyIndex;

         } else if ( mapSize >= maximumSize ) {
               // lets retire the least recently used item in the cache
               int lastIndex = maximumSize - 1;
               pair.position = lastIndex;
               Object oldKey = bubbleList.set( lastIndex, key );
               super.remove( oldKey );
  -        } 
  -        else {
  -            pair.position = i;
  -            bubbleList.add( i, key );
  +        } else {
  +            pair.position = mapSize;
  +            bubbleList.add( mapSize, key );
           }
           pair = (ValuePositionPair) putPair( key, pair );
           return ( pair != null ) ? pair.value : null;
  
  
  

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


Mime
View raw message