2010-08-04 15:33:12 +02:00
/ * *
* Index
* Copyright 2005 by Michael Peter Christen ; mc @yacy.net , Frankfurt a . M . , Germany
* First released 26 . 10 . 2005 at http : //yacy.net
2011-07-15 10:38:10 +02:00
*
2011-03-08 02:51:51 +01:00
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
2010-08-04 15:33:12 +02:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2 . 1 of the License , or ( at your option ) any later version .
2011-07-15 10:38:10 +02:00
*
2010-08-04 15:33:12 +02:00
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
2011-07-15 10:38:10 +02:00
*
2010-08-04 15:33:12 +02:00
* You should have received a copy of the GNU Lesser General Public License
* along with this program in the file lgpl21 . txt
* If not , see < http : //www.gnu.org/licenses/>.
2005-10-26 14:37:22 +02:00
* /
2009-10-10 01:32:08 +02:00
package net.yacy.kelondro.index ;
2005-10-26 14:37:22 +02:00
import java.io.IOException ;
2011-05-13 08:21:40 +02:00
import java.util.Collection ;
2009-10-12 10:06:35 +02:00
import java.util.Iterator ;
2010-05-31 02:27:00 +02:00
import java.util.List ;
2011-05-13 08:21:40 +02:00
import java.util.Map ;
2005-10-26 14:37:22 +02:00
2011-12-16 23:59:29 +01:00
import net.yacy.cora.order.CloneableIterator ;
2012-07-27 12:13:53 +02:00
import net.yacy.cora.util.SpaceExceededException ;
2009-10-10 01:22:22 +02:00
2009-01-30 16:33:00 +01:00
2010-08-04 15:33:12 +02:00
public interface Index extends Iterable < Row . Entry > {
2005-10-26 14:37:22 +02:00
2007-03-06 23:43:32 +01:00
public String filename ( ) ; // returns a unique identified for this index; can be a real or artificial file name
2007-04-19 15:37:02 +02:00
public int size ( ) ;
2014-02-28 14:01:09 +01:00
public void optimize ( ) ;
2010-08-03 06:58:48 +02:00
public long mem ( ) ;
2009-12-02 01:37:59 +01:00
public boolean isEmpty ( ) ;
2009-01-30 16:33:00 +01:00
public Row row ( ) ;
2010-04-19 18:42:37 +02:00
public byte [ ] smallestKey ( ) ;
public byte [ ] largestKey ( ) ;
2008-06-18 01:56:39 +02:00
public boolean has ( byte [ ] key ) ; // use this only if there is no get in case that has returns true
2011-07-15 10:38:10 +02:00
public Map < byte [ ] , Row . Entry > get ( final Collection < byte [ ] > keys , boolean forcecopy ) throws IOException , InterruptedException ;
public Row . Entry get ( byte [ ] key , boolean forcecopy ) throws IOException ;
2012-07-27 12:13:53 +02:00
public Row . Entry replace ( Row . Entry row ) throws SpaceExceededException , IOException ;
2011-07-15 10:38:10 +02:00
2010-09-15 12:43:14 +02:00
/ * *
* Adds the row to the index . The row is identified by the primary key of the row .
* @param row a index row
2011-07-15 10:38:10 +02:00
* @return true if this set did _not_ already contain the given row .
2010-09-15 12:43:14 +02:00
* @throws IOException
2012-07-27 12:13:53 +02:00
* @throws SpaceExceededException
2010-09-15 12:43:14 +02:00
* /
2012-07-27 12:13:53 +02:00
public boolean put ( Row . Entry row ) throws IOException , SpaceExceededException ;
public void addUnique ( Row . Entry row ) throws SpaceExceededException , IOException ; // no double-check
public List < RowCollection > removeDoubles ( ) throws IOException , SpaceExceededException ; // removes all elements that are double (to be used after all addUnique)
2010-04-20 16:47:41 +02:00
public boolean delete ( byte [ ] key ) throws IOException ;
2009-01-30 16:33:00 +01:00
public Row . Entry remove ( byte [ ] key ) throws IOException ;
public Row . Entry removeOne ( ) throws IOException ;
2010-05-31 02:27:00 +02:00
public List < Row . Entry > top ( int count ) throws IOException ;
2012-11-23 13:58:39 +01:00
public List < Row . Entry > random ( int count ) throws IOException ;
2009-01-30 23:08:08 +01:00
public CloneableIterator < byte [ ] > keys ( boolean up , byte [ ] firstKey ) throws IOException ; // iterates only the key
2009-02-24 11:40:20 +01:00
public CloneableIterator < Row . Entry > rows ( boolean up , byte [ ] firstKey ) throws IOException ; // iterates the whole row using the order of the keys
public CloneableIterator < Row . Entry > rows ( ) throws IOException ; // iterates the whole row without any order
2009-10-12 10:06:35 +02:00
public Iterator < Row . Entry > iterator ( ) ;
2008-09-12 13:51:48 +02:00
public void deleteOnExit ( ) ;
2008-05-24 14:30:50 +02:00
public void clear ( ) throws IOException ;
2007-03-09 09:48:47 +01:00
public void close ( ) ;
2005-10-26 14:37:22 +02:00
}