利用trietree樹結構,使其匹配過程可以在o(n)內搞定
#ifndef match_user_agent_h_
#define match_user_agent_h_
#include #include using std::string;
using std::vector;
#define ua_tree_width 50
#define ua_trietree_trans_arr_len 128
class treenode ;
class useragentinfo ;
#endif
#include "cpc_user_agent.h"
bool useragentinfo::readuafile(const std::string &user_agent_file, vector&result)
return true;
}void useragentinfo::trietreetransinit()
bool useragentinfo::uainit(const string &user_agent_file)
trietreetransinit();
vectorkeywords;
if (!readuafile(user_agent_file, keywords))
vector::const_iterator it = keywords.begin();
for (; it != keywords.end(); ++it)
} return true;
}bool useragentinfo::uatreenodeinsert(const char* keyword)
int str_len = strlen(keyword);
for (int i = 0; i < str_len; ++i)
curr->next_[ua_trans_arr_[(int)keyword[i]]] = new_node;
}curr = curr->next_[ua_trans_arr_[(int)keyword[i]]];
if (i == str_len - 1)
else
}} return true;}/*
void useragentinfo::uafaildbuild()
else
p = p->fail_;
}if(null == p)
}queue_nodes_[queue_head_++] = temp->next_[i];}}
}}
*/bool useragentinfo::uatreenodedestory(treenode* root)
for (int i = 0; i < ua_tree_width; ++i)
}} if (root != ua_root_)
return false;
}bool useragentinfo::uatreedestory()
bool useragentinfo::uatreeclean()
/*memset(queue_nodes_, 0, sizeof(treenode*) * (ua_tree_width * ua_trietree_trans_arr_len));
queue_head_ = 1;
queue_tail_ = 1;
*/return true;
}bool useragentinfo::uatreedynamicload(const std::string &user_agent_file)
vector::const_iterator it = keywords.begin();
for (; it != keywords.end(); ++it)
} return true;
}bool useragentinfo::uamatch(const char* user_agent)
if (null == user_agent)
for (unsigned int i = 0; i < strlen(user_agent); ++i)
}else
else
}} return false;
}
利用Tree命令生成磁碟檔案列表
命令原型 d tree 以圖形顯示驅動器或路徑的資料夾結構。tree drive path f a f 顯示每個資料夾中檔案的名稱。a 使用 ascii 字元,而不使用擴充套件字元。應用舉例 如果想生成某磁碟整個資料夾列表,輸入以下命令 e tree e.txt 即可生成整個磁碟的資料夾列表 如果輸...
利用SIFT進行特徵匹配
sift演算法是一種基於尺度空間的演算法。利用sift提取出的特徵點對旋轉 尺度變化 亮度變化具有不變性,對視角變化 仿射變換 雜訊也有一定的穩定性。sift實現特徵的匹配主要包括四個步驟 1 提取特徵點 構建尺度空間 模擬影象的多尺度特徵。經證實,唯一可能的尺度空間核是高斯函式。用l x,y,表示...
括號匹配問題 stack的利用
題目 擴號匹配問題 poj.grids.cn 描述 在某個字串 長度不超過100 中有左括號 右括號和大小寫字母 規定 與常見的算術式子一樣 任何乙個左括號都從內到外與在它右邊且距離最近的右括號匹配。其中不能匹配的左括號用 標註,不能匹配的右括號用 標註 關於輸入 第一行乙個正整數n,表示資料的組數...