Exemple #1
0
typename BinaryTree<T>::Node* BinaryTree<T>::_Find(Node *root,const T &value){
	if(root==NULL){
		return NULL;
	}
	if(root->_value == value){
		return root;
	}
	Node *ret = _Find(root->_left,value);
	if(ret==NULL){
		ret = _Find(root->_right,value);
	}
	return ret;
}
Exemple #2
0
	bool _Find(vector<vector<char> >& board, int curM, int curN, 
			string& word, int p, vector<vector<bool> >& used) {
		if (p >= word.size()) return true;
		
		int m = board.size();
		int n = board[0].size();
		static int M_DIFF[] = {-1, 0, 1, 0};
		static int N_DIFF[] = {0, 1, 0, -1};
		
		for (int i = 0; i < 4; ++i) {
			int newM = curM + M_DIFF[i];
			int newN = curN + N_DIFF[i];
			if (newM < 0 || newM >= m || newN < 0 || newN >= n)
				continue;
			if (used[newM][newN])
				continue;
			if (board[newM][newN] == word[p]) {
				used[newM][newN] = true;
				if (_Find(board, newM, newN, word, p+1, used))
					return true;
				else
					used[newM][newN] = false;
			}
		}
		return false;
	}
bool FileFinder::_Find(DirectorySpecifier &dir, Typecode type, bool recursive, int depth)
{
	// Get list of entries in directory
	vector<dir_entry> entries;
	if (!dir.ReadDirectory(entries))
		return false;
	sort(entries.begin(), entries.end());

	// Iterate through entries
	vector<dir_entry>::const_iterator i, end = entries.end();
	for (i = entries.begin(); i != end; i++) {

		// Construct full specifier of file/dir
		FileSpecifier file = dir + i->name;

		if (i->is_directory) {

			if (depth == 0 && i->name == "Plugins")
				continue;

			// Recurse into directory
			if (recursive)
				if (_Find(file, type, recursive, depth + 1))
					return true;

		} else {

			// Check file type and call found() function
			if (type == WILDCARD_TYPE || type == file.GetType())
				if (found(file))
					return true;
		}
	}
	return false;
}
	Node<T> * _Find(Node<T> *pRoot, const T &data) 
	{
		if (NULL != pRoot)
		{
			if (pRoot->_val == data)
				return pRoot;
			else
			{	Node<T> *ret;
				ret = _Find(pRoot->pLeft, data);
				if (ret)
					return ret;
				ret = _Find(pRoot->pRight, data);
				if (ret)
					return ret;
			}
		}
		return NULL;
	}
	BSTNode<K,V>* _Find(BSTNode<K,V>* root, const K& key)
	{
		if (root)
		{
			if (root->_key > key)
			{
				return _Find(root->_left, key);
			}
			else if (root->_key < key)
			{
				return _Find(root->_right, key);
			}
			else
			{
				return root;
			}
		}

		return NULL;
	}
Exemple #6
0
/*!
	Returns false if argv dispatcher with the same name already
	registered
*/
bool
Settings::Add(SettingsArgvDispatcher* setting)
{
	// check for uniqueness
	if (_Find(setting->Name()))
		return false;

	if (fCount >= fListSize) {
		fListSize += 30;
		fList = (SettingsArgvDispatcher **)realloc(fList,
			fListSize * sizeof(SettingsArgvDispatcher *));
	}
	fList[fCount++] = setting;
	return true;
}
Exemple #7
0
//---------------------------------------------------------
void CCandidates::Add(int x, int y, int Segment, double Similarity)
{
	if( m_Candidates && m_nCandidates < m_nMax )
	{
		int	iInsert	= _Find(Similarity);

		memmove(m_Candidates + iInsert + 1, m_Candidates + iInsert, sizeof(TCandidate) * (m_nCandidates - iInsert));

		m_Candidates[iInsert].x				= x;
		m_Candidates[iInsert].y				= y;
		m_Candidates[iInsert].Segment		= Segment;
		m_Candidates[iInsert].Similarity	= Similarity;
	}
	else
	{
		if( !m_pLow )
		{
			int	iDivide	= m_nMax / 2;

			m_pLow	= new CCandidates(m_nMax);
			m_pHigh	= new CCandidates(m_nMax);

			m_pLow ->m_nCandidates	= iDivide;
			m_pHigh->m_nCandidates	= m_nMax - iDivide;

			memcpy(m_pLow ->m_Candidates, m_Candidates                        , m_pLow ->m_nCandidates * sizeof(TCandidate));
			memcpy(m_pHigh->m_Candidates, m_Candidates + m_pLow->m_nCandidates, m_pHigh->m_nCandidates * sizeof(TCandidate));

			SG_Free(m_Candidates);
			m_Candidates	= NULL;
		}

		if( Similarity > m_pHigh->Get_Minimum() )
		{
			m_pHigh->Add(x, y, Segment, Similarity);
		}
		else
		{
			m_pLow ->Add(x, y, Segment, Similarity);
		}
	}

	m_nCandidates++;
}
Exemple #8
0
    bool exist(vector<vector<char> > &board, string word) {
        if (board.empty() || board[0].empty() || word.empty())
			return false;
		
		int m = board.size();
		int n = board[0].size();
		
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < n; ++j) {
				if (board[i][j] == word[0]) {
					vector<vector<bool> > used(m, vector<bool>(n, false));
					used[i][j] = true;
					if (_Find(board, i, j, word, 1, used)) return true;
					used[i][j] = false;
				}
			}
		}
		return false;
    }
Exemple #9
0
typename BinaryTree<T>::Node* BinaryTree<T>::Find(const T &value){
	return _Find(_root,value);
}
Exemple #10
0
status_t
Attribute::Find(int32 index)
{
	return _Find(NULL, index);
}
Exemple #11
0
status_t
Attribute::Find(const char* name)
{
	return _Find(name, -1);
}
Exemple #12
0
status_t
BPlusTree::FindExact(struct btrfs_key &key, void** _value, size_t* _size)
{
	return _Find(key, _value, _size, BPLUSTREE_EXACT);
}
Exemple #13
0
status_t
BPlusTree::FindPrevious(struct btrfs_key &key, void** _value, size_t* _size)
{
	return _Find(key, _value, _size, BPLUSTREE_BACKWARD);
}
Exemple #14
0
status_t
BPlusTree::FindNext(struct btrfs_key &key, void** _value, size_t* _size)
{
	return _Find(key, _value, _size, BPLUSTREE_FORWARD);
}
	BSTNode<K,D>* Find(const K& key)
	{
		return _Find(_root, key);
	}
	BSTNode<K,V>* Find_R(const K& key)
	{
		return _Find(_root, key);
	}
	Node<T> * Find(const T &data)
	{
		return _Find(pRoot, data);
	}