view example/regex_mas/ppe/Exec.cc @ 1786:ba6ffc679a8f draft

minor fix
author Masataka Kohagura <e085726@ie.u-ryukyu.ac.jp>
date Sat, 30 Nov 2013 21:06:44 +0900
parents a9ff87220a68
children 5cde37f02c66
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((int)skip[(int)text[i]],sw_len - j);
    }
    return match_counter;
}

static int
run(SchedTask *s, void *rbuf, void *wbuf)
{
    //set_inData
    unsigned char *i_data = (unsigned char *)s->get_input(rbuf,0);
    unsigned char *search_word = (unsigned char*)s->get_input(rbuf,1);
    //unsigned char search_word[] = "doing";
    int *skip_table = (int *)s->get_input(rbuf,2);
    int length = (int)s->get_inputSize(0);
    int sw_len = (int)s->get_inputSize(1);
    //set_param
    s->printf("length %d\n",length);
    s->printf("sw_len %d\n",sw_len);

    unsigned long long *o_data = (unsigned long long*)wbuf;
    o_data[0] = 0;

    s->printf("pre o_data :%d\n",o_data[0]);
    o_data[0] = BM_method(i_data,length,search_word,sw_len,skip_table);
    s->printf("aft o_data :%d\n",o_data[0]);

    //s->printf("in Exec.cc\n");
    return 0;
}