#include <sm_vas.h> // which includes sm.h static rc_t sort_file( const lvid_t& lvid, // logical vol id (input file) const serial_t& serial, // serial no for input file const lvid_t& s_lvid, // logical vol id (output file) serial_t& s_serial, // serial no for output file store_property_t property, // property for output file const key_info_t& key_info, // sort key info int run_size, // # of pages for each run bool unique = false, // eliminate duplicates bool destructive = false); // destroy input file
User can control the buffer size needed for the sorting by specifying the desired run_size. Usually the bigger the run_size, the faster the sort.
User need to provide detail information on the sort key in key_info. This includes information such as type, location and length. The location of the key has to be fixed offset from the beginning of the record. Class key_info_t is further described in sort_stream_i(ssm) .
Setting the unique flag to true will eliminate duplicate records in the file. Setting Setting the destructive to true will destroy the input file and map the records' logical IDs to those in the new sorted file.
For sorting on variable length records (keys may not stay at fixed location within records), one can fix the key location by copying the key from body to the beginning of hdr for the record, turn on derived flag in key_info before invoking sort_file. The result file will have the duplicated key eliminated in each record.
key_info.type = t_int; key_info.where = t_body; key_info.offset = 0; key_info.len = sizeof(int);