Пример #1
0
    Node_t* Remove(Node_t* node) {
        MZ_ASSERT_TRUE(!IsNull(node));
        MZ_ASSERT_TRUE(IsContain(node));

        auto prevNode = node->m_prevNode;
        auto nextNode = node->m_nextNode;
        if (IsNull(prevNode)) {
            MZ_ASSERT_TRUE(node == m_headNode);
            m_headNode = nextNode;
        }
        else {
            prevNode->m_nextNode = nextNode;
        }
        if (IsNull(nextNode)) {
            MZ_ASSERT_TRUE(node == m_tailNode);
            m_tailNode = prevNode;
        }
        else {
            nextNode->m_prevNode = prevNode;
        }
        node->m_prevNode = nullptr;
        node->m_nextNode = nullptr;
        --m_size;
        return nextNode;
    }
Пример #2
0
    Node_t* InsertAfter(Node_t* location, Node_t* node) {
        MZ_ASSERT_TRUE(!IsNull(location));
        MZ_ASSERT_TRUE(!IsNull(node));
        MZ_ASSERT_TRUE(IsContain(location));
        MZ_ASSERT_TRUE(!IsContain(node));

        auto nextNode = location->m_nextNode;
        if (IsNull(nextNode)) {
            m_tailNode = node;
        }
        else {
            nextNode->m_prevNode = node;
        }
        location->m_nextNode = node;
        node->m_prevNode = location;
        node->m_nextNode = nextNode;
        ++m_size;
        return node;
    }
Пример #3
0
    Node_t* InsertBefore(Node_t* location, Node_t* node) {
        MZ_ASSERT_TRUE(!IsNull(location));
        MZ_ASSERT_TRUE(!IsNull(node));
        MZ_ASSERT_TRUE(IsContain(location));
        MZ_ASSERT_TRUE(!IsContain(node));

        auto prevNode = location->m_prevNode;
        if (IsNull(prevNode)) {
            m_headNode = node;
        }
        else {
            prevNode->m_nextNode = node;
        }
        location->m_prevNode = node;
        node->m_prevNode = prevNode;
        node->m_nextNode = location;
        ++m_size;
        return node;
    }
Пример #4
0
/*
 * phrase is said to satisfy a choose interval if 
 * their intersections are the same */
static int CheckChoose(
		ChewingData *pgdata,
		int ph_id, int from, int to, Phrase **pp_phr, 
		char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ], 
		IntervalType selectInterval[], int nSelect )
{
	IntervalType inte, c;
	int chno, len;
	Phrase *phrase = ALC( Phrase, 1 );

	assert( phrase );
	inte.from = from;
	inte.to = to;
	*pp_phr = NULL;

	/* if there exist one phrase satisfied all selectStr then return 1, else return 0. */
	GetPhraseFirst( pgdata, phrase, ph_id );
	do {
		for ( chno = 0; chno < nSelect; chno++ ) {
			c = selectInterval[ chno ];

			if ( IsContain( inte, c ) ) {
				/* find a phrase of ph_id where the text contains 
				 * 'selectStr[chno]' test if not ok then return 0, if ok 
				 * then continue to test
				 */
				len = c.to - c.from;
				if ( memcmp(
					ueStrSeek( phrase->phrase, c.from - from ),
					selectStr[ chno ],
					ueStrNBytes( selectStr[ chno ], len ) ) )
					break;
			}
			else if ( IsIntersect( inte, selectInterval[ chno ] ) ) {
				free( phrase );
				return 0;
			} 
		}
		if ( chno == nSelect ) {
			*pp_phr = phrase;
			return 1;
		}
	} while ( GetPhraseNext( pgdata, phrase ) );
	free( phrase );
	return 0;
}
Пример #5
0
    Node_t* PushFront(Node_t* node) {
        MZ_ASSERT_TRUE(!IsNull(node));
        MZ_ASSERT_TRUE(!IsContain(node));

        node->m_prevNode = nullptr;
        node->m_nextNode = nullptr;
        if (IsNull(m_headNode)) {
            m_headNode = node;
            m_tailNode = node;
        }
        else {
            m_headNode->m_prevNode = node;
            node->m_nextNode = m_headNode;
            m_headNode = node;
        }
        ++m_size;
        return node;
    }
Пример #6
0
static int CheckUserChoose( 
		ChewingData *pgdata,
		uint16_t *new_phoneSeq, int from , int to,
		Phrase **pp_phr, 
		char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ], 
		IntervalType selectInterval[], int nSelect )
{
	IntervalType inte, c;
	int chno, len;
	int user_alloc;
	UserPhraseData *pUserPhraseData;
	Phrase *p_phr = ALC( Phrase, 1 );

	assert( p_phr );
	inte.from = from;
	inte.to = to;
	*pp_phr = NULL;

	/* pass 1
	 * if these exist one selected interval which is not contained by inte
	 * but has intersection with inte, then inte is an unacceptable interval
	 */
	for ( chno = 0; chno < nSelect; chno++ ) {
		c = selectInterval[ chno ];
		if ( IsIntersect( inte, c ) && ! IsContain( inte, c ) ) {
			free( p_phr );
			return 0;
		}
	}

	/* pass 2
	 * if there exist one phrase satisfied all selectStr then return 1, else return 0.
	 * also store the phrase with highest freq
	 */
	pUserPhraseData = UserGetPhraseFirst( pgdata, new_phoneSeq );
	p_phr->freq = -1;
	do {
		for ( chno = 0; chno < nSelect; chno++ ) {
			c = selectInterval[ chno ];

			if ( IsContain( inte, c ) ) {
				/* 
				 * find a phrase of ph_id where the text contains 
				 * 'selectStr[chno]' test if not ok then return 0, 
				 * if ok then continue to test. */
				len = c.to - c.from;
				if ( memcmp(
					ueStrSeek( pUserPhraseData->wordSeq, c.from - from ),
					selectStr[ chno ],
					ueStrNBytes( selectStr[ chno ], len ) ) )
					break;
			}

		}
		if ( chno == nSelect ) {
			/* save phrase data to "pp_phr" */
			if ( pUserPhraseData->userfreq > p_phr->freq ) {
				if ( ( user_alloc = ( to - from ) ) > 0 ) {
					ueStrNCpy( p_phr->phrase,
							pUserPhraseData->wordSeq,
							user_alloc, 1);
				}
				p_phr->freq = pUserPhraseData->userfreq;
				*pp_phr = p_phr;
			}
		}
	} while ( ( pUserPhraseData = UserGetPhraseNext( pgdata, new_phoneSeq ) ) != NULL );

	if ( p_phr->freq != -1 ) 
		return 1;
		
	free( p_phr );
	return 0;
}