src/siri/db/points.c
/*
 * This merge method works best when having a lot of series with only one point
 * or when the total number of points it not so high.
 */
This merge method works best when having a lot of series with only one point
or when the total number of points it not so high.
This merge method works best when having a lot of series with only one point or when the total number of points it not so high .
static void POINTS_merge_and_sort(slist_t * plist, siridb_points_t * points)
{
    siridb_points_t ** m;
    size_t i, n;
    n = points->len;
    uint8_t use_simple_sort = n == plist->len;
    while (plist->len)
    {
        for (i = 0; i < plist->len; i++)
        {
            m = (siridb_points_t **) &plist->data[i];
            points->data[--n] = (*m)->data[(*m)->len];
            if (!(*m)->len--)
            {
                siridb_points_free(*m);
                if (--plist->len)
                {
                    *m = (siridb_points_t *) plist->data[plist->len];
                }
            }
            if (!(n % MAX_ITERATE_MERGE_COUNT))
            {
                usleep(3000);
            }
        }
    }
#ifdef DEBUG
    assert (n == 0);
#endif
    usleep(5000);
    if (use_simple_sort)
    {
        POINTS_simple_sort(points);
    }
    else
    {
        qsort(  points->data,
                points->len,
                sizeof(siridb_point_t),
                &POINTS_compare);
    }
}
static void POINTS_merge_and_sort ( slist_t * plist , siridb_points_t * points ) { siridb_points_t * * m ; size_t i , n ; n = points -> len ; uint8_t use_simple_sort = n == plist -> len ; while ( plist -> len ) { for ( i = 0 ; i < plist -> len ; i ++ ) { m = ( siridb_points_t * * ) & plist -> data [ i ] ; points -> data [ -- n ] = ( * m ) -> data [ ( * m ) -> len ] ; if ( ! ( * m ) -> len -- ) { siridb_points_free ( * m ) ; if ( -- plist -> len ) { * m = ( siridb_points_t * ) plist -> data [ plist -> len ] ; } } if ( ! ( n % MAX_ITERATE_MERGE_COUNT ) ) { usleep ( 3000 ) ; } } } #ifdef DEBUG assert ( n == 0 ) ; #endif usleep ( 5000 ) ; if ( use_simple_sort ) { POINTS_simple_sort ( points ) ; } else { qsort ( points -> data , points -> len , sizeof ( siridb_point_t ) , & POINTS_compare ) ; } }
This merge method works best when having a lot of series with only one point
 or when the total number of points it not so high.
This merge method works best when having a lot of series with only one point or when the total number of points it not so high .
/* size should be exactly zero */