Txでdartsのようなtraverseをする関数
- Author: harajune
- Filed under: 雑記
Monday
Aug 31,2009
Txでdartsのようなtraverseをする関数を作ってみました。
使い方はdartsのtraverseと同じだと思います。たまたま作ったのでパッチをそのまま貼っておきます。動作は未保証。dartsよりも爆速でふきました。
CODE:
-
diff -cb tx-0.13/tx.cpp tx_original/tx.cpp
-
*** tx-0.13/tx.cpp 2009-04-13 13:21:14.000000000 +0900
-
--- tx_original/tx.cpp 2009-08-27 22:45:25.000000000 +0900
-
***************
-
*** 195,200 ****
-
--- 195,221 ----
-
return 0;
-
}
-
-
+ uint tx::traverse(const char* str, size_t& pos) const {
-
+ uint curPos = 2;
-
+ uint retId = NOTFOUND;
-
+ size_t begin = pos;
-
+ if (terminal.getSize() <= 2) return retId;
-
+
-
+ for (size_t i = 0 ; ; i++){
-
+ const uint nodeId = loud.rank(curPos-1,1)-1;
-
+ if (terminal.getBit(nodeId)){
-
+ pos = begin + i;
-
+ retId = terminal.rank(nodeId,1)-1;
-
+ }
-
+ uint nextPos = getChild(curPos,str[begin + i]);
-
+ if (nextPos == UINT_MAX){
-
+ break;
-
+ }
-
+ curPos = nextPos;
-
+ }
-
+ return retId;
-
+ }
-
+
-
uint tx::prefixSearch(const char* str, const size_t len, size_t& retLen) const {
-
uint curPos = 2;
-
uint retId = NOTFOUND;
-
diff -cb tx-0.13/tx.hpp tx_original/tx.hpp
-
*** tx-0.13/tx.hpp 2008-06-03 21:05:00.000000000 +0900
-
--- tx_original/tx.hpp 2009-08-27 22:41:04.000000000 +0900
-
***************
-
*** 26,31 ****
-
--- 26,32 ----
-
int read(const char* fileName);
-
-
uint prefixSearch(const char* str, const size_t len, size_t& retLen) const;
-
+ uint traverse(const char* str, size_t& pos) const;
-
uint expandSearch(const char* str, const size_t len, std::vector<std::string>& ret, const uint limit = 0) const;
-
uint commonPrefixSearch(const char* str, const size_t len, std::vector<std::string>& ret, std::vector<uint>& retID, const uint limit = TX_LIMIT_DEFAULT) const;
-
uint commonPrefixSearch(const char* str, const size_t len, std::vector<uint>& retLen, std::vector<uint>& retID, const uint limit = TX_LIMIT_DEFAULT) const;
-
***************
-
*** 42,48 ****
-
-
static uint NOTFOUND;
-
-
! private:
-
uint getChild(const uint pos, const char c) const;
-
uint getParent(const uint pos, char& c) const;
-
void enumerateAll(const uint pos, const std::string str, std::vector<std::pair<size_t, std::pair<std::string, uint>>>& ret) const;
-
--- 43,49 ----
-
-
static uint NOTFOUND;
-
-
! // private:
-
uint getChild(const uint pos, const char c) const;
-
uint getParent(const uint pos, char& c) const;
-
void enumerateAll(const uint pos, const std::string str, std::vector<std::pair<size_t, std::pair<std::string, uint>>>& ret) const;
One Response for "Txでdartsのようなtraverseをする関数"
[...] Txでdartsのようなtraverseをする関数 – 進・日進月歩 blog.gijutsuya.jp/harajune/2009/08/31/tx-darts-traverse – view page – cached #RSS 2.0 RSS .92 Atom 0.3 進・日進月歩 » Txでdartsのようなtraverseをする関数 Comments Feed 進・日進月歩 時代はwordpressだって? sennaでpatricia treeを作る キーワード自動リンクの話 — From the page [...]
Leave a reply