/*
 * @module
 *  sort.c
 * @description
 *  header file for lexsort used
 * @author
 *  rdoss.com
 */
#ifndef SORT_H
#define SORT_H
#include "types.h"

/* for sorting strings */
#define RADIX    26
#define CH(i,j)  C[A[i].S + j] - 'A'

/* for sorting based on size */
/* NOTE:  This is MACHINE DEPENDENT, THERE ARE TWO
 *    DEFINES, ONE FOR LITTLE-ENDIAN and ONE FOR
 *    BIG-ENDIAN. Intel is little-endian, Sparc is
 *    big-endian.
 */
#define  RADIX1     16
#define  WORDSIZE   8
#define  MACHINE_WORD   32   /* 32 bit integers */
#define  BYTE_SIZE  4    /* 4 bit bytes, ie , Hexadecimal */

#ifdef _LITTLE_ENDIAN
/*  (((size) >> (32 - ((j) +1) * 4)) & (15))
 */
#   define  DIGIT(i,j) (((A[i].T) >> (MACHINE_WORD - ((j) + 1) * BYTE_SIZE)) & (RADIX1 -1))
#elif _BIG_ENDIAN
/*  (((size) << (32 - ((j) +1) * 4)) & (15))
 */
#   define  DIGIT(i,j) (((A[i].T) << (MACHINE_WORD - ((j) + 1) * BYTE_SIZE)) & (RADIX1 -1))
#else
#   error  "YOU MUST DEFINE EITHER  _LITTLE_ENDIAN OR _BIG_ENDIAN, SEE include/sort.h"
#endif

void
read_file( const char *f );

void
sort_strings( void );

void
LSD_string_radix_sort( attribute_t *A,size_t lower, size_t upper,size_t k );

void
LSD_size_radix_sort(attribute_t *A,size_t lower, size_t upper);

void
print_string( void );

#endif /* SORT_H */