Exemplo n.º 1
0
Arquivo: tree.c Projeto: why0603/angel
void RemoveTree(TreePtr tree,void* key)
{
	TreeNodePtr child;
	TreeNodePtr node = FindTreeNode(tree,key);
	if (NULL != node)
	{
		if ((NULL == node->left) || (NULL == node->right))
		{
			//单亲或者无孩子节点
			child = node;
		}
		else
		{
			//获取左孩子节点下的孙子节点中最大的值
			//这个节点必然没有右孩子
			child = GetLeftMaxNode(node);


			//替换KEY和VALUE
			memcpy(node->keyValue,child->keyValue,tree->keyByteSize + tree->valueByteSize);
		}
		DeleteTreeNode(tree,child);
	}
	else
	{
		//printf("\r\nnode is null!\r\n");
	}
}
Exemplo n.º 2
0
Arquivo: tree.c Projeto: why0603/angel
void GetFromTree(TreePtr tree,void* key,void* value)
{
	TreeNodePtr node = FindTreeNode(tree,key);
	if ((NULL != node) && (tree->valueByteSize > 0) && (NULL != value))
	{
		CopyData(value,(char*)node->keyValue + tree->keyByteSize,(DataType)tree->valueByteSize,tree->valueByteSize);
	}
}
Exemplo n.º 3
0
Arquivo: tree.c Projeto: why0603/angel
void* GetTree(TreePtr tree,void* key)
{
	TreeNodePtr node = FindTreeNode(tree,key);
	if (NULL != node)
	{
		return (char*)node->keyValue + tree->keyByteSize;
	}
	return NULL;
}
Exemplo n.º 4
0
Arquivo: tree.c Projeto: why0603/angel
Boolean ContairTree(TreePtr tree,void* key)
{
	Boolean ret = False;
	TreeNodePtr node = FindTreeNode(tree,key);
	if (NULL != node)
	{
		ret = True;
	}
	return ret;
}
Exemplo n.º 5
0
void MeowPinyin::PrintCandidate()
{
	wprintf(L"%s -->", input);
	UINT8 path[4] = { 0 };
	unsigned rlen = results.size();
	for (unsigned int rt = 0; rt < rlen; rt++)
	{
		unsigned rsize = results[rt].pinyin.size();
		for (unsigned int i = 0; i < 4; i++)
		{
			if (i < rsize)
			{
				path[i] = GetPinyinTreeID(results[rt].pinyin[i]);
			}
			else
			{
				break;
			}
		}
		UINT32 node = FindTreeNode(0, path, rsize, 4);
		MEOW_PHRASETREE_NODE * treenode = &tree_phrase[node];
		unsigned int casize = treenode->phrases.size();
		unsigned int count = 0;
		for (unsigned int i = 0; i < casize; i++)
		{
			bool match = true;
			MEOW_PHRASE_NODE * wn = &table_phrase[treenode->phrases[i]];
			if (wn->length < rsize) continue;
			for (unsigned int j = 0; j < rsize; j++)
			{
				if (!MatchCharToPinyin(wn->phrase[j], results[rt].pinyin[j]))
				{
					match = false;
					break;
				}
			}
			if (match)
			{
				_setmode(_fileno(stdout), _O_U16TEXT);
				count++;
				wprintf(L" %ls", wn->phrase);
				if (count < 75)
				{

				}
				else
				{
				}
			}
		}
	}

	wprintf(L"\n");
}
Exemplo n.º 6
0
UINT32 MeowPinyin::FindTreeNode(UINT32 _parent, UINT8 * next, UINT8 length, UINT8 depth) {
	if (length <= 0 || depth <= 0) {
		return _parent;
	}
	if (*next >= 26) {
		return 0;
	}
	MEOW_PHRASETREE_NODE * parent = &tree_phrase[_parent];
	if (parent->children == 0) {
		return 0;
	}
	return FindTreeNode(parent->children + *next, next + 1, length - 1, depth - 1);
}