Exemplo n.º 1
0
static inline void radix_sort(short offset, uint64_t max, uint64_t *source,
        uint64_t *dest)
{
    uint64_t count[256] = {0};
    uint64_t *cp = NULL;
    uint64_t *sp = NULL;
    uint64_t *end = NULL;
    uint64_t s = 0;
    uint64_t c = 0;

    // count occurences of every byte value
    for (sp = source, end = source + max; sp < end; sp++) {
        count[ByteOf(sp, offset)]++;
    }

    // transform count into index by summing elements and storing into same array
    for (s = 0, cp = count, end = count + 256; cp < end; cp++) {
        c = *cp;
        *cp = s;
        s += c;
    }

    // fill dest with the right values in the right place
    for (sp = source, end = source + max; sp < end; sp++) {
        cp = count + ByteOf(sp, offset);
        dest[*cp] = *sp;
        ++(*cp);
    }
}
/*The function sorts the words in the radix map by the n'th character, given by count.
  offset gives the n'th position under consideration*/
static inline void radix_sort(short offset, uint64_t max, uint64_t *source, uint64_t *dest)
{
  uint64_t count[256] = {0};       /*256 possible characters of 8 bits (2^8)*/
  uint64_t *cp = NULL;
  uint64_t *sp = NULL;
  uint64_t *end = NULL;
  uint64_t s = 0;
  uint64_t c = 0;

  /*count occurences of every byte value*/
  for (sp = source, end = source + max; sp < end; sp++) {
    count[ByteOf(sp, offset)]++;
  }
  
  /*transform count into index by summing elements and storing into array*/
  for (s = 0, cp = count, end = count + 256; cp < end; cp++) {
    c = *cp;
    *cp = s;
    s += c;
  }

  /*fill dest with right values in the right place*/
  for (sp = source, end = source + max; sp < end; sp++) {
    cp = count + ByteOf(sp, offset); /*get the pointer to the index of the n'th place in the histogram(count)*/
    dest[*cp] = *sp;                 /*copy the whole 64bit word to that index position in the destination buffer*/
    ++(*cp);                         /*increment the index for other words with the same position in the n'th place*/
  }
}
Exemplo n.º 3
0
static void RadixMap_sort_optimized(RadixMap *map, uint64_t max, size_t starting_index,
										uint32_t smallest_key, uint32_t biggest_key)
{
	uint64_t *source = &map->contents[starting_index].raw;
	uint64_t *temp = &map->temp[starting_index].raw;
	
	uint32_t range_key = smallest_key | biggest_key;

	int i = 0;

	int drop_high_digits = 0;
	int drop_low_digits = 0;

	for(i = DIGITS - 1; i >= 0; i--) {
		if(ByteOf(&range_key, i) == 0) {
			drop_high_digits++;
		} else {
			break;
		}
	}

	for(i = 0; i < DIGITS; i++) {
		if(ByteOf(&range_key, i) == 0) {
			drop_low_digits++;
		} else {
			break;
		}
	}
	
	int significant_digits = 0;

	for(i = drop_low_digits; i < DIGITS - drop_high_digits; i++) {

		if(significant_digits % 2 == 0) {
			radix_sort(i, max, source, temp);
		} else {
			radix_sort(i, max, temp, source);
		}

		significant_digits++;
	}

	if(significant_digits > 0 && significant_digits % 2 == 1) {
		memcpy(source, temp, max * sizeof(uint64_t));
	}
}
Exemplo n.º 4
0
static inline void radix_sort(short offset, uint64_t max, uint64_t *source, uint64_t *dest)
{
  uint64_t count[256] = {0};
  uint64_t *cp = NULL;
  uint64_t *sp = NULL;
  uint64_t *end = NULL;
  uint64_t s = 0;
  uint64_t c = 0;

  // count occurances of every byte value
  for (sp = source, end = source + max; sp < end; sp++) {
    c = *cp;
    *cp = s;
    s += c;
  }

  // fill dest with the right values in the right place
  for (sp = source, end = source + max; sp < end; sp++) {
    cp = count + ByteOf(sp, offset);
    dest[*cp] = *sp;
    ++(*cp);
  }
}