<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      JavaScript 上萬關鍵字瞬間匹配 (轉 整理)

      ;(function (window, document, ns, undefined) {
          var Node = function  (data, parentNode) {
              this._childCount = 0;
              this.data = data;
              this.parentNode = parentNode || null;
              this.childNodes = {};
          };
          Node.prototype = {
              constuctor : Node,
              appendChild : function  (data) {
                  var child;
                  if(!(child = this.getChild(data))){
                      child = new Node(data, this);
                      this.childNodes[data] = child;
                      this._childCount ++;
                  }
                  return child;
              },
              getChild : function  (data) {
                  if(this.childNodes.hasOwnProperty(data)){
                      return this.childNodes[data];
                  }
                  return null;
              },
              removeChild : function  (data) {
                  var child;
                  if(child = this.getChild(data)){
                      delete this.childNodes[data];
                      this._childCount-- ;
                  }
                  return child;
              },
              clearChild : function  () {
                  this.childNodes = {};
                  this._childCount = 0;
                  return this;
              },
              hasChild : function  (data) {
                  if(!this._childCount){
                      return false;
                  }
                  if(arguments.length > 0){
                      for (var i = arguments.length; i--; ){
                          if(!this.getChild(arguments[i])){
                              return false;
                          }
                      }
                      return true;
                  }
                  return true;
              }
          };
       
          var TrieTree = function (aData) {
              var maxLength = 0;
              var currentStr;
              var currentChar;
              var root = new Node('');
              var currentNode;
              var childNode;
              for (var i = 0, l = aData.length; i < l; i++) {
                  if(!(currentStr = aData[i])){
                      continue;
                  }
                  currentNode = root;
       
                  for (var j = 0, li = currentStr.length; j < li; j++ ){
                      currentChar = currentStr.charAt(j);
                      childNode = currentNode.getChild(currentChar);
                      if(!childNode){
                          childNode = currentNode.appendChild(currentChar);
                      }
       
                      currentNode = childNode;
                  }
              };
       
              this._root  = root;
       
          };   
       
          TrieTree.prototype = {
              constuctor : TrieTree,
              exactMatch : function  (str) {
                  var currentNode = this._root;
                  var childNode;
                  for (var i = 0, l = str.length; i < l; i++){
                      childNode = currentNode.getChild(str.charAt(i));
                      if(!childNode){
                          return false;
                      }
                      currentNode = childNode;
                  }
                  if(currentNode.hasChild()){
                      return false;
                  }
                  return true;
              },
              mmFetch : function (str) {
                  var currentNode = this._root;
                  var childNode;
                  for (var i = 0, l = str.length; i < l; i++){
                      childNode = currentNode.getChild(str.charAt(i));
                      if(!childNode){
                          return false;
                      }
                      currentNode = childNode;
                  }
                  return true;
              }
          };
       
          ns.TrieTree = TrieTree;
       
      }(window, document, window));
       
       
       
       
      /*
          test case
          var dataSource = [
                '你好么',
                '你好呀',
                '你吃了么',
                '中國',
                '中南海',
                '中心思想',
                '上海',
                '上海人',
                '上證指數',
                '上海灘',
                '北京',
                '北京人',
                '北京你好',
                '北京猿人',
                '北京人在紐約'
            ];
            var tt  = new TrieTree(dataSource);
            document.write('<h1>數據源 : </h1></br>', dataSource.join('</br>'))
       
       
            var str = '上海灘';
            console.log(str, '\n前綴匹配 : ' + tt.mmFetch(str), '\n完全匹配 : ' + tt.exactMatch(str));

       

       

      var treeSearch = {
          makeTree: function(strKeys) {
              "use strict";
              var tblCur = {},
                  tblRoot,
                  key,
                  str_key,
                  Length,
                  j,
                  i
                  ;
              tblRoot = tblCur;
              for ( j = strKeys.length - 1; j >= 0; j -= 1) {
                  str_key = strKeys[j];
                  Length = str_key.length;
                  for ( i = 0; i < Length; i += 1) {
                      key = str_key.charAt(i);
                      if (tblCur.hasOwnProperty(key)) { //生成子節點
                          tblCur = tblCur[key];
                      } else {
                          tblCur = tblCur[key] = {};
                      }
                  }
                  tblCur.end = true; //最后一個關鍵字沒有分割符
                  tblCur = tblRoot;
              }
              return tblRoot;
          },
          search: function(content, tblRoot) {
              "use strict";
              var tblCur,
                  p_star = 0,
                  n = content.length,
                  p_end,
                  match,  //是否找到匹配
                  match_key,
                  match_str,
                  arrMatch = [],  //存儲結果
                  arrLength = 0   //arrMatch的長度索引
                  ;
       
              while (p_star < n) {
                  tblCur = tblRoot; //回溯至根部
                  p_end = p_star;
                  match_str = "";
                  match = false;
                  do {
                      match_key = content.charAt(p_end);
                      if (!(tblCur = tblCur[match_key])) { //本次匹配結束
                          p_star += 1;
                          break;
                      }else{
                          match_str += match_key;
                      }
                      p_end += 1;
                      if (tblCur.end === true) //是否匹配到尾部  //找到匹配關鍵字
                      {
                          match = true;
                      }
                  } while (true);
       
                  if (match === true) { //最大匹配
                      arrMatch[arrLength] = { //增強可讀性
                          key: match_str,
                          begin: p_star - 1,
                          end: p_end
                      };
                      arrLength += 1;
                      p_star = p_end;
                  }
              }
              return arrMatch;
          }
      };
      function test(strContent, strKeys) {
          var arrMatch,
              tblRoot = treeSearch.makeTree(strKeys),
              t = new Date();
       
       
          arrMatch = treeSearch.search(strContent, tblRoot);
       
          console.log("time is: " + (new Date() - t) + "mm");
       
          console.log(arrMatch);
      }
      var s = (function() {
          var Things = [' ', '\n', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
          var s = "";
          for (var i = 1000000; i >= 0; i--) {
              s += Things[parseInt(Math.random() * Things.length) % Things.length]
          };
          return s;
      })()
      test(s, ["abc", "efge", "fun", "tree"]);

       

       

       

      原文:http://www.rzrgm.cn/index-html/archive/2013/04/17/js_keyword_match.html

       

      http://www.rzrgm.cn/ry123/archive/2013/04/24/3039720.html

      posted @ 2020-06-17 11:34  Shikyoh  閱讀(419)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲欧美偷国产日韩| 日韩精品无码区免费专区| 国产超碰无码最新上传| 欧美巨大极度另类| 亚洲国产性夜夜综合| 亚洲人亚洲人成电影网站色| 国产亚洲一本大道中文在线| 国产午夜在线观看视频| 又大又粗又硬又爽黄毛少妇| 亚洲久悠悠色悠在线播放| 蜜臀av一区二区三区日韩| 亚洲日韩性欧美中文字幕| 国产专区精品三级免费看| 亚洲欧美日韩国产精品专区| 狠狠躁夜夜躁人人爽天天5| 人妻少妇精品系列一区二区| 少妇愉情理伦片丰满丰满午夜| 久久蜜臀av一区三区| 亚洲第一区二区快射影院| 亚洲暴爽av天天爽日日碰| 亚洲中文字幕aⅴ天堂| 自拍偷自拍亚洲精品情侣| 亚洲日韩久热中文字幕| 亚洲欧美激情在线一区| 日本人一区二区在线观看| 国产日韩久久免费影院| 青青草国产精品日韩欧美| 国产95在线 | 欧美| 最近中文字幕国产精品| 无码免费大香伊蕉在人线国产| 国产成人午夜福利在线观看| 国产精品无码av在线一区 | 97人人模人人爽人人少妇| 在线国产极品尤物你懂的| 亚洲中文字幕日产无码成人片| 另类国产精品一区二区| 夜夜偷天天爽夜夜爱| 国产亚洲无线码一区二区| 最新精品国产自偷在自线| 精品视频不卡免费观看| 午夜免费无码福利视频麻豆|