mirror of
https://github.com/dvorka/hstr.git
synced 2024-12-25 08:55:09 +08:00
More efficient radix index evaluation.
This commit is contained in:
parent
9875792881
commit
fc60ac469d
1 changed files with 10 additions and 10 deletions
|
@ -15,8 +15,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#define GET_TOP_INDEX(KEY) (unsigned)trunc(((double)KEY)/(double)SLOT_SIZE)
|
#define GET_TOP_INDEX(KEY) KEY/SLOT_SIZE
|
||||||
#define GET_LOW_INDEX(KEY, TOPINDEX) KEY-TOPINDEX*SLOT_SIZE
|
#define GET_LOW_INDEX(KEY) KEY%SLOT_SIZE
|
||||||
|
|
||||||
void radixsort_init(RadixSorter *rs, unsigned keyLimit) {
|
void radixsort_init(RadixSorter *rs, unsigned keyLimit) {
|
||||||
unsigned topIndexLimit=GET_TOP_INDEX(keyLimit);
|
unsigned topIndexLimit=GET_TOP_INDEX(keyLimit);
|
||||||
|
@ -46,7 +46,7 @@ RadixItem **radixsort_get_slot(RadixSorter *rs, unsigned topIndex) {
|
||||||
|
|
||||||
void radixsort_add(RadixSorter *rs, RadixItem *item) {
|
void radixsort_add(RadixSorter *rs, RadixItem *item) {
|
||||||
unsigned topIndex = GET_TOP_INDEX(item->key);
|
unsigned topIndex = GET_TOP_INDEX(item->key);
|
||||||
unsigned lowIndex = GET_LOW_INDEX(item->key, topIndex);
|
unsigned lowIndex = GET_LOW_INDEX(item->key);
|
||||||
|
|
||||||
|
|
||||||
if(!rs->topDigits[topIndex]) {
|
if(!rs->topDigits[topIndex]) {
|
||||||
|
@ -75,10 +75,10 @@ void radix_dec_slot_descriptor_size(RadixSorter *rs, RadixSlot *descriptor, unsi
|
||||||
descriptor->max=0;
|
descriptor->max=0;
|
||||||
} else {
|
} else {
|
||||||
if(descriptor->size==1) {
|
if(descriptor->size==1) {
|
||||||
if(rs->topDigits[topIndex][descriptor->max]) {
|
if(rs->topDigits[topIndex][GET_LOW_INDEX(descriptor->max)]) {
|
||||||
descriptor->min=descriptor->max;
|
descriptor->min=descriptor->max;
|
||||||
} else {
|
} else {
|
||||||
if(rs->topDigits[topIndex][descriptor->min]) {
|
if(rs->topDigits[topIndex][GET_LOW_INDEX(descriptor->min)]) {
|
||||||
descriptor->max=descriptor->min;
|
descriptor->max=descriptor->min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ RadixItem *radix_cut(RadixSorter *rs, unsigned key, void *data) {
|
||||||
// TODO optimization: fix min/max on cut of a value
|
// TODO optimization: fix min/max on cut of a value
|
||||||
if(key<=rs->maxKey) {
|
if(key<=rs->maxKey) {
|
||||||
unsigned topIndex = GET_TOP_INDEX(key);
|
unsigned topIndex = GET_TOP_INDEX(key);
|
||||||
unsigned lowIndex = GET_LOW_INDEX(key, topIndex);
|
unsigned lowIndex = GET_LOW_INDEX(key);
|
||||||
|
|
||||||
if(rs->topDigits[topIndex]) {
|
if(rs->topDigits[topIndex]) {
|
||||||
RadixItem *ri=rs->topDigits[topIndex][lowIndex];
|
RadixItem *ri=rs->topDigits[topIndex][lowIndex];
|
||||||
|
@ -128,8 +128,8 @@ RadixItem **radixsort_dump(RadixSorter *rs) {
|
||||||
do {
|
do {
|
||||||
if(rs->topDigits[t]) {
|
if(rs->topDigits[t]) {
|
||||||
if(rs->_slotDescriptors[t]->size>0) {
|
if(rs->_slotDescriptors[t]->size>0) {
|
||||||
l=GET_LOW_INDEX(rs->_slotDescriptors[t]->max,t);
|
l=GET_LOW_INDEX(rs->_slotDescriptors[t]->max);
|
||||||
slotMin=GET_LOW_INDEX(rs->_slotDescriptors[t]->min,t);
|
slotMin=GET_LOW_INDEX(rs->_slotDescriptors[t]->min);
|
||||||
slotSize=rs->_slotDescriptors[t]->size;
|
slotSize=rs->_slotDescriptors[t]->size;
|
||||||
slotCount=0;
|
slotCount=0;
|
||||||
do {
|
do {
|
||||||
|
@ -162,8 +162,8 @@ void radixsort_stat(RadixSorter *rs) {
|
||||||
if(rs->topDigits[t]) {
|
if(rs->topDigits[t]) {
|
||||||
printf("\n Slot %u (size/min/max): %u %u %u",t, rs->_slotDescriptors[t]->size, rs->_slotDescriptors[t]->min, rs->_slotDescriptors[t]->max);
|
printf("\n Slot %u (size/min/max): %u %u %u",t, rs->_slotDescriptors[t]->size, rs->_slotDescriptors[t]->min, rs->_slotDescriptors[t]->max);
|
||||||
if(rs->_slotDescriptors[t]->size>0) {
|
if(rs->_slotDescriptors[t]->size>0) {
|
||||||
l=GET_LOW_INDEX(rs->_slotDescriptors[t]->max,t);
|
l=GET_LOW_INDEX(rs->_slotDescriptors[t]->max);
|
||||||
slotMin=GET_LOW_INDEX(rs->_slotDescriptors[t]->min,t);
|
slotMin=GET_LOW_INDEX(rs->_slotDescriptors[t]->min);
|
||||||
slotSize=rs->_slotDescriptors[t]->size;
|
slotSize=rs->_slotDescriptors[t]->size;
|
||||||
slotCount=0;
|
slotCount=0;
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in a new issue