コード例 #1
0
ファイル: Trie.cs プロジェクト: Hussain008/Spotlight
            int IComparer.Compare(Object a, Object b)
            {
                FileObj x = (FileObj)a;
                FileObj y = (FileObj)b;

                return(y.rank - x.rank);
            }
コード例 #2
0
        void BuildTrie()
        {
            trie = new Trie(new TrieNode('H'));

            //reading the all the file names, location and rank
            string[] lines = File.ReadAllLines(@"C:\\Users\\gunny\\source\\repos\\Spotlight\\allFilesCopy.txt", Encoding.UTF8);


            foreach (string line in lines)
            {
                char[] spearator = { '<' };
                char[] sep2      = { '\\' };
                char[] sep3      = { ' ' };

                String[] strlist  = line.Split(spearator);
                String   location = strlist[0];

                String[] tmp = location.Split(sep2);

                string name = tmp[tmp.Length - 1];

                FileObj newFile = new FileObj(name.ToLower(), location, Convert.ToInt32(strlist[1]));

                trie.Insert(trie.root, newFile, 0);
            }
            Debug.WriteLine("Trie built");
            trie.Update(trie.root);

            trie.Dfs(trie.root, "", 0);
            Debug.WriteLine("DFS done");

            Debug.WriteLine(trie.map.Count);
        }
コード例 #3
0
ファイル: Trie.cs プロジェクト: Hussain008/Spotlight
        //basic trie insertion
        public void Insert(TrieNode node, FileObj file, int index)
        {
            if (index == file.name.Length)
            {
                //if reached the end of the string , simply add the current file to the list of current node's files
                node.files.Add(file);
                return;
            }

            char cur = file.name[index];

            //if child does not exist yet, then create it.
            if (!node.children.ContainsKey(cur))
            {
                node.children[cur] = new TrieNode(cur);
            }

            //recur for every chaaracter of the file
            Insert(node.children[cur], file, index + 1);
        }