it.unimi.dsi.archive4j
Class ArrayArchive

java.lang.Object
  extended by it.unimi.dsi.archive4j.ArchiveWriter<ArrayDocumentSummary>
      extended by it.unimi.dsi.archive4j.ArrayArchive
All Implemented Interfaces:
Archive<ArrayDocumentSummary>, FlyweightPrototype<Archive<ArrayDocumentSummary>>, Closeable, Iterable<ArrayDocumentSummary>

public class ArrayArchive
extends ArchiveWriter<ArrayDocumentSummary>
implements Archive<ArrayDocumentSummary>

Dynamic implementation of an in-memory archive. Supports random access.

Just append summaries and query, in any order.

Author:
Alessio Orlandi

Field Summary
protected  Int2ObjectLinkedOpenHashMap<ArrayDocumentSummary> data
           
protected  Int2IntLinkedOpenHashMap frequency
           
protected  int numberOfWords
           
protected  IntArrayList ordinal
           
 
Constructor Summary
ArrayArchive()
           
 
Method Summary
 void append(ArrayDocumentSummary summary)
          Appends a new document summary to the archive.
 void close()
           
 Archive<ArrayDocumentSummary> copy()
           
 int frequency(int term)
          Return the frequency of a given term.
 ArrayDocumentSummary getDocumentById(int id)
          Returns a document given its id (optional operation).
 ArrayDocumentSummary getDocumentByIndex(int idx)
          Returns a document by index (position in the archive) (optional operation).
 boolean hasRandomAccess()
          Returns whether the archive supports random access, that is, Archive.getDocumentById(int) and Archive.getDocumentByIndex(int).
 Iterator<ArrayDocumentSummary> iterator()
           
 int numberOfDocuments()
          Returns the number of documents in the archive.
 int numberOfTerms()
          Returns the number of terms in the archive.
 long numberOfWords()
          Returns the number of words in the collection (i.e., the sum of the lengths of all documents).
 
Methods inherited from class it.unimi.dsi.archive4j.ArchiveWriter
appendAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected Int2ObjectLinkedOpenHashMap<ArrayDocumentSummary> data

ordinal

protected IntArrayList ordinal

numberOfWords

protected int numberOfWords

frequency

protected Int2IntLinkedOpenHashMap frequency
Constructor Detail

ArrayArchive

public ArrayArchive()
Method Detail

append

public void append(ArrayDocumentSummary summary)
            throws IOException
Description copied from class: ArchiveWriter
Appends a new document summary to the archive.

Specified by:
append in class ArchiveWriter<ArrayDocumentSummary>
Parameters:
summary - a document summary.
Throws:
IOException

frequency

public int frequency(int term)
Description copied from interface: Archive
Return the frequency of a given term.

Specified by:
frequency in interface Archive<ArrayDocumentSummary>
Parameters:
term - a term number.
Returns:
the frequency of the given term.

getDocumentById

public ArrayDocumentSummary getDocumentById(int id)
                                     throws IOException
Description copied from interface: Archive
Returns a document given its id (optional operation).

Specified by:
getDocumentById in interface Archive<ArrayDocumentSummary>
Parameters:
id - a document id.
Returns:
the document with given id, or null if no such document exists.
Throws:
IOException

getDocumentByIndex

public ArrayDocumentSummary getDocumentByIndex(int idx)
                                        throws IOException
Description copied from interface: Archive
Returns a document by index (position in the archive) (optional operation).

Specified by:
getDocumentByIndex in interface Archive<ArrayDocumentSummary>
Parameters:
idx - the document index.
Throws:
IOException

numberOfDocuments

public int numberOfDocuments()
Description copied from interface: Archive
Returns the number of documents in the archive.

Specified by:
numberOfDocuments in interface Archive<ArrayDocumentSummary>
Returns:
the number of documents in the archive.

numberOfTerms

public int numberOfTerms()
Description copied from interface: Archive
Returns the number of terms in the archive.

Specified by:
numberOfTerms in interface Archive<ArrayDocumentSummary>
Returns:
the number of terms in the archive.

numberOfWords

public long numberOfWords()
Description copied from interface: Archive
Returns the number of words in the collection (i.e., the sum of the lengths of all documents).

Specified by:
numberOfWords in interface Archive<ArrayDocumentSummary>
Returns:
the number of words in the collection.

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

iterator

public Iterator<ArrayDocumentSummary> iterator()
Specified by:
iterator in interface Iterable<ArrayDocumentSummary>

hasRandomAccess

public boolean hasRandomAccess()
Description copied from interface: Archive
Returns whether the archive supports random access, that is, Archive.getDocumentById(int) and Archive.getDocumentByIndex(int).

Specified by:
hasRandomAccess in interface Archive<ArrayDocumentSummary>
Returns:
whether the archive supports random access.

copy

public Archive<ArrayDocumentSummary> copy()
Specified by:
copy in interface FlyweightPrototype<Archive<ArrayDocumentSummary>>