本文整理汇总了C#中System.Collections.SortedList.SetByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.SetByIndex方法的具体用法?C# SortedList.SetByIndex怎么用?C# SortedList.SetByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.SortedList
的用法示例。
在下文中一共展示了SortedList.SetByIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSetByIndex
public void TestSetByIndex ()
{
SortedList sl1 = new SortedList (24);
for (int i = 49; i >= 0; i--) sl1.Add (100 + i, i);
try {
sl1.SetByIndex (-1, 77);
Assert.Fail ("#A");
} catch (ArgumentOutOfRangeException) {
}
try {
sl1.SetByIndex (100, 88);
Assert.Fail ("#B");
} catch (ArgumentOutOfRangeException) {
}
for (int i = 5; i < 25; i++)
sl1.SetByIndex (i, -1);
for (int i = 0; i < 5; i++)
Assert.AreEqual (i, sl1 [100 + i], "#C1");
for (int i = 5; i < 25; i++)
Assert.AreEqual (-1, sl1 [100 + i], "#C2");
for (int i = 25; i < 50; i++)
Assert.AreEqual (i, sl1 [100 + i], "#C3");
}
示例2: LeaveFunction
/* record leaving of a function */
void LeaveFunction(SortedList functions, int functionId)
{
int index = functions.IndexOfKey(functionId);
if(index != -1)
{
int newValue = (int)functions.GetByIndex(index) - 1;
if(newValue <= 0)
{
functions.RemoveAt(index);
}
else
{
functions.SetByIndex(index, newValue);
}
}
}
示例3: btn_p5_termList_Click
private void btn_p5_termList_Click(object sender, EventArgs e)
{
string line = "", Term = "", POS = "", DocNO_tag = ""; //資料列, 詞彙, 詞性標記
int index = 0, value = 0, pt = 0;
StringBuilder SB5 = new StringBuilder();
List<string> temp_list = new List<string>();
SortedList Term_DF_slist = new SortedList(); //整個文件集之"詞彙列表" 及詞會出現次數 DF
List<KeyValuePair<string, int>> Doctermtf_list = new List<KeyValuePair<string, int>>(); //-記錄每篇文件出現之詞彙集詞頻 -
// if ((openFileDialog1.ShowDialog() == DialogResult.OK) && ((txt_p5_fileName.Text = openFileDialog1.FileName) != null)) //開啟Window開啟檔案管理對話視窗
//{
using (StreamReader myTextFileReader = new StreamReader(@txt_p5_fileName.Text, Encoding.Default))
{
SortedList DocTermTF_slist = new SortedList(); //暫存每篇文件之"詞彙列表" 及詞會出現次數 TF
// ---- 處理文件集中的每一篇文件與文件中的所有詞彙 (詞彙列表 ,計算 TF , 計算 DF)----
while (myTextFileReader.EndOfStream != true) //非資料檔案結尾
{
line = (myTextFileReader.ReadLine().Trim()) + " ";
// ----- 若為一篇新文件的開始
if (line.Contains("<DocNo>"))
{
TotalDocNum++;
DocNO_tag = line.Substring(line.IndexOf("<DocNo>"), ((line.IndexOf("</DocNo>") + 8) - line.IndexOf("<DocNo>")));
//line = line.Remove(line.IndexOf("<DocNo>"), ((line.IndexOf("</DocNo>") + 8) - line.IndexOf("<DocNo>")));
// -------------------------------------- 計算詞彙之 DF ---------------------------------------------------
if (temp_list.Count != 0)
{
foreach (string str in temp_list) //複製與計算出現在每一文件之詞彙的"DF"
{
//-- 計算詞彙之 DF --
if ((index = Term_DF_slist.IndexOfKey(str)) != -1) //在termList中找尋特定的Term,若Term不存在怎則傳回-1
{
value = (int)Term_DF_slist.GetByIndex(index);
value++; //該term存在,則term的出現次數加1
Term_DF_slist.SetByIndex(index, value);
}
else
Term_DF_slist.Add(str, 1); //該詞彙(term)不存在於termList中,則加入該新詞彙(term)
}
temp_list.Clear(); //清除紀錄每一篇文件內之詞彙的SortedList
}
//--------------記錄每篇文件出現之詞彙集詞頻 -Doctermtf_list -----------
if (DocTermTF_slist.Count != 0)
{
foreach (DictionaryEntry obj in DocTermTF_slist)
{
KeyValuePair<string, int> x = new KeyValuePair<string, int>((string)obj.Key, (int)obj.Value);
Doctermtf_list.Add(x);
}
DocTermTF_slist.Clear();
}
KeyValuePair<string, int> x1 = new KeyValuePair<string, int>(DocNO_tag, 0); //加入文件編號標籤
Doctermtf_list.Add(x1);
continue;
}
// ---------------------------------- 記錄並產生整個文件集之"詞彙列表" 及詞會出現次數 TF------------------------------------------
string[] terms = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string str in terms)
{
if (str.IndexOf("(") == -1 || str.IndexOf(")") == -1) //找不到'()',就不處理/
continue;
Term = str.Substring(0, str.IndexOf("("));
POS = str.Substring(str.IndexOf("("));
if (Term.Length != 0) //若有"詞彙"存在
{
//--- 記錄每篇文件之詞彙及其出現次數 ---
if ((pt = DocTermTF_slist.IndexOfKey((Term + POS))) != -1)
{
value = (int)DocTermTF_slist.GetByIndex(pt);
value++; //該term存在,則term的出現次數加1
DocTermTF_slist.SetByIndex(pt, value); //紀錄整個文件集之"詞彙列表" 及詞會出現次數 TF
}
else
DocTermTF_slist.Add((Term + POS), 1); //該詞彙(term)不存在於termList中,則加入該新詞彙(term)
// --- 紀錄出現在每一文件之詞彙有哪些,用於計算詞彙之DF
if ((index = temp_list.IndexOf((Term + POS))) == -1)
temp_list.Add((Term + POS)); //紀錄出現在每一文件之詞彙有哪些,用於計算詞彙之DF
}
}
//TF詞頻比較
if (Doctermtf_list.Count != 0)
{
foreach (KeyValuePair<string, int> kvp in Doctermtf_list)
{
//KeyValuePair<string, int> x = new KeyValuePair<string, int>((string)obj.Key, (int)obj.Value);
}
}
}//End of while每一文件
// ----記錄並計算最後一篇文件之詞彙 DF --------
if (temp_list.Count != 0)
{
foreach (string str in temp_list) //複製與計算出現在每一文件之詞彙的"DF"
{
//.........这里部分代码省略.........
示例4: EnterFunction
/* record call to a function */
void EnterFunction(SortedList functions, int functionId)
{
int index = functions.IndexOfKey(functionId);
if(index == -1)
{
functions.Add(functionId, 1);
}
else
{
/* if in the list, add 1 to its counter (need to keep keys unique) */
functions.SetByIndex(index, 1 + (int)functions.GetByIndex(index));
}
}
示例5: TestSetByIndex
public void TestSetByIndex() {
SortedList sl1 = new SortedList(24);
for (int i = 49; i>=0; i--) sl1.Add(100+i,i);
try {
sl1.SetByIndex(-1,77);
Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
} catch (ArgumentOutOfRangeException) {}
try {
sl1.SetByIndex(100,88);
Fail("sl.SetByIndex: ArgumentOutOfRangeException not caught, when key is out of range");
} catch (ArgumentOutOfRangeException) {}
for(int i=5; i<25; i++) sl1.SetByIndex(i,-1);
for(int i=0; i<5; i++)
AssertEquals("sl.SetByIndex: set failed(1)",sl1[100+i],i);
for(int i=5; i<25; i++)
AssertEquals("sl.SetByIndex: set failed(2)",sl1[100+i],-1);
for(int i=25; i<50; i++)
AssertEquals("sl.SetByIndex: set failed(3)",sl1[100+i],i);
}