Example #1
0
void get_words_with_prefix(ucs4_t * word, int p)
{
	int i;
	static ucs4_t buff[DATRIE_WORD_MAX_LENGTH];
	static ucs4_t words_set_char_buff[DATRIE_WORD_MAX_COUNT];
	
	for (i = 0; i < p; i ++)
		buff[i] = word[i];
	buff[p] = 0;
	
	words_set_count = 0;
	for (i = binary_search(buff); i < lexicon_count && is_prefix(buff,lexicon[i].key); i ++)
	{
		if (ucs4cmp(buff,lexicon[i].key) == 0)
			continue;
		words_set_char_buff[words_set_count] = lexicon[i].key[p];
		words_set[words_set_count ++] = i;
	}
	words_set_char_buff[words_set_count] = 0;
	
	qsort(words_set_char_buff, words_set_count, sizeof(words_set_char_buff[0]), wcmp);
	
	ucs4_t * wfp, * wp, last;
	for (last = 0, wfp = words_set_char_buff, wp = words_set_char; *wfp; wfp ++)
	{
		if (*wfp != last)
		{
			last = *wfp;
			*wp = *wfp;
			wp ++;
		}
	}
	*wp = 0;
}
Example #2
0
int binary_search(const ucs4_t *str)
{
	int a = 0,b = lexicon_count - 1,c;
	while (a + 1 < b)
	{
		c = (a + b) / 2;
		if (ucs4cmp(str,lexicon[c].key) <= 0)
			b = c;
		else
			a = c+1;
	}
	if (is_prefix(str,lexicon[a].key) && (a == 0 || !is_prefix(str,lexicon[a-1].key)))
		return a;
	if (is_prefix(str,lexicon[b].key) && !is_prefix(str,lexicon[b-1].key))
		return b;
	return -1;
}
Example #3
0
File: text.c Project: Axure/librime
int qsort_entry_cmp(const void* a, const void* b) {
  return ucs4cmp(((TextEntry*)a)->key, ((TextEntry*)b)->key);
}
Example #4
0
int cmp(const void *a, const void *b)
{
	return ucs4cmp(((const opencc_entry *)a)->key, ((const opencc_entry *)b)->key);
}