Esempio n. 1
0
static apr_status_t
lcn_multi_reader_fs_field_bitvector( lcn_index_reader_t *index_reader,
                                     lcn_bitvector_t **bitvector,
                                     const char *fname,
                                     lcn_bool_t (*filter_function)( lcn_fs_field_t *, unsigned int ),
                                     apr_pool_t *pool )
{
    apr_status_t s;

    do
    {
        unsigned int i;
        unsigned int bv_size;

        lcn_fs_field_t *field = (lcn_fs_field_t*) apr_hash_get( index_reader->fs_fields,
                                                                fname,
                                                                APR_HASH_KEY_STRING );

        LCNCE( lcn_index_reader_null_bitvector( index_reader, bitvector, pool ) );

        if ( NULL == field )
        {
            return s;
        }

        /* assert that the field is loaded to RAM */

        bv_size = lcn_bitvector_size( *bitvector );

        for( i = 0; i < bv_size; i++ )
        {
            unsigned int val;
            LCNCE( lcn_fs_field_int_value( (lcn_fs_field_t*) field, &val, i ));

            if ( filter_function( (lcn_fs_field_t*) field, i ))
            {
                LCNCE( lcn_bitvector_set_bit( *bitvector, i ));
            }
        }
    }
    while(0);

    return s;
}
Esempio n. 2
0
static apr_status_t
lcn_multi_reader_fs_field_int_bitvector( lcn_index_reader_t *reader,
                                         lcn_bitvector_t **bitvector,
                                         const char *fname,
                                         lcn_bool_t (*filter_function) (void* data, unsigned int val, unsigned int doc_order ),
                                         void *filter_data,
                                         apr_pool_t *pool )
{
    apr_status_t s;

    do
    {
        unsigned int i;
        unsigned int bv_size;

        lcn_fs_field_t *field = (lcn_fs_field_t*) apr_hash_get( reader->fs_fields,
                                                                fname,
                                                                APR_HASH_KEY_STRING );

        LCNCE( lcn_index_reader_null_bitvector( reader, bitvector, pool ) );

        if ( NULL == field )
        {
            return s;
        }

        bv_size = lcn_bitvector_size( *bitvector );

        for( i = 0; i < bv_size; i++ )
        {
            unsigned int val;

            LCNCE( lcn_fs_field_int_value( (lcn_fs_field_t*) field, &val, i ));

            if ( filter_function( filter_data, val, i ))
            {
                LCNCE( lcn_bitvector_set_bit( *bitvector, i ));
            }
        }
    }
    while(0);

    return s;
}
Esempio n. 3
0
/* Apply filter manually by copying iters from romFullList model to romDisplay model
 * if they match filter criteria. Optimized to just do a sort on romDisplaymodel if
 * filter is empty twice in a row.
 */
static void apply_filter()
{
    int g_iNumRoms;
    static short resort = 0;
    GtkTreeModel* destination;
    const gchar* filter;

    filter = gtk_entry_get_text(GTK_ENTRY(g_MainWindow.filter));
    if(filter[0]!='\0'||resort==1)
        {
        if(filter[0]!='\0')
            resort=1;
        else
            resort=0;

        GtkTreeModel *model, *source;
        GtkTreeIter sourceiter, destinationiter;
        gboolean validiter;

        char *country, *goodname, *usercomments, *filename, *md5hash, *crc1, *crc2, *internalname, *savetype, *players, *size, *compressiontype, *imagetype, *cicchip, *rumble;
        GdkPixbuf *status[5];
        GdkPixbuf *flag;
        cache_entry* entry; 
        short int counter;

        /* Clear the display model. */
        GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_MainWindow.romDisplay));
        gtk_tree_selection_select_all(selection);
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay));
        gtk_list_store_clear(GTK_LIST_STORE(model));

        source = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romFullList));
        g_iNumRoms = gtk_tree_model_iter_n_children(source, NULL);
        validiter = gtk_tree_model_get_iter_first(source, &sourceiter);

        destination = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay));
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(destination), g_MainWindow.romSortColumn,  return_zero, (gpointer)NULL, (gpointer)NULL);

        if(validiter)
            {
            for(counter = 0; counter < g_iNumRoms; ++counter)
                {
                if(filter_function(source, &sourceiter, (gpointer)NULL))
                    {
                    gtk_tree_model_get(GTK_TREE_MODEL(source), &sourceiter, 0, &country, 1, &goodname, 3, &usercomments, 4, &filename, 5, &md5hash, 6, &crc1, 7, &crc2, 8, &internalname, 9, &savetype, 10, &players, 11, &size, 12, &compressiontype, 13, &imagetype, 14, &cicchip, 15, &rumble, 16, &status[0], 17, &status[1], 18, &status[2], 19, &status[3], 20, &status[4], 21, &flag, 22, &entry, -1);

                    gtk_list_store_append(GTK_LIST_STORE(destination), &destinationiter);
                    gtk_list_store_set(GTK_LIST_STORE(destination), &destinationiter, 0, country, 1, goodname, 2, NULL, 3, usercomments, 4, filename, 5, md5hash, 6, crc1, 7, crc2, 8, internalname, 9, savetype, 10, players, 11, size, 12, compressiontype, 13, imagetype, 14, cicchip, 15, rumble, 16, status[0], 17, status[1], 18, status[2], 19, status[3], 20, status[4], 21, flag, 22, entry, -1);
                    }
                if(!gtk_tree_model_iter_next(source, &sourceiter))
                     break;
                }
           }
        }
    else
        destination = gtk_tree_view_get_model(GTK_TREE_VIEW(g_MainWindow.romDisplay));

        /* Always sort romDisplay, otherwise regular column sorting won't work. */
        gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(destination), g_MainWindow.romSortColumn,  rombrowser_compare, (gpointer)NULL, (gpointer)NULL);
        gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(destination), g_MainWindow.romSortColumn, g_MainWindow.romSortType);
}