Exemplo n.º 1
0
        public void SetUpScoredEntities()
        {
            //This version of NUnit does not support TestFixtureSetUp
            if (!testFixtureSetUp)
            {
                // Create a list.
                entities = GenerateList(20);

                Console.WriteLine("Original list");
                ScoredEntity.PrintList(entities);
                Console.WriteLine();

                //Sort list and make radix tree.
                entities.Sort(ScoredEntity.CompareEntitiesByScore);
                radixEntities = new trie <int>(10);
                int index = 0;
                foreach (var entity in entities)
                {
                    String[] names = entity.name.ToLower().Split('_');
                    foreach (var name in names)
                    {
                        radixEntities.Add(name, index);
                    }
                    ++index;
                }

                testFixtureSetUp = true;
            }
        }
Exemplo n.º 2
0
 internal trie <T> Add(string s, T value)
 {
     if (values.Count < this.maxResults)
     {
         if (values.Count == 0 || !values[values.Count - 1].Equals(value))
         {
             values.Add(value);
         }
     }
     if (s.Length > 0)
     {
         if (!edges.ContainsKey(s[0]))
         {
             edges[s[0]] = new trie <T>(maxResults);
         }
         if (s.Length > 1)
         {
             edges[s[0]].Add(s.Substring(1, s.Length - 1), value);
         }
         else
         {
             edges[s[0]].Add("", value);
         }
     }
     return(this);
 }
Exemplo n.º 3
0
        public void Solve()
        {
            var n = ri;
            var L = rl;
            var r = new trie();

            for (int i = 0; i < n; i++)
            {
                var s  = rs;
                var rr = r;
                for (int j = 0; j < s.Length; j++)
                {
                    var v = s[j] - '0';
                    if (rr.ch[v] == null)
                    {
                        rr.ch[v] = new trie();
                    }
                    rr = rr.ch[v];
                }
                rr.sz++;
            }
            var map = new HashMap <long, int>();
            Action <trie, int> dfs = null;

            dfs = (root, d) =>
            {
                if (root.sz == 1)
                {
                    return;
                }
                for (int k = 0; k < 2; k++)
                {
                    if (root.ch[k] != null)
                    {
                        dfs(root.ch[k], d + 1);
                    }
                    else
                    {
                        map[(L - d) & -(L - d)] ^= 1;
                    }
                }
            };
            dfs(r, 0);
            if (map.Sum(x => x.Value) > 0)
            {
                Console.WriteLine("Alice");
            }
            else
            {
                Console.WriteLine("Bob");
            }
        }
Exemplo n.º 4
0
        public AutoCompleteUI()
        {
            InitializeComponent();
            init_trie = new trie();
            //reads file form trie directory
            string[] readText = File.ReadAllLines("../../wordsEn.txt");

            //loads the source of the trie file into memory
            foreach (string word in readText)
            {
                init_trie.insert(word);
            }
        }
Exemplo n.º 5
0
        public void SerializeDeserialize()
        {
            var    jsEntities = new JsonSerializer <List <ScoredEntity> >();
            string json       = jsEntities.Serialize(entities);

            entities = jsEntities.Deserialize(json);
            Assert.IsNotNull(entities);
            Assert.AreEqual(entities.Count, 20);

            var jsTrie = new JsonSerializer <trie <int> >();

            json          = jsTrie.Serialize(radixEntities);
            radixEntities = jsTrie.Deserialize(json);
            Assert.IsNotNull(radixEntities);
        }