Ejemplo n.º 1
0
Archivo: sort.c Proyecto: ljx0305/tbox
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_void_t tb_sort(tb_iterator_ref_t iterator, tb_size_t head, tb_size_t tail, tb_iterator_comp_t comp)
{
    // check
    tb_assert_and_check_return(iterator);

    // no elements?
    tb_check_return(head != tail);

    // readonly?
    tb_assert_and_check_return(!(tb_iterator_mode(iterator) & TB_ITERATOR_MODE_READONLY));

#ifdef TB_CONFIG_MICRO_ENABLE
    // random access iterator?
    tb_assert_and_check_return(tb_iterator_mode(iterator) & TB_ITERATOR_MODE_RACCESS);

    // sort it
    tb_quick_sort(iterator, head, tail, comp);
#else
    // random access iterator? 
    if (tb_iterator_mode(iterator) & TB_ITERATOR_MODE_RACCESS) 
    {
        if (tb_distance(iterator, head, tail) > 100000) tb_heap_sort(iterator, head, tail, comp);
        else tb_quick_sort(iterator, head, tail, comp); //!< @note the recursive stack size is limit
    }
    else tb_insert_sort(iterator, head, tail, comp);
#endif
}
Ejemplo n.º 2
0
tb_void_t tb_insert_sort_all(tb_iterator_ref_t iterator, tb_iterator_comp_t comp)
{
    tb_insert_sort(iterator, tb_iterator_head(iterator), tb_iterator_tail(iterator), comp);
}