Class FSOrderedMapFile<K extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable>
- java.lang.Object
-
- org.terrier.structures.collections.ReadOnlyMap<K,V>
-
- org.terrier.structures.collections.FSOrderedMapFile<K,V>
-
- Type Parameters:
K- Type of the keysV- Type of the values
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.util.Map<K,V>,java.util.SortedMap<K,V>,OrderedMap<K,V>
public class FSOrderedMapFile<K extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable> extends ReadOnlyMap<K,V> implements OrderedMap<K,V>, java.io.Closeable, java.util.SortedMap<K,V>
An implementation of java.util.Map that can be accessed from disk. Key and value types are assumed to have a fixed size. Their factories must be passed to the constructor. In the name, FSOrderedMapFile, FS stands for Fixed Size.- Since:
- 3.0
- Author:
- Craig Macdonald
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFSOrderedMapFile.EntryIterator<IK extends org.apache.hadoop.io.Writable,IV extends org.apache.hadoop.io.Writable>an iterator for entries.static interfaceFSOrderedMapFile.FSOMapFileBSearchShortcut<KEY>interface FSOMapFileBSearchShortcutstatic classFSOrderedMapFile.MapFileInMemory<IK extends org.apache.hadoop.io.Writable,IV extends org.apache.hadoop.io.Writable>MapFileInMemory classstatic interfaceFSOrderedMapFile.MapFileWriterInterface for writing a FSOMapFilestatic classFSOrderedMapFile.MultiFSOMapWriterWrites out a FSOMapFile, but assumes that input data need not be sorted by key.
-
Field Summary
Fields Modifier and Type Field Description protected RandomDataInputdataFileactual underlying data fileprotected java.lang.StringdataFilenamefilename of the underlying fileprotected intentrySizetotal size of one key,value pairprotected FixedSizeWriteableFactory<K>keyFactoryprotected static org.slf4j.LoggerloggerThe logger used for this classprotected intnumberOfEntriesThe number of entries in the file.protected FSOrderedMapFile.FSOMapFileBSearchShortcut<K>shortcutstatic java.lang.StringUSUAL_EXTENSIONUSUAL_EXTENSIONprotected FixedSizeWriteableFactory<V>valueFactory
-
Constructor Summary
Constructors Constructor Description FSOrderedMapFile(java.lang.String filename, boolean updateable, FixedSizeWriteableFactory<K> _keyFactory, FixedSizeWriteableFactory<V> _valueFactory)Construct a new object to access the underlying file data structureFSOrderedMapFile(IndexOnDisk index, java.lang.String structureName)constructorFSOrderedMapFile(RandomDataInput file, java.lang.String filename, FixedSizeWriteableFactory<K> _keyFactory, FixedSizeWriteableFactory<V> _valueFactory)constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_clear()voidclear()Remove all entries from this mapvoidclose()java.util.Comparator<? super K>comparator()Always returns null, as keys for FSOMapFile are always Comparable, and their Comparable implementation are used.booleancontainsKey(java.lang.Object o)booleancontainsValue(java.lang.Object o)java.util.Set<java.util.Map.Entry<K,V>>entrySet()KfirstKey()java.util.Map.Entry<K,V>get(int entryNumber)Return the entry at the specified indexVget(java.lang.Object _key)protected org.terrier.structures.collections.FSOrderedMapFile.MapFileEntry<K,V>getEntry(K key)this method is the one which does the actual disk lookup of entries.WriteableFactory<K>getKeyFactory()Get the key factoryWriteableFactory<V>getValueFactory()Get the value factoryjava.util.SortedMap<K,V>headMap(K to)booleanisEmpty()java.util.Set<K>keySet()KlastKey()static FSOrderedMapFile.MapFileWritermapFileWrite(java.lang.String filename)returns a utility class which can be used to write a FSOrderedMapFile.static voidmapFileWrite(java.lang.String filename, java.lang.Iterable<java.util.Map.Entry<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable>> t)writes an entire map FSOrderedMapFile at once, to the specified filename, and using the data contained in the specified iteratorstatic voidmapFileWrite(java.lang.String filename, java.util.Iterator<java.util.Map.Entry<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable>> ti)writes an entire map FSOrderedMapFile at once, to the specified filename, and using the data contained in the specified iteratorstatic intnumberOfEntries(java.lang.String filename, FixedSizeWriteableFactory<?> _keyFactory, FixedSizeWriteableFactory<?> _valueFactory)Return number of entriesvoidputAll(java.util.Map<? extends K,? extends V> m)voidsetBSearchShortcut(FSOrderedMapFile.FSOMapFileBSearchShortcut<K> _shortcut)Set the FSOMapFileBSearchShortcutintsize()Returns the number of entries in this mapjava.util.SortedMap<K,V>subMap(K from, K to)java.util.SortedMap<K,V>tailMap(K from)java.util.Collection<V>values()protected RandomDataOutputwrite()-
Methods inherited from class org.terrier.structures.collections.ReadOnlyMap
put, remove
-
-
-
-
Field Detail
-
USUAL_EXTENSION
public static final java.lang.String USUAL_EXTENSION
USUAL_EXTENSION- See Also:
- Constant Field Values
-
logger
protected static final org.slf4j.Logger logger
The logger used for this class
-
dataFile
protected RandomDataInput dataFile
actual underlying data file
-
dataFilename
protected java.lang.String dataFilename
filename of the underlying file
-
numberOfEntries
protected int numberOfEntries
The number of entries in the file.
-
entrySize
protected int entrySize
total size of one key,value pair
-
shortcut
protected FSOrderedMapFile.FSOMapFileBSearchShortcut<K extends org.apache.hadoop.io.WritableComparable> shortcut
-
keyFactory
protected FixedSizeWriteableFactory<K extends org.apache.hadoop.io.WritableComparable> keyFactory
-
valueFactory
protected FixedSizeWriteableFactory<V extends org.apache.hadoop.io.Writable> valueFactory
-
-
Constructor Detail
-
FSOrderedMapFile
public FSOrderedMapFile(IndexOnDisk index, java.lang.String structureName) throws java.io.IOException
constructor- Parameters:
index-structureName-- Throws:
java.io.IOException
-
FSOrderedMapFile
public FSOrderedMapFile(java.lang.String filename, boolean updateable, FixedSizeWriteableFactory<K> _keyFactory, FixedSizeWriteableFactory<V> _valueFactory) throws java.io.IOExceptionConstruct a new object to access the underlying file data structure- Parameters:
filename- Filename of the file containing the structureupdateable- Whether the file can be updated in this JVM_keyFactory- factory object for keys_valueFactory- factory object for values- Throws:
java.io.IOException- thrown if an IO problem occurs
-
FSOrderedMapFile
public FSOrderedMapFile(RandomDataInput file, java.lang.String filename, FixedSizeWriteableFactory<K> _keyFactory, FixedSizeWriteableFactory<V> _valueFactory) throws java.io.IOException
constructor- Parameters:
file-filename-_keyFactory-_valueFactory-- Throws:
java.io.IOException
-
-
Method Detail
-
write
protected RandomDataOutput write()
-
numberOfEntries
public static int numberOfEntries(java.lang.String filename, FixedSizeWriteableFactory<?> _keyFactory, FixedSizeWriteableFactory<?> _valueFactory)Return number of entries- Parameters:
filename-_keyFactory-_valueFactory-- Returns:
- number of entries
-
getKeyFactory
public WriteableFactory<K> getKeyFactory()
Get the key factory
-
getValueFactory
public WriteableFactory<V> getValueFactory()
Get the value factory
-
clear
public void clear()
Remove all entries from this map
-
_clear
protected void _clear()
-
keySet
public java.util.Set<K> keySet()
-
values
public java.util.Collection<V> values()
-
size
public int size()
Returns the number of entries in this map
-
containsValue
public boolean containsValue(java.lang.Object o)
-
containsKey
public boolean containsKey(java.lang.Object o)
-
isEmpty
public boolean isEmpty()
-
setBSearchShortcut
public void setBSearchShortcut(FSOrderedMapFile.FSOMapFileBSearchShortcut<K> _shortcut)
Set the FSOMapFileBSearchShortcut
-
getEntry
protected org.terrier.structures.collections.FSOrderedMapFile.MapFileEntry<K,V> getEntry(K key)
this method is the one which does the actual disk lookup of entries. If an entry is not found, then a MapFileEntry is returned where the index field indicates the (-(insertion point) -1) of the specified key. See also Arrays.binarySearch()
-
firstKey
public K firstKey()
-
lastKey
public K lastKey()
-
comparator
public final java.util.Comparator<? super K> comparator()
Always returns null, as keys for FSOMapFile are always Comparable, and their Comparable implementation are used.
-
get
public V get(java.lang.Object _key)
-
get
public java.util.Map.Entry<K,V> get(int entryNumber)
Return the entry at the specified index- Specified by:
getin interfaceOrderedMap<K extends org.apache.hadoop.io.WritableComparable,V extends org.apache.hadoop.io.Writable>
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
mapFileWrite
public static void mapFileWrite(java.lang.String filename, java.lang.Iterable<java.util.Map.Entry<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable>> t) throws java.io.IOExceptionwrites an entire map FSOrderedMapFile at once, to the specified filename, and using the data contained in the specified iterator- Throws:
java.io.IOException
-
mapFileWrite
public static void mapFileWrite(java.lang.String filename, java.util.Iterator<java.util.Map.Entry<org.apache.hadoop.io.WritableComparable,org.apache.hadoop.io.Writable>> ti) throws java.io.IOExceptionwrites an entire map FSOrderedMapFile at once, to the specified filename, and using the data contained in the specified iterator- Throws:
java.io.IOException
-
mapFileWrite
public static FSOrderedMapFile.MapFileWriter mapFileWrite(java.lang.String filename) throws java.io.IOException
returns a utility class which can be used to write a FSOrderedMapFile. Input data MUST be sorted by key.- Throws:
java.io.IOException
-
-