コード例 #1
0
ファイル: trie.cpp プロジェクト: AshKarath/bumo
	int Trie::NextBranch(const Location& s1, const Location& s2){
		int len1 = s1.length();
		if (s1.at(0) == ODD_PREFIX){
			char ch = s2.at(len1 - 1);
			return ch & 0x0f;
		}
		else {
			char ch = s2.at(len1);
			return (ch >> 4) & 0x0f;
		}
	}
コード例 #2
0
ファイル: trie.cpp プロジェクト: AshKarath/bumo
	Location Trie::CommonPrefix(const Location& s1, const Location& s2){
		Location out = "";
		char pre = EVEN_PREFIX;
		out.push_back(pre);
		for (std::size_t i = 1; i < s1.length() && i < s2.length(); i++){
			char c1 = s1.at(i);
			char c2 = s2.at(i);
			if ((c1 & 0xf0) != (c2 & 0xf0)){
				break;
			}

			if (i == s1.length() - 1 && s1.at(0) == ODD_PREFIX){
				char ch = c1 & 0xf0;
				out.push_back(ch);
				pre = ODD_PREFIX;
				break;
			}

			if (i == s2.length() - 1 && s2.at(0) == ODD_PREFIX){
				char ch = c1 & 0xf0;
				out.push_back(ch);
				pre = ODD_PREFIX;
				break;
			}

			if ((c1 & 0x0f) != (c2 & 0x0f)){
				char ch = c1 & 0xf0;
				out.push_back(ch);
				pre = ODD_PREFIX;
				break;
			}

			char ch = c1;
			out.push_back(ch);
		}
		out[0] = pre;
		return out;
	}