void radixsort_add(RadixSorter *rs, RadixItem *item) { if(item->key > rs->keyLimit) { if(rs->_debug > RADIX_DEBUG_LEVEL_NONE) { fprintf(stderr, "WARNING: Radix sort overflow - inserted key is bigger than limit (%u): %u\n", rs->keyLimit, item->key); } if(rs->optionBigKeys==RADIX_BIG_KEYS_FLOOR) { item->key = rs->keyLimit-1; } else { if(rs->optionBigKeys==RADIX_BIG_KEYS_SKIP) { return; } else { exit(0); } } } unsigned topIndex = GET_TOP_INDEX(item->key); unsigned lowIndex = GET_LOW_INDEX(item->key); if(!rs->topDigits[topIndex]) { rs->topDigits[topIndex]=radixsort_get_slot(rs, topIndex); } RadixItem *chain=rs->topDigits[topIndex][lowIndex]; rs->topDigits[topIndex][lowIndex]=item; if(chain==NULL) { item->next=NULL; } else { item->next=chain; } rs->size++; rs->maxKey=MAX(rs->maxKey,item->key); rs->_slotDescriptors[topIndex]->min=MIN(rs->_slotDescriptors[topIndex]->min,item->key); rs->_slotDescriptors[topIndex]->max=MAX(rs->_slotDescriptors[topIndex]->max,item->key); rs->_slotDescriptors[topIndex]->size++; }
void radixsort_add(RadixSorter *rs, RadixItem *item) { unsigned topIndex = GET_TOP_INDEX(item->key); unsigned lowIndex = GET_LOW_INDEX(item->key); if(!rs->topDigits[topIndex]) { rs->topDigits[topIndex]=radixsort_get_slot(rs, topIndex); } RadixItem *chain=rs->topDigits[topIndex][lowIndex]; rs->topDigits[topIndex][lowIndex]=item; if(chain==NULL) { item->next=NULL; } else { item->next=chain; } rs->size++; rs->maxKey=MAX(rs->maxKey,item->key); rs->_slotDescriptors[topIndex]->min=MIN(rs->_slotDescriptors[topIndex]->min,item->key); rs->_slotDescriptors[topIndex]->max=MAX(rs->_slotDescriptors[topIndex]->max,item->key); rs->_slotDescriptors[topIndex]->size++; }