view example/regex_mas/ppe/Exec.cc @ 1809:138e7edff3ae draft

fix bound int size
author Yuhi TOMARI <yuhi@cr.ie.u-ryukyu.ac.jp>
date Wed, 11 Dec 2013 18:42:34 +0900
parents a77876642bb3
children 45139c74dad1
line wrap: on
line source

#include <stdio.h>
#include <string.h>
#include "Exec.h"
#include "Func.h"
#include "SchedTask.h"
#define max(a,b)((a)>(b)?a:b) 

/* これは必須 */
SchedDefineTask(Exec);

//ボイヤームーア法による文字列検索アルゴリズム
static int BM_method(unsigned char *text,int text_len,
              unsigned char *pattern,int sw_len,int *skip)
{
    int i = sw_len - 1;
    int match_counter = 0;

    while ( i < text_len){
        int j = sw_len - 1;
        while (text[i] == pattern[j]){
            if (j == 0){
                match_counter++;
            }
            --i;
            --j;
        }
        i = i + max(skip[text[i]],sw_len - j);
    }
    return match_counter;
}

static int
run(SchedTask *s, void *rbuf, void *wbuf)
{
    //get_input
    unsigned char *i_data = (unsigned char *)s->get_input(rbuf, 0);
    unsigned char *search_word = (unsigned char *)s->get_input(rbuf, 1);
    int *skip_table = (int *)s->get_input(rbuf, 2);

    int length = (int)s->get_inputSize(0);
    int sw_len = (int)s->get_inputSize(1);

    //get_param
    //long task_count = (long)s->get_param(0);  //何番目のtaskか
    //s->printf("[task count: %lld]\n",task_count+1);

    unsigned long long *o_data = (unsigned long long*)s->get_output(wbuf,0);

    o_data[0] = 0;
    o_data[0] = BM_method(i_data,length,search_word,sw_len,skip_table);

    return 0;
}