コード例 #1
0
ファイル: fuzzystrmatch.c プロジェクト: JiannengSun/postgres
Datum
levenshtein(PG_FUNCTION_ARGS)
{
	text	   *src = PG_GETARG_TEXT_PP(0);
	text	   *dst = PG_GETARG_TEXT_PP(1);
	const char *s_data;
	const char *t_data;
	int			s_bytes,
				t_bytes;

	/* Extract a pointer to the actual character data */
	s_data = VARDATA_ANY(src);
	t_data = VARDATA_ANY(dst);
	/* Determine length of each string in bytes and characters */
	s_bytes = VARSIZE_ANY_EXHDR(src);
	t_bytes = VARSIZE_ANY_EXHDR(dst);

	PG_RETURN_INT32(varstr_levenshtein(s_data, s_bytes, t_data, t_bytes, 1, 1,
									   1));
}
コード例 #2
0
Datum
levenshtein_with_costs(PG_FUNCTION_ARGS)
{
	text	   *src = PG_GETARG_TEXT_PP(0);
	text	   *dst = PG_GETARG_TEXT_PP(1);
	int			ins_c = PG_GETARG_INT32(2);
	int			del_c = PG_GETARG_INT32(3);
	int			sub_c = PG_GETARG_INT32(4);
	const char *s_data;
	const char *t_data;
	int			s_bytes,
				t_bytes;

	/* Extract a pointer to the actual character data */
	s_data = VARDATA_ANY(src);
	t_data = VARDATA_ANY(dst);
	/* Determine length of each string in bytes */
	s_bytes = VARSIZE_ANY_EXHDR(src);
	t_bytes = VARSIZE_ANY_EXHDR(dst);

	PG_RETURN_INT32(varstr_levenshtein(s_data, s_bytes, t_data, t_bytes,
									   ins_c, del_c, sub_c, false));
}