Beispiel #1
0
/*
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

void smallSort(int&, int&, int&);
void initialSort(int&, int&);

int main() //main function should be removed or commented out before submitting to TEACH
{
	int a = 14;
	int b = -90;
	int c = 2;
	smallSort(a, b, c);
	cout << a << ", " << b << ", " << c << endl;
	return 0;
}
*/
void smallSort(int& num1, int& num2, int& num3)
{
	int temp; //used to temporarily save values

	initialSort(num1,num2);

	//compare the second and third numbers in the set
	if (num2 > num3)
	{
		//if second number is greater than the third, then swap the numbers
		temp = num2;
		num2 = num3;
		num3 = temp;

		initialSort(num1,num2);
	}
}
Beispiel #2
0
short_pair*
simpleSuffixSort(short_pair* pairs, uint n, uint threads)
{
  if(pairs == 0 || n == 0) { return 0; }

  uint* keys = new uint[n];   // In text order.
  std::vector<ss_range> unsorted;
  threads = std::max(threads, (uint)1);
  #ifdef MULTITHREAD_SUPPORT
  omp_set_num_threads(threads);
  #endif

  // Initialize pairs.
  #pragma omp parallel for schedule(static)
  for(uint i = 0; i < n; i++) { pairs[i].first = i; }

  uint total = initialSort(pairs, keys, unsorted, n, threads, 1);
  return prefixDoubling(pairs, keys, unsorted, n, threads, total, 1);
}
Beispiel #3
0
short_pair*
simpleSuffixSort(const uchar* sequence, uint n, uint sequences, uint threads)
{
  if(sequence == 0 || n == 0) { return 0; }

  short_pair* pairs = new short_pair[n];  // In sorted order.
  uint* keys = new uint[n];               // In text order.
  std::vector<ss_range> unsorted;
  threads = std::max(threads, (uint)1);
  #ifdef MULTITHREAD_SUPPORT
  omp_set_num_threads(threads);
  #endif

  // Remap alphabet.
  uint alphabet[CHARS];
  for(uint c = 0; c < CHARS; c++) { alphabet[c] = 0; }
  for(uint i = 0; i < n; i++) { alphabet[sequence[i]]++; }
  uint alphabet_size = sequences;
  for(uint c = 1; c < CHARS; c++)
  {
    uint temp = alphabet_size;
    if(alphabet[c] > 0) { alphabet_size++; }
    alphabet[c] = temp;
  }

  // Determine pack factor.
  uint limit = std::numeric_limits<uint>::max() / alphabet_size;
  uint h = 1, pack_multiplier = 1;
  if(alphabet_size > 1)
  {
    while(pack_multiplier * alphabet_size <= limit) { h++; pack_multiplier *= alphabet_size; }
  }

  // Initialize pairs.
  uint zeros = 0, value = 0;
  for(uint i = 0; i < h; i++)
  {
    value *= alphabet_size;
    if(sequence[i] == 0) { value += zeros; zeros++; }
    else { value += alphabet[sequence[i]]; }
  }
  for(uint i = 0; i < n - h; i++)
  {
    pairs[i].first = i; pairs[i].second = value;
    value = (value % pack_multiplier) * alphabet_size;
    if(sequence[i + h] == 0) { value += zeros; zeros++; }
    else { value += alphabet[sequence[i + h]]; }
  }
  for(uint i = n - h; i < n; i++)
  {
    pairs[i].first = i; pairs[i].second = value;
    value = (value % pack_multiplier) * alphabet_size;
  }

  // Initialize pairs.
/*  uint zeros = 0;
  for(uint i = 0; i < n; i++)
  {
    pairs[i].first = i;
    pairs[i].second = (sequence[i] == '\0' ? zeros++ : sequence[i] + sequences);
  }
  uint h = 1;
  if(length(CHARS + sequences - 1) <= sizeof(uint) * CHAR_BIT / 2)
  {
    for(uint i = 0; i < n - 1; i++)
    {
      pairs[i].second = (CHARS + sequences) * pairs[i].second + pairs[i + 1].second;
    }
    pairs[n - 1].second *= CHARS + sequences;
    h = 2;
  }*/

  uint total = initialSort(pairs, keys, unsorted, n, threads, h);
  return prefixDoubling(pairs, keys, unsorted, n, threads, total, h);
}