src/siri/db/series.c
/*
 * Will sort an index to its correct order. The start of idx should be correct
 * with a valid shard. All replaced shard indexes are sorted towards the end.
 */
Will sort an index to its correct order. The start of idx should be correct
with a valid shard. All replaced shard indexes are sorted towards the end.
Will sort an index to its correct order . The start of idx should be correct with a valid shard . All replaced shard indexes are sorted towards the end .
static void SERIES_idx_sort(
        idx_t * idx,
        uint_fast32_t start,
        uint_fast32_t end)
{
    siridb_shard_t * shard = idx[start].shard;
    idx_t * a, * b;
    uint_fast32_t i = start;
    uint_fast32_t n, m;
    idx_t tmp;
    while (++i < end)
    {
        a = idx + i;
        b = idx + i + 1;
        if (    b->shard == shard &&
                (a->shard != shard || a->start_ts > b->start_ts))
        {
            n = i - start;
            m = i + 1;
            tmp = idx[m];
            do
            {
                idx[m] = idx[m - 1];
                m--;  
            }
            while (--n && (
                    idx[m - 1].shard != tmp.shard ||
                    idx[m - 1].start_ts > tmp.start_ts));
            idx[m] = tmp;
        }
    }
}
static void SERIES_idx_sort ( idx_t * idx , uint_fast32_t start , uint_fast32_t end ) { siridb_shard_t * shard = idx [ start ] . shard ; idx_t * a , * b ; uint_fast32_t i = start ; uint_fast32_t n , m ; idx_t tmp ; while ( ++ i < end ) { a = idx + i ; b = idx + i + 1 ; if ( b -> shard == shard && ( a -> shard != shard || a -> start_ts > b -> start_ts ) ) { n = i - start ; m = i + 1 ; tmp = idx [ m ] ; do { idx [ m ] = idx [ m - 1 ] ; m -- ; } while ( -- n && ( idx [ m - 1 ] . shard != tmp . shard || idx [ m - 1 ] . start_ts > tmp . start_ts ) ) ; idx [ m ] = tmp ; } } }
Will sort an index to its correct order.
Will sort an index to its correct order .
/*
     * Since the first position is always correct we can leave this one alone.
     */ /*
         * We only need to swap if at least the last position is of the correct
         * shard and if the time-stamps should be swapped.
         */ /*
             * Swap at least a and b but also check if we can swap a - 1 with b
             */ /* we must decrement here */