Untitled

 avatar
unknown
c_cpp
a year ago
887 B
9
Indexable
bitset<DATA_MAX> WildCardSearch(string word, int index, int root) {
		int len = word.size();
		if(len == 3 && word[1] == '*') {
			bitset<DATA_MAX> result;
			result.set();
			return result;
		}
		if (word[index] == '*') {
			while (index+1 < len && word[index+1] == '*') {
				index++; // avoid multiple '*'
			}
			if (index == len-2) {
				return prefix[root];
			}
			bitset<DATA_MAX> result;
			for (int i = 0; i < 26; ++i) {
				if (trie[root][i] != 0) {
					result |= ((WildCardSearch(word, index, trie[root][i]) | WildCardSearch(word, index + 1, root)));
				}
			}
			return result;
		} 
		else {
			int charIndex = charToIndex(word[index]);
			if (trie[root][charIndex] == 0) {
				return NOT_FOUND;
			}
			if(index == len-2) {
				return ed[trie[root][charIndex]];
			}
			return WildCardSearch(word, index + 1, trie[root][charIndex]);
		}
	}
Editor is loading...
Leave a Comment