コード例 #1
0
ファイル: Trie.cs プロジェクト: v-geberr/EntityMatch
        private void LevelVisit(int k)
        {
            BFS_Q.Clear();
            BFS_Q.Enqueue(0);
            m_AN1.AddNode(0, 0);

            while (BFS_Q.Count > 0)
            {
                int nextState = BFS_Q.Dequeue();
                //int distance = m_level[nextState];
                int distance = m_AN1.Distance(nextState);
                Debug.Assert(distance <= k);
                m_AN1.AddNode(nextState, distance);
                if (distance == k)
                {
                    continue;
                }
                m_childState.BeginTarget(nextState);
                int tmpState;
                while ((tmpState = m_childState.GetNextTarget()) != -1)
                {
                    BFS_Q.Enqueue(tmpState);
                    m_AN1.AddNode(tmpState, distance + 1);
                }
            }
        }
コード例 #2
0
ファイル: Trie.cs プロジェクト: v-geberr/EntityMatch
        public void AppendChar(char c)
        {
            m_prefix += c;
            int prefixlen = m_prefix.Length;

            int currState;
            int idx = prefixlen - 1;

            while ((currState = m_AN1.GetNext()) != -1)
            {
                int dist = m_AN1.Distance(currState);
                if (dist < m_CurrentLookupThreshold)
                {
                    m_AN2.AddNode(currState, dist + 1);
                }

                int childState_inputChar = Goto(currState, c);
                if (childState_inputChar != -1 && childState_inputChar != 0)
                {
                    m_AN2.AddNode(childState_inputChar, dist);
                }

                int newdist = m_AN2.Distance(currState);
                int mindist = (dist < newdist) ? dist : newdist;
                if (mindist < m_CurrentLookupThreshold)
                {
                    m_childState.BeginTarget(currState);

                    int childState;
                    while ((childState = m_childState.GetNextTarget()) != -1)
                    {
                        if (childState != childState_inputChar)
                        {
                            m_AN2.AddNode(childState, mindist + 1);
                        }
                    }
                }
            }
            m_AN1.ClearDistances();
            Swap(ref m_AN1, ref m_AN2);
            m_totalValidNodes += m_AN1.Count;
#if DEBUG
            //Console.WriteLine("No. of active nodes after character {1}: {0}", AN1.Count, i + 1);
            //ActiveNodeAggregator.Add(i + 1, AN1.Count);
#endif
        }