KinoSearch1

 view release on metacpan or  search on metacpan

lib/KinoSearch1/Search/HitCollector.pm  view on Meta::CPAN

our %instance_vars;

sub new {
    my $self = shift->SUPER::new;
    confess kerror() unless verify_args( \%instance_vars, @_ );
    my %args = @_;
    croak("Required parameter: 'hit_collector'")
        unless a_isa_b( $args{hit_collector},
        "KinoSearch1::Search::HitCollector" );

    $self->_set_filter_bits( $args{filter_bits} );
    $self->_set_storage( $args{hit_collector} );
    $self->_define_collect;

    return $self;
}

package KinoSearch1::Search::OffsetCollector;
use strict;
use warnings;
use KinoSearch1::Util::ToolSet;
use base qw( KinoSearch1::Search::HitCollector );

BEGIN {
    __PACKAGE__->init_instance_vars(
        hit_collector => undef,
        offset        => undef,
    );
}
our %instance_vars;

sub new {
    my $self = shift->SUPER::new;
    confess kerror() unless verify_args( \%instance_vars, @_ );
    my %args = @_;
    croak("Required parameter: 'hit_collector'")
        unless a_isa_b( $args{hit_collector},
        "KinoSearch1::Search::HitCollector" );

    $self->_set_f( $args{offset} );
    $self->_set_storage( $args{hit_collector} );
    $self->_define_collect;

    return $self;
}

1;

__END__

__XS__

MODULE = KinoSearch1    PACKAGE = KinoSearch1::Search::HitCollector

void
new(either_sv)
    SV *either_sv;
PREINIT:
    const char   *class;
    HitCollector *hc;
PPCODE:
    hc    = Kino1_HC_new();
    class = sv_isobject(either_sv) 
        ? sv_reftype(either_sv, 0)
        : SvPV_nolen(either_sv);
    ST(0) = sv_newmortal();
    sv_setref_pv(ST(0), class, (void*)hc);
    XSRETURN(1);

=begin comment

    $hit_collector->collect( $doc_num, $score );

Process a doc_num/score combination.  In production, this method should not be
called from Perl, as collecting hits is an extremely data-intensive operation.

=end comment
=cut

void
collect(hc, doc_num, score)
    HitCollector *hc;
    U32           doc_num;
    float         score;
PPCODE:
    hc->collect(hc, doc_num, score);

SV* 
_set_or_get(hc, ...)
    HitCollector *hc;
ALIAS:
    _set_storage     = 1
    get_storage      = 2
    _set_i           = 3
    get_i            = 4
    _set_f           = 5
    _get_f           = 6
    _set_filter_bits = 7
    _get_filter_bits = 8
CODE:
{
    KINO_START_SET_OR_GET_SWITCH
    
    case 1:  SvREFCNT_dec(hc->storage_ref);
             hc->storage_ref = newSVsv( ST(1) );
             Kino1_extract_anon_struct(hc->storage_ref, hc->storage);
             /* fall through */
    case 2:  RETVAL = newSVsv(hc->storage_ref);
             break;

    case 3:  hc->i = SvUV( ST(1) );
             /* fall through */
    case 4:  RETVAL = newSVuv(hc->i);
             break;

    case 5:  hc->f = SvNV( ST(1) );
             /* fall through */
    case 6:  RETVAL = newSVnv(hc->f);
             break;
             
    case 7:  SvREFCNT_dec(hc->filter_bits_ref);
             hc->filter_bits_ref = newSVsv( ST(1) );
             Kino1_extract_struct( hc->filter_bits_ref, hc->filter_bits, 
                BitVector*, "KinoSearch1::Util::BitVector" );
             /* fall through */
    case 8:  RETVAL = newSVsv(hc->filter_bits_ref);
             break;

    KINO_END_SET_OR_GET_SWITCH
}
OUTPUT: RETVAL

void
DESTROY(hc)
    HitCollector *hc;
PPCODE:
    Kino1_HC_destroy(hc);


MODULE = KinoSearch1    PACKAGE = KinoSearch1::Search::HitQueueCollector

void
_define_collect(hc)
    HitCollector *hc;
PPCODE:
    hc->collect = Kino1_HC_collect_HitQueue;

MODULE = KinoSearch1    PACKAGE = KinoSearch1::Search::BitCollector

void
_define_collect(hc)
    HitCollector *hc;
PPCODE:
    hc->collect = Kino1_HC_collect_BitVec;

MODULE = KinoSearch1    PACKAGE = KinoSearch1::Search::FilteredCollector

void
_define_collect(hc);
    HitCollector *hc;
PPCODE:
    hc->collect = Kino1_HC_collect_filtered;

MODULE = KinoSearch1    PACKAGE = KinoSearch1::Search::OffsetCollector

void
_define_collect(hc);
    HitCollector *hc;
PPCODE:
    hc->collect = Kino1_HC_collect_offset;



__H__

#ifndef H_KINO_HIT_COLLECTOR
#define H_KINO_HIT_COLLECTOR 1

#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "KinoSearch1UtilCarp.h"
#include "KinoSearch1UtilMathUtils.h"
#include "KinoSearch1UtilBitVector.h"
#include "KinoSearch1UtilPriorityQueue.h"
#include "KinoSearch1UtilMemManager.h"

typedef struct hitcollector {
    void      (*collect)(struct hitcollector*, U32, float);
    float       f;
    U32         i;
    void       *storage;
    SV         *storage_ref;
    BitVector  *filter_bits;
    SV         *filter_bits_ref;
} HitCollector;

HitCollector* Kino1_HC_new();
void Kino1_HC_collect_death(HitCollector*, U32, float);
void Kino1_HC_collect_HitQueue(HitCollector*, U32, float);
void Kino1_HC_collect_BitVec(HitCollector*, U32, float);
void Kino1_HC_collect_filtered(HitCollector*, U32, float);
void Kino1_HC_collect_offset(HitCollector*, U32, float);
void Kino1_HC_destroy(HitCollector*);

#endif /* include guard */

__C__


#include "KinoSearch1SearchHitCollector.h"

HitCollector*
Kino1_HC_new() {
    HitCollector  *hc;

    /* allocate memory and init */
    Kino1_New(0, hc, 1, HitCollector);
    hc->f               = 0;
    hc->i               = 0;
    hc->storage         = NULL;
    hc->storage_ref     = &PL_sv_undef;
    hc->filter_bits     = NULL;
    hc->filter_bits_ref = &PL_sv_undef;

    /* force the subclass to spec a collect method */
    hc->collect = Kino1_HC_collect_death;

    return hc;



( run in 0.787 second using v1.01-cache-2.11-cpan-5511b514fd6 )