public void BeginUpdate() { m_numStates = 1; m_numIndexEntities = 0; m_gotoFnUpdate = new IntPairHashTable(1000000); m_outputFnUpdate = new List <List <int> >(); m_childTokensUpdate = new List <List <char> >(); m_childTokensUpdate.Add(new List <char>(0)); m_outputFnUpdate.Add(new List <int>(0)); m_descendantsUpdate.Add(new List <int>(0)); }
private void MoveToLookupStructures() { MarkChains(); RenameNodeIds(); int nChains = m_nHiEdges - m_nHiSources + 1; for (int i = 0; i < m_numStates; i++) { if (m_descendantsUpdate[i].Count >= m_topL) { int newid = m_oldId2NewId[i]; int[] descendants = m_descendantsUpdate[i].ToArray(); m_descendants.Add(newid, descendants); } } m_descendantsUpdate.Clear(); m_descendantsUpdate = null; int nOutput = 0; for (int i = 0; i < m_numStates; i++) { if (m_outputFnUpdate[i].Count > 0) { nOutput++; } } m_outputFn = new OutputStruct[nOutput]; int totalChars = 0; foreach (string e in m_EntitiesUpdate) { totalChars += e.Length; } m_EntityChars = new char[totalChars]; m_EntityOffsets = new int[m_EntitiesUpdate.Count]; int currOffset = 0; int currEntityId = 0; foreach (string e in m_EntitiesUpdate) { m_EntityOffsets[currEntityId++] = currOffset; foreach (char c in e) { m_EntityChars[currOffset++] = c; } } m_EntitiesUpdate.Clear(); m_EntitiesUpdate = null; int TotalEdges = 0; int idx = 0; for (int i = 0; i < m_numStates; i++) { if (m_outputFnUpdate[i].Count > 0) { if (m_outputFnUpdate[i].Count > 1) { throw new Exception("Output size exceeded 1"); } m_outputFn[idx].nodeid = m_oldId2NewId[i]; m_outputFn[idx].entityid = m_outputFnUpdate[i][0]; idx++; } m_outputFnUpdate[i].Clear(); int nChildren = m_childTokensUpdate[i].Count; TotalEdges += nChildren; } OutputComparer comparer = new OutputComparer(); Array.Sort(m_outputFn, comparer); m_outputFnUpdate.Clear(); m_outputFnUpdate = null; m_childState = new TrieChildState(m_numStates, m_nHiSources, TotalEdges, m_nHiEdges); Dictionary <int, int> newId2oldId = new Dictionary <int, int>(); Dictionary <int, int> .Enumerator old2newEnum = m_oldId2NewId.GetEnumerator(); int maxNewId = 0; while (old2newEnum.MoveNext()) { newId2oldId.Add(old2newEnum.Current.Value, old2newEnum.Current.Key); if (old2newEnum.Current.Value > maxNewId) { maxNewId = old2newEnum.Current.Value; } } for (int i = 0; i < m_nHiSources; i++) { int oldid = newId2oldId[i]; m_childState.BeginHiSource(i, m_childTokensUpdate[oldid].Count); m_childTokensUpdate[oldid].Sort(); foreach (char c in m_childTokensUpdate[oldid]) { int tgt; m_gotoFnUpdate.TryGetValue(oldid, c, out tgt); m_childState.AddHiTarget(i, c, m_oldId2NewId[tgt]); } m_childTokensUpdate[oldid].Clear(); } m_childState.BeginLo(); for (int i = m_nHiSources; i < maxNewId; i++) { int oldid = newId2oldId[i]; if (m_chains.ContainsKey(oldid)) { m_childState.AddLo(i, m_chains[oldid].ToCharArray()); } } newId2oldId.Clear(); newId2oldId = null; m_childTokensUpdate.Clear(); m_childTokensUpdate = null; m_gotoFnUpdate.Clear(); m_gotoFnUpdate = null; m_oldId2NewId.Clear(); m_oldId2NewId = null; m_chains.Clear(); m_chains = null; }
static void Main(string[] args) { Random randomNumberGenerator = new Random(1234); int randomNumberCount = 10; int randomNumberSearchIndex = 8; // test out minesweeper TestMinesweeper(); return; // make a test array of numbers int[] randomIntegers = new int[randomNumberCount]; int[] randomIntegersAlt = new int[randomNumberCount]; for (int randomNumberIndex = 0; randomNumberIndex < randomNumberCount; ++randomNumberIndex) { randomIntegers[randomNumberIndex] = randomNumberGenerator.Next() % 100; randomIntegersAlt[randomNumberIndex] = randomIntegers[randomNumberIndex]; } // heap sorter test IntHeapSorter integerHeapSorter = new IntHeapSorter(); integerHeapSorter.Sort(randomIntegers); //IntHeapSorterAlt integerHeapSorterAlt = new IntHeapSorterAlt(); IntMergeSorter integerHeapSorterAlt = new IntMergeSorter(); integerHeapSorterAlt.Sort(randomIntegersAlt); // binary searcher test IntBinarySearcher integerBinarySearcher = new IntBinarySearcher(); int foundIndex = integerBinarySearcher.Search(randomIntegers, randomIntegers[randomNumberSearchIndex]); // hash table test IntPairHashTable integerHashTable = new IntPairHashTable(); for (int randomNumberIndex = 0; randomNumberIndex < randomNumberCount; ++randomNumberIndex) { integerHashTable.Add(randomIntegers[randomNumberIndex], randomNumberIndex); } for (int randomNumberIndex = 0; randomNumberIndex < randomNumberCount; ++randomNumberIndex) { int randomNumberValue; integerHashTable.Get(randomIntegers[randomNumberIndex], out randomNumberValue); } randomNumberSearchIndex = randomNumberCount - 1; while (randomNumberSearchIndex >= 0) { integerHashTable.Remove(randomIntegers[randomNumberSearchIndex]); for (int randomNumberIndex = 0; randomNumberIndex < randomNumberSearchIndex; ++randomNumberIndex) { int randomNumberValue; integerHashTable.Get(randomIntegers[randomNumberIndex], out randomNumberValue); } randomNumberSearchIndex--; } // binary tree set test IntBinaryTreeSet integerBinaryTreeSet = new IntBinaryTreeSet(); for (int randomNumberIndex = 0; randomNumberIndex < randomNumberCount; ++randomNumberIndex) { integerBinaryTreeSet.AddElement(randomIntegers[randomNumberIndex]); } integerBinaryTreeSet.Output(); integerBinaryTreeSet.Serialize("test_binary_tree_set.txt"); integerBinaryTreeSet.Deserialize("test_binary_tree_set.txt"); integerBinaryTreeSet.Output(); }