iterator
Class Sort

java.lang.Object
  extended byiterator.Iterator
      extended byiterator.Sort
All Implemented Interfaces:
Flags, GlobalConst

public class Sort
extends Iterator
implements GlobalConst

The Sort class sorts a file. All necessary information are passed as arguments to the constructor. After the constructor call, the user can repeatly call get_next() to get tuples in sorted order. After the sorting is done, the user should call close() to clean up.


Field Summary
 
Fields inherited from class iterator.Iterator
closeFlag
 
Fields inherited from interface global.GlobalConst
INVALID_PAGE, MAX_NAME, MAX_SPACE, MAXATTRNAME, MAXFILENAME, MAXINDEXNAME, MINIBASE_BUFFER_POOL_SIZE, MINIBASE_DB_SIZE, MINIBASE_DEFAULT_SHAREDMEM_SIZE, MINIBASE_MAX_TRANSACTIONS, MINIBASE_MAXARRSIZE, MINIBASE_PAGESIZE, NUMBUF
 
Fields inherited from interface global.Flags
DEBUG, TEST
 
Constructor Summary
Sort(AttrType[] in, short len_in, short[] str_sizes, Iterator am, int sort_fld, TupleOrder sort_order, int sort_fld_len, int n_pages)
          Class constructor, take information about the tuples, and set up the sorting
 
Method Summary
 void close()
          Cleaning up, including releasing buffer pages from the buffer pool and removing temporary files from the database.
 Tuple get_next()
          Returns the next tuple in sorted order.
 
Methods inherited from class iterator.Iterator
free_buffer_pages, get_buffer_pages
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sort

public Sort(AttrType[] in,
            short len_in,
            short[] str_sizes,
            Iterator am,
            int sort_fld,
            TupleOrder sort_order,
            int sort_fld_len,
            int n_pages)
     throws java.io.IOException,
            SortException
Class constructor, take information about the tuples, and set up the sorting

Parameters:
in - array containing attribute types of the relation
len_in - number of columns in the relation
str_sizes - array of sizes of string attributes
am - an iterator for accessing the tuples
sort_fld - the field number of the field to sort on
sort_order - the sorting order (ASCENDING, DESCENDING)
n_pages - amount of memory (in pages) available for sorting
Throws:
java.io.IOException - from lower layers
SortException - something went wrong in the lower layer.
Method Detail

get_next

public Tuple get_next()
               throws java.io.IOException,
                      SortException,
                      UnknowAttrType,
                      LowMemException,
                      JoinsException,
                      java.lang.Exception
Returns the next tuple in sorted order. Note: You need to copy out the content of the tuple, otherwise it will be overwritten by the next get_next() call.

Specified by:
get_next in class Iterator
Returns:
the next tuple, null if all tuples exhausted
Throws:
java.io.IOException - from lower layers
SortException - something went wrong in the lower layer.
JoinsException - from generate_runs().
UnknowAttrType - attribute type unknown
LowMemException - memory low exception
java.lang.Exception - other exceptions

close

public void close()
           throws SortException,
                  java.io.IOException
Cleaning up, including releasing buffer pages from the buffer pool and removing temporary files from the database.

Specified by:
close in class Iterator
Throws:
java.io.IOException - from lower layers
SortException - something went wrong in the lower layer.