TrimToSize() public method

public TrimToSize ( ) : void
return void
Esempio n. 1
0
 // Trim the capacity of this sorted list to its actual size.
 public override void TrimToSize()
 {
     lock (SyncRoot)
     {
         list.TrimToSize();
     }
 }
Esempio n. 2
0
 public override void TrimToSize()
 {
     lock (_root)
     {
         _list.TrimToSize();
     }
 }
 public override void TrimToSize()
 {
     lock (host.SyncRoot)
     {
         host.TrimToSize();
     }
 }
 static public int TrimToSize(IntPtr l)
 {
     try {
         System.Collections.SortedList self = (System.Collections.SortedList)checkSelf(l);
         self.TrimToSize();
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 5
0
		public void TestTrimToSize ()
		{
			SortedList sl1 = new SortedList (24);

			sl1.TrimToSize ();

			for (int i = 72; i >= 0; i--)
				sl1.Add (100 + i, i);
			sl1.TrimToSize ();
		}
Esempio n. 6
0
		public void TestTrimToSize ()
		{
			SortedList sl1 = new SortedList (24);

			sl1.TrimToSize ();
#if !NET_2_0 // no such expectation as it is broken in .NET 2.0
			Assert.AreEqual (icap, sl1.Capacity, "#1");
#endif

			for (int i = 72; i >= 0; i--)
				sl1.Add (100 + i, i);
			sl1.TrimToSize ();
#if !NET_2_0 // no such expectation as it is broken in .NET 2.0
			Assert.AreEqual (73, sl1.Capacity, "#2");
#endif
		}
Esempio n. 7
0
 /// <summary>
 /// Splits a string into words and returns a sorted list that contains the
 /// words and the number of times they appear in the original string.
 /// </summary>
 /// <param name="strInput">The string to split into words</param>
 /// <returns>A SortedList containing the words and their frequency</returns>
 private SortedList SplitString(string strInput)
 {
     SortedList sl=new SortedList();
     string[] words=strInput.Split(Delimiters);
     foreach(string s in words)
     {
         string word=s.Trim();
         if(word.Length>1)
         {
             if((ExistsInAllStopWords(word))||(IsNumericString(word)))
             {
                 continue;
             }
             try
             {
                 word=StemWord(word);
                 if(sl.ContainsKey(word))
                 {
                     //this word already exists. Just increment it's count
                     sl[word]=(int)sl[word]+1;
                 }
                 else
                 {
                     //The word does not exist, add it to the list with a count of 1
                     sl.Add(word, 1);
                 }
             }
             catch
             {
                 continue;
             }
         }
     }
     sl.TrimToSize();
     return sl;
 }
	public void TestTrimToSize() {
		SortedList sl1 = new SortedList(24);
		
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming empty list",icap,sl1.Capacity);
		
		for (int i = 72; i>=0; i--) sl1.Add(100+i,i);
		sl1.TrimToSize();
		AssertEquals("sl.TrimToSize: incorrect capacity after trimming a list",73,sl1.Capacity);
	}
Esempio n. 9
0
        public void TestTrimToSizeBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);
            //

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            String s1 = null;
            String s2 = null;
            String s3 = null;

            int i = 0;
            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(this);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);
            Assert.Null(s3);

            //   Testcase: add few key-val pairs

            // start adding elements
            for (i = 0; i < 32; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                sl2.Add(s1, s2);
            }

            //
            //  add one more elemnt now the capacity should be doubled
            //
            sl2.Add("key_32", "val_32");
            Assert.Equal(33, sl2.Count);

            //
            //   Testcase: now Remove few elements and TrimToSize
            //
            for (i = 0; i < 10; i++)
            {
                sl2.Remove("key_" + i.ToString()); // remove the current object
            }

            //   Testcase:  validate the Count and capacity
            Assert.Equal(23, sl2.Count);

            //  now TrimToSize
            sl2.TrimToSize();

            //  clear the list
            sl2.Clear();

            //  now TrimToSize
            sl2.TrimToSize();
        }
Esempio n. 10
0
 /// <summary>
 /// Populates the asset list control.
 /// </summary>
 /// <param name="listControl">The list control.</param>
 /// <param name="arrText">The arr text.</param>
 /// <param name="arrValue">The arr value.</param>
 public void PopulateAssetListControl(ListControl listControl, string[] arrText, string[] arrValue)
 {
     if(listControl != null && arrText != null)
     {
         SortedList sortedAssetNames = new SortedList();
         for(int intIndex = 0; intIndex < arrText.Length; intIndex++)
         {
             sortedAssetNames.Add(arrValue[intIndex], arrText[intIndex]);
         }
         sortedAssetNames.TrimToSize();
         listControl.DataSource = sortedAssetNames;
         listControl.DataValueField = "key";
         listControl.DataTextField = "value";
         listControl.DataBind();
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Loads the searche names.
 /// </summary>
 /// <param name="asset">The asset.</param>
 /// <param name="dropdownLstBx">The dropdown LST bx.</param>
 public void LoadSearcheNames(string asset, DropDownList dropdownLstBx)
 {
     const string SEARCHES = "Searches";
     const string SPLITSTRING = ";#";
     const string VALUE = "Value";
     const string SEARCHNAMEEXP = "%SEARCHNAME%";
     string strCmlQryAsstSrchMap = "<Where><Eq><FieldRef Name=\"Asset\" /><Value Type=\"Lookup\">" + asset + "</Value></Eq></Where>";
     string strViewFields = @"<FieldRef Name='Title'/><FieldRef Name='" + SEARCHES + "'/>";
     string strCmlQrySrchNames = "<Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + SEARCHNAMEEXP + "</Value></Eq></Where>";
     string strSearcheNames = string.Empty;
     string strSrchName = string.Empty;
     string strSrchValue = string.Empty;
     DataTable objDataTable = null;
     SortedList sortedLstSrchNames = new SortedList();
     try
     {
         objDataTable = ((MOSSServiceManager)objMossController).ReadList(SPContext.Current.Site.Url, ASSETSEARCHMAPPINGLIST, strCmlQryAsstSrchMap, strViewFields);
         if(objDataTable != null && objDataTable.Rows.Count > 0 && objDataTable.Rows[0][SEARCHES] != null)
         {
             strSearcheNames = (string)objDataTable.Rows[0][SEARCHES];
         }
         if(!string.IsNullOrEmpty(strSearcheNames))
         {
             string[] arrSearches = strSearcheNames.Split(SPLITSTRING.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
             for(int intSrchNamesCounter = 0; intSrchNamesCounter < arrSearches.Length; intSrchNamesCounter += 2)
             {
                 if(!string.IsNullOrEmpty(arrSearches[intSrchNamesCounter]))
                 {
                     strSrchName = arrSearches[intSrchNamesCounter];
                     strSrchValue = GetColValueFromDtRow(GetLookUpColumnRow(SEARCHES, strCmlQrySrchNames.Replace(SEARCHNAMEEXP,arrSearches[intSrchNamesCounter])), VALUE);
                     sortedLstSrchNames.Add(strSrchValue, strSrchName);
                 }
             }
         }
         sortedLstSrchNames.TrimToSize();
         dropdownLstBx.DataSource = sortedLstSrchNames;
         dropdownLstBx.DataTextField = "value";
         dropdownLstBx.DataValueField = "key";
         dropdownLstBx.DataBind();
         dropdownLstBx.Items.Insert(0, "---Select---");
     }
     finally
     {
         if(objDataTable != null)
         {
             objDataTable.Dispose();
         }
     }
 }