public void TestRedBlackTree() { RedBlackTree tree = new RedBlackTree(""); tree.Insert("1"); tree.Insert("2"); tree.Insert("3"); tree.Insert("4"); tree.Insert("5"); tree.Insert("6"); tree.Insert("16"); tree.Insert("17"); tree.Insert("18"); tree.Insert("19"); tree.Insert("0"); tree.Insert("e"); tree.Insert("F"); tree.Insert("G"); tree.Insert("h"); tree.Insert("7"); tree.Insert("8"); tree.Insert("9"); tree.Insert("10"); tree.Insert("11"); tree.Insert("12"); tree.Insert("13"); tree.Insert("14"); tree.Insert("15"); tree.Insert("A"); tree.Insert("b"); tree.Insert("C"); tree.Insert("d"); tree.PrintTree(); string test = (string)tree.Find("5"); Assert.AreEqual("5",test,"5 should have been added"); test = (string)tree.Find("b",new System.Collections.Comparer(new System.Globalization.CultureInfo("en-us"))); Assert.AreEqual("b",test,"b should have been added"); test = (string)tree.Find("B",new System.Collections.Comparer(new System.Globalization.CultureInfo("en-us"))); Assert.AreEqual(null,test,"B should not have been found when searching via a case-sensitive search"); test = (string)tree.Find("B",new System.Collections.CaseInsensitiveComparer()); Assert.AreEqual("b",test,"B should be found when searching via a case-insensitive search"); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged /// resources; <c>false</c> to release only unmanaged resources. /// </param> /// ------------------------------------------------------------------------------------ protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { // release managed objects if (components != null) components.Dispose(); if (m_fwTextBoxTestWs != null) m_fwTextBoxTestWs.Dispose(); // We may have made the cache from COM objects given to us by a COM client. // In that case, we have to dispose it. if (m_cacheMadeLocally && m_cache != null) m_cache.Dispose(); if (m_langDefCurrent != null) m_langDefCurrent.ReleaseRootRb(); if (cbDictionaries != null) cbDictionaries.Dispose(); } // release unmanaged objects regardless of disposing flag if (m_fwt != null && Marshal.IsComObject(m_fwt)) { System.Runtime.InteropServices.Marshal.ReleaseComObject(m_fwt); m_fwt = null; } if (m_strmLog != null && Marshal.IsComObject(m_strmLog)) { System.Runtime.InteropServices.Marshal.ReleaseComObject(m_strmLog); m_strmLog = null; } PUACharacter.ReleaseTheCom(); // Garbage collect the cached ICU m_cachedIcu = null; // GC.Collect(); Can't be deterministic about when it happens, even by calling for a collection. m_langDefCurrent = null; m_fwTextBoxTestWs = null; cbDictionaries = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a new empty Icu Cache, if it doesn't already exist /// </summary> /// ------------------------------------------------------------------------------------ private void InitializeIcuCache() { // Only fill the cache if it hasn't been done. if (m_cachedIcu == null) { // Set the initial capacity to include the entire first range m_cachedIcu = new RedBlackTree(new PUACharacter("")); } }