字符md5快速查找

//分类
const tagMap={
};

function findTag(s) {
    let pos=1;
    let tag=s.substr(0,pos);
    while (tagMap[tag]){
        pos++;
        tag=s.substr(0,pos);
    }

    return pos-1;
}

function set(s1,callback) {

    const pos=findTag(s1);
    const tag=s1.substr(0,pos);
    const d=s1[pos];

    const arr=tagMap[tag];
    if(arr){
        if(arr.indexOf(s1.substr(pos))===-1){
            const arr1=[]
            const arr2=[]
            arr.forEach(function (str) {
                if(str[0]===d){
                    arr2.push(str.substr(1))
                }else{
                    arr1.push(str)
                }
            })
            if(arr2.length===0){
                tagMap[tag].push(s1.substr(pos));
            }else{
                tagMap[tag]=arr1;
                arr2.push(s1.substr(pos+1))
                tagMap[tag+d]=arr2;
            }

        }else{

        }

    }else{
        tagMap[tag]=[]
        tagMap[tag].push(s1.substr(pos));
    }

}

set('552cb8e71eea229fd1ea8ac0010057e6')
set('552cb8e71eea229fd1ea8ac0010057e6')
set('542cb8e71eea229fd1ea8ac0010057e6')
set('532cb8e71eea229fd1ea8ac0010057e6')
set('522cb8e71eea229fd1ea8ac0010057e6')
set('512cb8e71eea229fd1ea8ac0010057e6')

console.log(tagMap)

猜你喜欢

转载自www.cnblogs.com/caoke/p/11902123.html
MD5