コード例 #1
0
ファイル: timing_tests.cpp プロジェクト: mclow/search-library
void check_one (  const Container &haystack, const Container &needle, int where ) {
	int expected;
	switch ( where ) {
		case -2: {
					auto it = std::search ( haystack.begin (), haystack.end (), needle.begin (), needle.end ());
					 assert ( it != haystack.end ());
					 expected = std::distance ( haystack.begin (), it);
				 }
				 break;
				 
		case -3: expected = haystack.size () - needle.size (); break;
		default: expected = where; break;
		}
	
    std::cout << "Needle is " << needle.size () << " entries long\n";
	duration stds = std_search ( haystack, needle, expected );
	std::cout << "Standard search took       :            " << stds.count ()   << "\t(" << dur_pct ( stds, stds ) << ")" << std::endl;
	duration def = default_search ( haystack, needle, expected );
	std::cout << "Default search took       :             " << def.count ()    << "\t(" << dur_pct ( stds, def ) << ")" << std::endl;
	duration def_p = default_search ( haystack, needle, expected );
	std::cout << "Default search w/pred took:             " << def_p.count ()  << "\t(" << dur_pct ( stds, def_p ) << ")" << std::endl;
	duration bm = bm_search ( haystack, needle, expected );
	std::cout << "Boyer-Moore search took:                " << bm.count ()     << "\t(" << dur_pct ( stds, bm ) << ")" << std::endl;
	duration bm_map = bm_search_map ( haystack, needle, expected );
	std::cout << "Boyer-Moore (map) search took:          " << bm_map.count () << "\t(" << dur_pct ( stds, bm_map ) << ")" << std::endl;
	duration bmh = bmh_search ( haystack, needle, expected );
	std::cout << "Boyer-Moore-Horspool search took:       " << bmh.count ()    << "\t(" << dur_pct ( stds, bmh ) << ")" << std::endl;
	duration bmh_map = bmh_search_map ( haystack, needle, expected );
	std::cout << "Boyer-Moore-Horspool (map) search took: " << bmh_map.count ()<< "\t(" << dur_pct ( stds, bmh_map ) << ")" << std::endl;
	}
コード例 #2
0
ファイル: filter_env.c プロジェクト: chutz/pkgcore
/* Sets an exception and returns NULL if out of memory. */
static const char *
walk_here_statement(const char *start, const char *p, const char *end)
{
	char *end_here, *temp_string;
	++p;
	/* DEBUG("starting here processing for COMMAND for level 2 at p == '%.10s'",
	 * p); */
	if (p >= end) {
		fprintf(stderr, "bailing\n");
		return p;
	}
	if ('<' == *p) {
		/* d2printf("correction, it's a third level here.  Handing back to "
		 * "command parsing\n"); */
		return ++p;
	}
	while (p < end && (isspace(*p) || '-' == *p))
		++p;

	if ('\'' == *p || '"' == *p) {
		end_here = (char *)walk_statement_no_parsing(p + 1, end, *p);
		++p;
	} else {
		end_here = (char *)walk_command_complex(start, p, end,
												' ', SPACE_PARSING);
		if (!end_here)
			return NULL;
	}

	/* INFO("end_here=%.5s",end_here); */
	temp_string = malloc(end_here -p + 1);
	if (!temp_string) {
		PyErr_NoMemory();
		return NULL;
	}
	int here_len = end_here - p;
	Py_MEMCPY(temp_string, p, here_len);
	temp_string[here_len] = '\0';
	/* d2printf("matched len('%zi')/'%s' for a here word\n", end_here - p,
	 * temp_string); */
	/* XXX watch this.  potential for horkage.  need to do the quote
		removal thing.
		this sucks.
	*/
	++end_here;
	if (end_here >= end) {
		free(temp_string);
		return end_here;
	}

	end_here = (char *)bmh_search((unsigned char*)temp_string,
								  (unsigned char*)end_here, end - end_here);
	while(end_here) {
		char *i = end_here + here_len;
		if (';' == *i || '\n' == *i || '\r' == *i) {
			i = end_here - 1;
			while (i != p && ('\t' == *i || ' ' == *i))
				--i;
			if (i != p && '\n' == *i)
				break;
		}
		end_here = (char *)bmh_search((unsigned char*)temp_string,
									  (unsigned char*)(end_here + here_len),
									  end - end_here - here_len);
	}
	INFO("bmh returned %p", end_here);
	free(temp_string);

	if (!end_here) {
		return end;
	}
	/* d2printf("bmh = %.10s\n", end_here); */
	return end_here + here_len;
}
コード例 #3
0
char * my_locate (const char * pattern, const char * data, const long datalen)
{
  bmh_init (pattern);
  return   (bmh_search (data, datalen) );
}