src/siri/db/points.c
/*
 * This merge method works best when having both a lot of series and having
 * any number of points for each series.
 */
This merge method works best when having both a lot of series and having
any number of points for each series.
This merge method works best when having both a lot of series and having any number of points for each series .
static void POINTS_highest_and_merge(slist_t * plist, siridb_points_t * points)
{
    siridb_points_t ** m = NULL;
    size_t i, n, l = 0;
    siridb_points_t ** tpts;
    uint64_t highest = 0;
    n = points->len;
    while (plist->len)
    {
        if (m != NULL)
        {
            tpts = m;
            m = NULL;
            for (; l < plist->len; l++, tpts++)
            {
                if (((*tpts)->data + (*tpts)->len)->ts == highest)
                {
                    m = tpts;
                    break;
                }
            }
        }
        if (m == NULL)
        {
            m = (siridb_points_t **) plist->data;
            for (i = 1, tpts = m + 1; i < plist->len; i++, tpts++)
            {
                if (((*tpts)->data + (*tpts)->len)->ts >
                    ((*m)->data + (*m)->len)->ts)
                {
                    m = tpts;
                    l = i;
                    highest = ((*m)->data + (*m)->len)->ts;
                }
            }
        }
        points->data[--n] = (*m)->data[(*m)->len];
        if ((*m)->len--)
        {
            m++;
            l++;
        }
        else
        {
            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
}
static void POINTS_highest_and_merge ( slist_t * plist , siridb_points_t * points ) { siridb_points_t * * m = NULL ; size_t i , n , l = 0 ; siridb_points_t * * tpts ; uint64_t highest = 0 ; n = points -> len ; while ( plist -> len ) { if ( m != NULL ) { tpts = m ; m = NULL ; for ( ; l < plist -> len ; l ++ , tpts ++ ) { if ( ( ( * tpts ) -> data + ( * tpts ) -> len ) -> ts == highest ) { m = tpts ; break ; } } } if ( m == NULL ) { m = ( siridb_points_t * * ) plist -> data ; for ( i = 1 , tpts = m + 1 ; i < plist -> len ; i ++ , tpts ++ ) { if ( ( ( * tpts ) -> data + ( * tpts ) -> len ) -> ts > ( ( * m ) -> data + ( * m ) -> len ) -> ts ) { m = tpts ; l = i ; highest = ( ( * m ) -> data + ( * m ) -> len ) -> ts ; } } } points -> data [ -- n ] = ( * m ) -> data [ ( * m ) -> len ] ; if ( ( * m ) -> len -- ) { m ++ ; l ++ ; } else { 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 }
This merge method works best when having both a lot of series and having
 any number of points for each series.
This merge method works best when having both a lot of series and having any number of points for each series .
/* size should be exactly zero */