本文整理汇总了C#中SortedList.IndexOfKey方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.IndexOfKey方法的具体用法?C# SortedList.IndexOfKey怎么用?C# SortedList.IndexOfKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.IndexOfKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test01
public void Test01()
{
StringBuilder sblMsg = new StringBuilder(99);
SortedList sl2 = null;
Hashtable ht = null;
StringBuilder sbl3 = new StringBuilder(99);
StringBuilder sbl4 = new StringBuilder(99);
StringBuilder sblWork1 = new StringBuilder(99);
//
// Construct a hashtable with 3 elements in an unsorted order
//
ht = new Hashtable();
var k0 = new SortedListCtorTestClass("cde");
var k1 = new SortedListCtorTestClass("abc");
var k2 = new SortedListCtorTestClass("bcd");
ht.Add(k0, null);
ht.Add(k1, null);
ht.Add(k2, null);
//
// Constructor: Create a SortedList using the hashtable (dictionary) created
//
sl2 = new SortedList(ht);
// Verify that the SortedList is not null.
Assert.NotNull(sl2);
// Verify that the SortedList Count is right.
Assert.Equal(3, sl2.Count);
// Verify that the SortedList actually sorted the hashtable.
Assert.Equal(2, sl2.IndexOfKey(k0));
Assert.Equal(0, sl2.IndexOfKey(k1));
Assert.Equal(1, sl2.IndexOfKey(k2));
// Verify that the SortedList contains the right keys.
Assert.True(((SortedListCtorTestClass)sl2.GetKey(0)).ToString().Equals("abc"));
Assert.True(((SortedListCtorTestClass)sl2.GetKey(1)).ToString().Equals("bcd"));
Assert.True(((SortedListCtorTestClass)sl2.GetKey(2)).ToString().Equals("cde"));
ht = new Hashtable();
sl2 = new SortedList(ht);
Assert.Equal(0, sl2.Count);
}
示例2: RunSuite
public void RunSuite(Spec suite)
{
var mainSuiteExecutionPlan = new SortedList<string, List<Definition>>();
// var mainSuiteExecutionPlan = new Dictionary<string, List<Definition>>();
foreach (var spec in suite.Registry.ExecutableLookupTable)
{
mainSuiteExecutionPlan.Add(spec.Id, new List<Definition>());
List<Definition> executionPlan = mainSuiteExecutionPlan[spec.Id];
executionPlan.Add(spec);
AddBeforeEachs(spec, executionPlan);
AddAfterEach(spec, executionPlan);
}
foreach (var executionPlan in mainSuiteExecutionPlan)
{
foreach (var definition in executionPlan.Value)
{
if(definition.GetType() == typeof(GlobalHook))
{
var globalHook = (GlobalHook) definition;
if (globalHook.Kind == GlobalHookKind.BeforeAll)
{
if (globalHook.ExecutionStatus != ExecStatus.NotRun)
continue;
}
if (globalHook.Kind == GlobalHookKind.AfterAll)
{
var max = mainSuiteExecutionPlan.SelectMany(x => x.Value, (x, y) => new
{
x.Key,
val=y,
idx=mainSuiteExecutionPlan.IndexOfKey(x.Key)
})
.Where(x=>x.val==definition)
.Max(x=>x.idx);
var index = mainSuiteExecutionPlan.IndexOfKey(executionPlan.Key);
if (index<max)
{
continue;
}
}
}
SafeExecute(definition);
}
}
}
示例3: ContainsNearbyAlmostDuplicate
public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t)
{
if (k <= 0 || t < 0) return false;
var index = new SortedList<int, object>();
for (int i = 0; i < nums.Length; ++i)
{
if (index.ContainsKey(nums[i]))
{
return true;
}
index.Add(nums[i], null);
var j = index.IndexOfKey(nums[i]);
if (j > 0 && (long)nums[i] - index.Keys[j - 1] <= t)
{
return true;
}
if (j < index.Count - 1 && (long)index.Keys[j + 1] - nums[i] <= t)
{
return true;
}
if (index.Count > k)
{
index.Remove(nums[i - k]);
}
}
return false;
}
示例4: Filter
public void Filter(string queryText)
{
SortedList<int, List<AutoSuggestModel.OptionValue>> l_sortedOption = new SortedList<int, List<AutoSuggestModel.OptionValue>>();
foreach (AutoSuggestModel.OptionValue l_item in mOptionValueDB)
{
string l_target = l_item.CodeName + l_item.Description;
string l_upperTarget = l_target.ToUpper();
string l_upperSource = queryText.ToUpper();
int l_index = l_upperTarget.IndexOf(l_upperSource);
if (l_index >= 0)
{
int l_sortedIndex = l_sortedOption.IndexOfKey(l_index);
if (l_sortedIndex == -1)
{
l_sortedOption[l_index] = new List<AutoSuggestModel.OptionValue>();
}
l_sortedOption[l_index].Add(l_item);
}
}
mOptionValueList = new List<AutoSuggestModel.OptionValue>();
foreach (KeyValuePair<int, List<AutoSuggestModel.OptionValue>> l_items in l_sortedOption)
{
foreach (AutoSuggestModel.OptionValue l_item in l_items.Value)
{
mOptionValueList.Add(l_item);
}
}
}
示例5: Filter
public void Filter(string queryText)
{
SortedList<int, List<AutoSuggestModel.Instrument>> l_sortedInstrument = new SortedList<int, List<AutoSuggestModel.Instrument>>();
foreach (AutoSuggestModel.Instrument l_item in mInstrumentDB)
{
string l_target = l_item.CodeName + l_item.Description;
string l_upperTarget = l_target.ToUpper();
string l_upperSource = queryText.ToUpper();
int l_index = l_upperTarget.IndexOf(l_upperSource);
if (l_index >= 0)
{
int l_sortedIndex = l_sortedInstrument.IndexOfKey(l_index);
if (l_sortedIndex == -1)
{
l_sortedInstrument[l_index] = new List<AutoSuggestModel.Instrument>();
}
l_sortedInstrument[l_index].Add(l_item);
}
}
//if (mInstrumentList != null)
//{
// mInstrumentList.Clear();
//}
mInstrumentList = new List<AutoSuggestModel.Instrument>();
foreach (KeyValuePair<int, List<AutoSuggestModel.Instrument>> l_items in l_sortedInstrument)
{
foreach (AutoSuggestModel.Instrument l_item in l_items.Value)
{
mInstrumentList.Add(l_item);
}
}
}
示例6: Main
static void Main(String[] args)
{
// Java has more suitable tree set features in this case
Console.SetIn(new StreamReader(Console.OpenStandardInput((int) Math.Pow(10, 20))));
int numCases = int.Parse(Console.ReadLine());
for (int i = 0; i < numCases; i++)
{
string[] input = Console.ReadLine().Split(' ');
int len = int.Parse(input[0]);
ulong mod = ulong.Parse(input[1]);
string[] array = Console.ReadLine().Split(' ');
ulong[] prefix = new ulong[len];
ulong curr = 0;
for (int j = 0; j < array.Length; j++)
{
curr = (ulong.Parse(array[j]) % mod + curr) % mod;
prefix[j] = curr;
}
SortedList<ulong, string> cache = new SortedList<ulong, string>();
ulong ret = 0;
for(int k = 0; k < len; k++)
{
ret = Math.Max(ret, prefix[k]);
if (!cache.ContainsKey(prefix[k]))
{
cache.Add(prefix[k], "");
}
int next = cache.IndexOfKey(prefix[k]) + 1;
if (next < cache.Count)
{
ret = Math.Max(ret, prefix[k] - cache.Keys[next] + mod);
}
}
Console.WriteLine(ret);
}
}
示例7: Main
static void Main()
{
/* Write a program that finds the most frequent number in an array. Example:
* {4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3} 4 (5 times) */
Console.Write("Enter array lenght (or 0 for array autogeneration): ");
int n = int.Parse(Console.ReadLine());
int[] arr;
if (n == 0)
{
// random generated array
Random rnd = new Random();
n = rnd.Next(20, 30);
arr = new int[n];
Console.WriteLine("Generated N is: {0}", n);
Console.WriteLine("Generated array is:");
for (int i = 0; i < n; i++)
{
arr[i] = rnd.Next(10);
Console.Write("{0,2}", arr[i]);
}
Console.WriteLine();
}
else
{
// user defined and fileld array
arr = new int[n];
for (int i = 0; i < n; i++)
{
Console.Write("Element {0}: ", i + 1);
arr[i] = int.Parse(Console.ReadLine());
}
}
// input is done
SortedList count = new SortedList(); // I use SortedList to automate some work. "Index" field is value of element, "value" element is count of this elements
for (int i = 0; i < arr.Length; i++) // let's walk in array - form start to end
{
int index = count.IndexOfKey(arr[i]); // is this element already in sorted list?
if (index < 0)
count.Add(arr[i], 1); // no, this element is not in the list. Add them, and place "1" at count position
else
count[arr[i]] = (int)count[arr[i]]+1 ; // yes, element is in the list. Add 1 to count position.
}
//count of all elements is done
int maxPos = 0; // now we must find which element have biggest count (in "value" fielt in sorted array)
int maxValue = (int)count.GetByIndex(0); // get first element for starting
for (int i = 1; i < count.Count; i++)
{
if (maxValue < (int)count.GetByIndex(i))
{
maxPos = i;
maxValue = (int)count.GetByIndex(i);
}
}
//finding the most frequent element is done
Console.WriteLine("Value {0} is most frequent - {1} times",count.GetKey(maxPos),maxValue) ;
for (int i = 0; i < n; i++)
{
if (arr[i] == (int)count.GetKey(maxPos))
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("{0,2}", arr[i]);
Console.ForegroundColor = ConsoleColor.Gray;
}
Console.WriteLine();
}
示例8: MakeCanonicalString
public string MakeCanonicalString(string verb, string resource,
SortedList<string, string> headers, string expires)
{
StringBuilder buf = new StringBuilder();
buf.Append(verb);
buf.Append("\n");
SortedList<string,string> interestingHeaders = new SortedList<string,string>();
if (headers != null)
{
foreach (string key in headers.Keys)
{
string lk = key.ToLower();
if (lk.Equals("content-type") ||
lk.Equals("content-md5") ||
lk.Equals("date") ||
lk.StartsWith("x-amz-"))
{
interestingHeaders.Add(lk, headers[key]);
}
}
}
if (interestingHeaders.ContainsKey("x-amz-date"))
{
interestingHeaders.Add("date", "");
}
// if the expires is non-null, use that for the date field. this
// trumps the x-amz-date behavior.
if (expires != null)
{
interestingHeaders.Add("date", expires);
}
// these headers require that we still put a new line after them,
// even if they don't exist.
{
string[] newlineHeaders = { "content-type", "content-md5" };
foreach (string header in newlineHeaders)
{
if (interestingHeaders.IndexOfKey(header) == -1)
{
interestingHeaders.Add(header, "");
}
}
}
// Finally, add all the interesting headers (i.e.: all that startwith x-amz- ;-))
foreach (string key in interestingHeaders.Keys)
{
if (key.StartsWith("x-amz-"))
{
buf.Append(key).Append(":").Append((interestingHeaders[key] as string).Trim());
}
else
{
buf.Append(interestingHeaders[key]);
}
buf.Append("\n");
}
// Do not include the query string parameters
int queryIndex = resource.IndexOf('?');
string path = queryIndex == -1 ? resource : resource.Substring(0, queryIndex);
if (IsUS)
buf.Append(path);
else
buf.Append("/" + Bucket + path);
Regex aclQueryStringRegEx = new Regex(".*[&?]acl($|=|&).*");
Regex torrentQueryStringRegEx = new Regex(".*[&?]torrent($|=|&).*");
if (aclQueryStringRegEx.IsMatch(resource))
{
buf.Append("?acl");
}
else if (torrentQueryStringRegEx.IsMatch(resource))
{
buf.Append("?torrent");
}
return buf.ToString();
}
示例9: maxSlidingWindow02
//.........这里部分代码省略.........
*
* Therefore, return the max sliding window as [3,3,5,5,6,7].
*
* Note:
* You may assume k is always valid, ie: 1 ≤ k ≤ input array's size for non-empty
* array.
*
* Follow up:
* Could you solve it in linear time?
*
* How about using a data structure such as deque (double-ended queue)?
* The queue size need not be the same as the window’s size.
* Remove redundant elements and the queue should store only elements that need to be
* considered.
*
**********************************************************************************/
/*
* source code from blog:
* https://github.com/haoel/leetcode/commit/74d83796aa48cc55d7995b1f9e61db40759204bb
*
* comment from julia:
* 1. Find C++ multiset analog in C#:
* read the webpage:
* 1. https://msdn.microsoft.com/en-us/library/6tc79sx1
* understand C# choices for container classes
* 2. http://www.ccplusplus.com/2014/01/stl-multiset-example-c.html
* Go through C++ multiset and try to understand the author's implementation, things I
* should learn if I work with the C++ code.
* Based on the review of the above two web pages, my idea is to use C# SortedList<int>
* to replace the multiset.
*
* SortedList coding example:
* https://msdn.microsoft.com/en-us/library/e7a8xew6
* http://www.c-sharpcorner.com/UploadFile/c25b6d/working-on-sortedlist-using-C-Sharp/
*
* another example about IComparer:
* https://github.com/jianminchen/MaxBoxes/blob/master/Program.cs
*
* http://www.codeproject.com/Articles/42839/Sorting-Lists-using-IComparable-and-IComparer-Inte
*
*/
//O(nlog(k)
/* julia's comment: implemented in C++, need to convert it to C# code
* Read the code and try to expand the knowledge with C++/ C#
*
public static int[] maxSlidingWindow02(int[] nums, int k) {
int[] result;
//using multiset for collecting the window data (O(nlog(k) time complexity)
multiset<int> w;
for(int i=0; i<nums.Length; i++) {
//remove the left item which leaves window
if (i >= k) {
w.erase(w.find(nums[i-k]));
}
//insert the right itme which enter the window
w.insert(nums[i]);
if (i>=k-1) {
result.push_back(*w.rbegin());
}
}
return result;
}
* */
/*
* julia's comment: try to figure out how to use SortedList here.
* come back to revisit later.
*/
public static int[] maxSlidingWindow02(int[] nums, int k)
{
int len = nums.Length;
if(k==0 || k>len) return nums;
int[] result = new int[len-k+1];
//using multiset for collecting the window data (O(nlog(k) time complexity)
SortedList<int, int> w = new SortedList<int, int>();
for (int i = 0; i < nums.Length; i++)
{
//remove the left item which leaves window
if (i >= k)
{
w.Remove(w.IndexOfValue(nums[i - k])); // ?
}
//insert the right itme which enter the window
w.Add(i, nums[i]); // ?
int index = i-k+1;
if (i >= k - 1)
{
result[index] = w.IndexOfKey(0); //?
}
}
return result;
}
示例10: ConvertToSubDivisionMesh
public SubDivisionMesh[] ConvertToSubDivisionMesh()
{
List<SubDivisionMesh> importedMeshes = new List<SubDivisionMesh>();
foreach (var group in this.Groups)
{
List<int[]> faces = new List<int[]>();
SortedList<int, Point> sortedIndexPointList = new SortedList<int, Point>();
//create the used points list
foreach (var face in group.Faces)
{
foreach (var vertex in face.VertexArray)
sortedIndexPointList[vertex] = this.Vertices[vertex];
}
//get the indices from the used point list and add face
foreach (var face in group.Faces)
{
int[] newVertexArray = new int[face.VertexArray.Length];
for (int i = 0; i < face.VertexArray.Length; ++i)
newVertexArray[i] = sortedIndexPointList.IndexOfKey(face.VertexArray[i]);
faces.Add(newVertexArray);
}
if (faces.Count == 0)
continue;
Point[] usedPointsList = new Point[sortedIndexPointList.Count];
sortedIndexPointList.Values.CopyTo(usedPointsList, 0);
try
{
importedMeshes.Add(new SubDivisionMesh(usedPointsList, faces.ToArray(), 0, true));
}
catch (System.InvalidOperationException)
{
}
}
return importedMeshes.ToArray();
}
示例11: PopulateMeshesEbo
public void PopulateMeshesEbo(GameObject[] gs, Dictionary<string, Material[]> mats)
{
int vertexCount;
Vector3[] tvertices;
Vector2[] tuvs;
int[] triangles;
using (var s = new MemoryStream(EboBuffer))
using (var br = new BinaryReader(s))
{
// File is prefixed with face count, times 3 for vertices
vertexCount = br.ReadUInt16() * 3;
SortedList<int, Vector3> vertices = new SortedList<int, Vector3>();
SortedList<int, Vector2> uvs = new SortedList<int, Vector2>();
triangles = new int[vertexCount];
// Enumerate vertices
for (int i = 0; i < vertexCount; i++)
{
try
{
switch ((int) br.ReadByte())
{
case (0):
int bufferIndex = (int) br.ReadUInt32();
triangles[i] = vertices.IndexOfKey(bufferIndex);
break;
case (64):
bufferIndex = (int) br.ReadUInt32();
vertices.Add(i, vertices[bufferIndex]);
uvs.Add(i, new Vector2(br.ReadSingle(), br.ReadSingle()));
triangles[i] = vertices.IndexOfKey(i);
break;
case (128):
throw new EndOfStreamException("Unexpectedly hit end of EBO stream");
case (255):
vertices.Add(i, new Vector3(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()));
uvs.Add(i, new Vector2(br.ReadSingle(), br.ReadSingle()));
triangles[i] = vertices.IndexOfKey(i);
break;
}
}
catch (Exception)
{
Debug.Log("Failure with : "+ vertexCount);
throw;
}
}
tvertices = vertices.Values.ToArray();
tuvs = uvs.Values.ToArray();
}
Mesh m = (gs[0].GetComponent(typeof(MeshFilter)) as MeshFilter).mesh;
// RPL HACK FIX
for (int i = 0; i < tvertices.Length; i++)
{
Vector3 t = new Vector3(-tvertices[i].x, tvertices[i].z + 600, -tvertices[i].y);
tvertices[i] = t;
}
for (int i = 0; i < triangles.Length; i += 3)
{
int t0 = triangles[i];
int t1 = triangles[i + 1];
int t2 = triangles[i + 2];
triangles[i] = t0;
triangles[i + 1] = t2;
triangles[i + 2] = t1;
}
// END HACK
if (tvertices.Length > 65000)
{
Debug.LogErrorFormat("GameObject {0} had too many vertices", gs[0].name);
}
m.vertices = tvertices;
m.uv = tuvs;
m.triangles = triangles;
// m.RecalculateNormals();
if (mats != null)
{
GroupData gd = _objects[0].Groups[0];
if (gd.MaterialName == null)
{
Dictionary<string, Material[]>.KeyCollection.Enumerator keys = mats.Keys.GetEnumerator();
keys.MoveNext();
gd.MaterialName = keys.Current;
}
Renderer renderer = gs[0].GetComponent<Renderer>();
renderer.materials = mats[gd.MaterialName];
}
}
示例12: TestGetKeyBasic
public void TestGetKeyBasic()
{
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;
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);
// Testcase: GetKey - key at index 0 , ArgExc expected
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
sl2.GetKey(0);
});
// Testcase: GetKey - null val, should pass
sl2["first key"] = (string)null;
Assert.Equal(1, sl2.Count);
// Testcase: vanila Set
sl2.Clear();
// Testcase: add key-val pairs
for (i = 0; i < 50; 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);
}
//
// now get their keys using GetKey
//
for (i = 0; i < 50; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_");
sblMsg.Append(i);
s1 = sblMsg.ToString();
Assert.True(((string)sl2.GetKey(sl2.IndexOfKey(s1))).Equals(s1));
}
Assert.Equal(50, sl2.Count);
}
示例13: TestIndexOfKeyBasic
public void TestIndexOfKeyBasic()
{
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;
string s4 = null;
int i = 0;
int j = 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);
// boundary
// null key
Assert.Throws<ArgumentNullException>(() =>
{
j = sl2.IndexOfKey((string)null);
}
);
// invalid key
j = sl2.IndexOfKey("No_Such_Key");
Assert.Equal(-1, j);
// Testcase: add few key-val pairs
for (i = 0; i < 100; 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);
}
//
// Testcase: test IndexOfKey
//
for (i = 0; i < sl2.Count; i++)
{
sblMsg.Length = 0;
sblMsg.Append("key_"); //key
sblMsg.Append(i);
s1 = sblMsg.ToString();
sblMsg.Length = 0;
sblMsg.Append("val_"); //value
sblMsg.Append(i);
s2 = sblMsg.ToString();
// now use IndexOfKey and IndexOfVal to obtain the same object through GetByIndex and check
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1)); //Get the index of this key and then get object
s4 = (string)sl2.GetByIndex(sl2.IndexOfValue(s2)); //Get the index of this val and then get object
Assert.True(s3.Equals(s4));
// now Get using the index obtained thru IndexOfKey () and compare it with s2
s3 = (string)sl2.GetByIndex(sl2.IndexOfKey(s1));
Assert.True(s3.Equals(s2));
}
//
// Remove a key and then check
//
sblMsg.Length = 0;
sblMsg.Append("key_50");
s1 = sblMsg.ToString();
sl2.Remove(s1); //removes "Key_50"
j = sl2.IndexOfKey(s1);
Assert.Equal(-1, j);
}
示例14: runTest
public virtual bool runTest()
{
Console.Error.WriteLine( "Co4331IndexOfKey runTest() started." );
String strLoc="Loc_000oo";
StringBuilder sblMsg = new StringBuilder( 99 );
int iCountErrors = 0;
int iCountTestcases = 0;
SortedList sl2 = null;
StringBuilder sbl3 = new StringBuilder( 99 );
StringBuilder sbl4 = new StringBuilder( 99 );
StringBuilder sblWork1 = new StringBuilder( 99 );
String str5 = null;
String str6 = null;
String str7 = null;
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
int[] in4a = new int[9];
int nCapacity = 100;
bool bol = false;
int i = 0;
int j = 0;
try
{
LABEL_860_GENERAL:
do
{
strLoc="100cc";
iCountTestcases++;
sl2 = new SortedList( this );
iCountTestcases++;
if ( sl2 == null )
{
Console.WriteLine( strTest+ "E_101" );
Console.WriteLine( strTest+ "SortedList creation failure" );
++iCountErrors;
break;
}
iCountTestcases++;
if ( sl2.Count != 0 )
{
Console.WriteLine( strTest+ "E_102" );
Console.WriteLine( strTest+ "New SortedList is not empty" );
++iCountErrors;
}
iCountTestcases++;
try
{
j = sl2.IndexOfKey((String)null);
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_23dg! - ArgExc expected..." );
}
catch (ArgumentException aexc) {}
iCountTestcases++;
j = sl2.IndexOfKey("No_Such_Key");
if (j != -1)
{
++iCountErrors;
Console.Error.WriteLine( "POINTTOBREAK: Error Err_658d! - should return -1..." );
Console.Error.WriteLine( "returned: " + j );
}
strLoc="Loc_141aa";
for (i=0; i<100; i++)
{
++iCountTestcases;
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);
}
strLoc="Loc_151aa";
for (i=0; i < sl2.Count ; 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();
++iCountTestcases;
s3 = (String) sl2.GetByIndex(sl2.IndexOfKey(s1)) ;
s4 = (String) sl2.GetByIndex(sl2.IndexOfValue(s2)) ;
strLoc="Loc_161aa";
if (!s3.Equals (s4))
{
++iCountErrors;
sblMsg.Length = 0 ;
sblMsg.Append( "POINTTOBREAK: Error Err_1032bc! - s4 == " );
sblMsg.Append( s4 );
sblMsg.Append( "; s3 == " );
sblMsg.Append( s3 );
Console.Error.WriteLine( sblMsg.ToString() );
//.........这里部分代码省略.........
示例15: format
//return formatted input code for the appropriate language
public string format(string input, string language)
{
//read language-specific tokens/keywords and HTML tags from the file we want
StreamReader langfile = new StreamReader("C:\\Users\\Zimmy\\Documents\\Snippit\\Languages\\" + language + ".txt");
//sorted lists containing each keyword or token to format and their corresponding HTML tags
SortedList<string, string> openers = new SortedList<string, string>();
SortedList<string, string> closers = new SortedList<string, string>();
string[] cols = new string[3]; //holds each value for each row of data
char[] delimiters = {'\t'}; //each value is separated by tab
string line; //a line of text that is read in
//read in each line, placing the keyword/token and
//it's opening or closing HTML tag into the appropriate SortedList
while((line = langfile.ReadLine()) != null)
{
cols = line.Split(delimiters);
openers.Add(cols[0], cols[1]);
closers.Add(cols[0], cols[2]);
}
//close the StreamReader
langfile.Close();
//read language-specific tokens/keywords and HTML tags from the file we want
StreamReader delfile = new StreamReader("C:\\Users\\Zimmy\\Documents\\Snippit\\Languages\\" + language + "dels.txt");
string del; //delimiter that is read in
string dels = @""; //list of delimiters that breaks the code into tokens
//get each delimiter from the delimiter file and add it to the list
del = delfile.ReadLine();
dels += "(" + del.ToString() + ")";
while ((del = delfile.ReadLine()) != null)
{
dels += "|(" + del.ToString() + ")";
}
//close the StreamReader
delfile.Close();
string separators = @"(\"")|( )|(&)|(%)|($)|(#)|(!)|(\-)|(//)|(/\*)|(\')|(\*\/)|(\()|(\))|(\*)|(,)|(\.)|(:)|(;)|(\?)|(@)|(\[)|(\])|(^)|(`)|(\{)|(\|)|(\})|(~)|(\+)|(<)|(=)|(\n)|(\t)|(>)";
//string[] tokens = System.Text.RegularExpressions.Regex.Split(input, separators);
string[] tokens = System.Text.RegularExpressions.Regex.Split(input, dels);
string fcode = "";
foreach (string token in tokens)
{
if (openers.ContainsKey(token))
{
fcode += openers.ElementAt(openers.IndexOfKey(token)).Value + token
+ closers.ElementAt(closers.IndexOfKey(token)).Value;
}
else
{
fcode += token;
}
}
return fcode;
}