You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Morgan Delagrange <md...@yahoo.com> on 2002/02/14 22:13:01 UTC

[Collections] subclassing LRUMap

Hi all,

I just made a backward-compatible change to LRUMap to facilitate
subclassing.  Now, you can override removeLRU() if you want to manipulate
(e.g. persist to disk) an Object before it is automatically removed from the
Map.  You can also subclass remove(Object) if you want to manipulate all
Objects before they are removed, whether or not they are being removed by
the LRU algorithm.

This seemed like a pretty reasonable thing to do, but I wanted to drop a
note to the list since it enhances the contract of LRUMap.  Let me know if
you object to the idea or the approach.

I also added a couple of unit tests (TestLRUMap.java) that confirm the
ability of subclasses to control Object removal.

- Morgan


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] subclassing LRUMap

Posted by "Michael A. Smith" <mi...@iammichael.org>.
On Thu, 14 Feb 2002, Morgan Delagrange wrote:
> > I don't know if you saw these other messages talking about LRUMap
> > (there's more, I just selected a couple):
> >
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg02555.html
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03084.html
> >
> 
> Yup I've seen them.  James quoted the relevant portions in his Javadocs.

Actually, I submitted the patch for that.  James just committed it.  :)
http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03069.html

> > Oh, and since you seem to have an active interest in collections (no one
> > else seems to), maybe you could review the patches I've submitted that
> > have not yet been applied?
> >
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03055.html
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03056.html
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03057.html
> > http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03060.html
> 
> I may take a look, but right now I'm just focusing on LRUMap.  I plan to
> implement a cache with it.

That's cool.  Although you might want to take a look at my
SequencedHashMap patch.  I really think it would help in implementing a 
better LRUMap -- one with decent add/remove performance for larger maps.  
Then again, I'm probably biased towards my implementation 
of things.   :)

regards,
michael


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] subclassing LRUMap

Posted by Morgan Delagrange <md...@yahoo.com>.
----- Original Message -----
From: "Michael A. Smith" <mi...@iammichael.org>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>;
"Morgan Delagrange" <mo...@apache.org>
Sent: Thursday, February 14, 2002 3:49 PM
Subject: Re: [Collections] subclassing LRUMap


> On Thu, 14 Feb 2002, Morgan Delagrange wrote:
> > I just made a backward-compatible change to LRUMap to facilitate
> > subclassing.  Now, you can override removeLRU() if you want to
manipulate
> > (e.g. persist to disk) an Object before it is automatically removed from
the
> > Map.  You can also subclass remove(Object) if you want to manipulate all
> > Objects before they are removed, whether or not they are being removed
by
> > the LRU algorithm.
> >
> > This seemed like a pretty reasonable thing to do, but I wanted to drop a
> > note to the list since it enhances the contract of LRUMap.  Let me know
if
> > you object to the idea or the approach.
>
> Actually, I just object to the implementation of LRUMap itself.  Many of
> its operations have O(n) cost when they could be O(1).  I haven't taken a
> good look at the changes you've made, but it doesn't look like you've
> fixed that.  :)

No, the changes I've made recently were mainly to fix bugs and allow more
control in subclasses.  If anything, I've made the class slightly less
performant for put(Object,Object) operations.

> I'll try to take a closer look at what you've changed
> when I have a few spare cycles (possibly not until this weekend).

Yeah, there are longer-term issues with LRUMap, particularly wrt. its
effectiveness of its algorithm as a cache.  I'll launch this in a separate
thread soon.  I'm going to need to write more unit tests, because any
changes I make should try to be compatible with previous externalized
versions, or they can't be made in a 1.x version of Collections (Collections
has already performed an official 1.0 release).  (We really should have had
a unit test for externalized versions before I started making changes, but
there were some outright bugs that needed attention.)

> I don't know if you saw these other messages talking about LRUMap
> (there's more, I just selected a couple):
>
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg02555.html
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03084.html
>

Yup I've seen them.  James quoted the relevant portions in his Javadocs.

> Oh, and since you seem to have an active interest in collections (no one
> else seems to), maybe you could review the patches I've submitted that
> have not yet been applied?
>
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03055.html
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03056.html
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03057.html
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03060.html

I may take a look, but right now I'm just focusing on LRUMap.  I plan to
implement a cache with it.

> I was planning on "fixing" LRUMap once the SequencedHashMap patch was
> applied.  I also plan on adding a ton of test cases as well (for all Map
> implementations).  I mentioned that here:
>
> http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03054.html
>
> I've got quite a few done, but its not nearly as complete as I'd like.

I've added several unit tests for LRUMap, mainly to illustrate bugs before I
committed the fix.

- Morgan


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [Collections] subclassing LRUMap

Posted by "Michael A. Smith" <mi...@iammichael.org>.
On Thu, 14 Feb 2002, Morgan Delagrange wrote:
> I just made a backward-compatible change to LRUMap to facilitate
> subclassing.  Now, you can override removeLRU() if you want to manipulate
> (e.g. persist to disk) an Object before it is automatically removed from the
> Map.  You can also subclass remove(Object) if you want to manipulate all
> Objects before they are removed, whether or not they are being removed by
> the LRU algorithm.
> 
> This seemed like a pretty reasonable thing to do, but I wanted to drop a
> note to the list since it enhances the contract of LRUMap.  Let me know if
> you object to the idea or the approach.

Actually, I just object to the implementation of LRUMap itself.  Many of
its operations have O(n) cost when they could be O(1).  I haven't taken a
good look at the changes you've made, but it doesn't look like you've
fixed that.  :)  I'll try to take a closer look at what you've changed
when I have a few spare cycles (possibly not until this weekend).

I don't know if you saw these other messages talking about LRUMap 
(there's more, I just selected a couple):

http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg02555.html
http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03084.html


Oh, and since you seem to have an active interest in collections (no one 
else seems to), maybe you could review the patches I've submitted that 
have not yet been applied?  

http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03055.html
http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03056.html
http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03057.html
http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03060.html

I was planning on "fixing" LRUMap once the SequencedHashMap patch was 
applied.  I also plan on adding a ton of test cases as well (for all Map 
implementations).  I mentioned that here:

http://www.mail-archive.com/commons-dev@jakarta.apache.org/msg03054.html

I've got quite a few done, but its not nearly as complete as I'd like.

regards,
michael


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>