Thanks, I added this to our 'patch queue'.

Otis

--- Nick Smith <[EMAIL PROTECTED]> wrote:
> 
> Hi Lucene Developers,
>    Thanks for a great product!
>    
> I need to be able to 'snapshot' our in-memory indices (RAMDirectory
> instances).
> 
> I have been using :
> 
> RAMDirectory activeDir = new RAMDirectory();
> // many inserts, deletes etc
> RAMDirectory cloneDir = new RAMDirectory(activeDir);
> 
> but unfortunately this is rather slow for large indices.
> 
> I have a suggestion - implement java.lang.Cloneable interface
> in RAMDirectory.  I.e to be able to call :
> 
> RAMDirectory cloneDir = (RAMDirectory)activeDir.clone();
> 
> This bypasses the input/output stream handling of the
> copy constructor by cloneing the underlying buffers that
> form the directory and is much faster. (Diff attached).
> 
> Any comments?
> 
> Regards,
> 
> Nick
> > Index: RAMDirectory.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/store/RAMDirectory.java,v
> retrieving revision 1.8
> diff -r1.8 RAMDirectory.java
> 72c72
> < public final class RAMDirectory extends Directory {
> ---
> > public final class RAMDirectory extends Directory implements
> Cloneable {
> 210a211,223
> > 
> >   public Object clone() {
> >     RAMDirectory clone = new RAMDirectory();
> >     // *deep* copy files.
> >     for (java.util.Iterator
> it=files.entrySet().iterator();it.hasNext();)
> >     {
> >         java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
> >         String name = (String)entry.getKey();
> >         RAMFile file = (RAMFile)entry.getValue();
> >         clone.files.put(new String(name), file.clone());
> >     }
> >     return clone;
> >   }
> 302c315
> < final class RAMFile {
> ---
> > final class RAMFile implements Cloneable {
> 305a319,327
> > 
> >   public Object clone() {
> >     RAMFile clone = new RAMFile();
> >     clone.buffers = (Vector)buffers.clone();
> >     clone.length = length;
> >     clone.lastModified = lastModified;
> >     return clone;
> >   }
> > 
> 
> >
---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to