本文整理汇总了C#中SortedDictionary类的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary类的具体用法?C# SortedDictionary怎么用?C# SortedDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortedDictionary类属于命名空间,在下文中一共展示了SortedDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetArtists
private static SortedDictionary<string, int> GetArtists(XmlNode rootNode)
{
var artists = new SortedDictionary<string, int>();
if (rootNode == null)
{
throw new ArgumentNullException("rootNode" + "is empty");
}
foreach (var artistName in from XmlNode node in rootNode.ChildNodes
select node["artist"] into xmlElement
where xmlElement != null
select xmlElement.InnerText)
{
if (artists.ContainsKey(artistName))
{
artists[artistName]++;
}
else
{
artists.Add(artistName, 1);
}
}
return artists;
}
示例2: SqlCallProcedureInfo
public SqlCallProcedureInfo(MethodInfo method, ISerializationTypeInfoProvider typeInfoProvider)
{
if (method == null) {
throw new ArgumentNullException("method");
}
if (typeInfoProvider == null) {
throw new ArgumentNullException("typeInfoProvider");
}
SqlProcAttribute procedure = GetSqlProcAttribute(method);
schemaName = procedure.SchemaName;
name = procedure.Name;
timeout = procedure.Timeout;
deserializeReturnNullOnEmptyReader = procedure.DeserializeReturnNullOnEmptyReader;
deserializeRowLimit = procedure.DeserializeRowLimit;
deserializeCallConstructor = procedure.DeserializeCallConstructor;
SortedDictionary<int, SqlCallParameterInfo> sortedParams = new SortedDictionary<int, SqlCallParameterInfo>();
outArgCount = 0;
foreach (ParameterInfo parameterInfo in method.GetParameters()) {
if ((parameterInfo.GetCustomAttributes(typeof(SqlNameTableAttribute), true).Length > 0) || (typeof(XmlNameTable).IsAssignableFrom(parameterInfo.ParameterType))) {
if (xmlNameTableParameter == null) {
xmlNameTableParameter = parameterInfo;
}
} else {
SqlCallParameterInfo sqlParameterInfo = new SqlCallParameterInfo(parameterInfo, typeInfoProvider, ref outArgCount);
sortedParams.Add(parameterInfo.Position, sqlParameterInfo);
}
}
parameters = sortedParams.Select(p => p.Value).ToArray();
returnTypeInfo = typeInfoProvider.GetSerializationTypeInfo(method.ReturnType);
if ((procedure.UseReturnValue != SqlReturnValue.Auto) || (method.ReturnType != typeof(void))) {
useReturnValue = (procedure.UseReturnValue == SqlReturnValue.ReturnValue) || ((procedure.UseReturnValue == SqlReturnValue.Auto) && (typeInfoProvider.TypeMappingProvider.GetMapping(method.ReturnType).DbType == SqlDbType.Int));
}
}
示例3: Search
public static string[] Search(String[] token, String txt, out Byte distance)
{
if (txt.Length > 0)
{
Byte bestKey = 255;
SortedDictionary<Byte, List<string>> matches = new SortedDictionary<byte, List<string>>();
Docking.Tools.ITextMetric tm = new Docking.Tools.Levenshtein(50);
foreach(string s in token)
{
Byte d = tm.distance(txt, s);
if (d <= bestKey) // ignore worse matches as previously found
{
bestKey = d;
List<string> values;
if (!matches.TryGetValue(d, out values))
{
values = new List<string>();
matches.Add(d, values);
}
if (!values.Contains(s))
values.Add(s);
}
}
if (matches.Count > 0)
{
List<string> result = matches[bestKey];
distance = bestKey;
return result.ToArray();
}
}
distance = 0;
return null;
}
示例4: ReadStudentsInfoFromFile
private static void ReadStudentsInfoFromFile(string filePath, SortedDictionary<string, SortedSet<Student>> courses)
{
using (StreamReader reader = new StreamReader(filePath))
{
string line = reader.ReadLine();
while (line != string.Empty && line != null)
{
string[] data = line.Split('|');
string firstName = data[0].Trim();
string lastName = data[1].Trim();
string courseName = data[2].Trim();
if (courses.ContainsKey(courseName))
{
courses[courseName].Add(new Student(firstName, lastName));
}
else
{
courses[courseName] = new SortedSet<Student>();
courses[courseName].Add(new Student(firstName, lastName));
}
line = reader.ReadLine();
}
}
}
示例5: FindReplaceForm
public FindReplaceForm()
{
InitializeComponent();
m_Selection = new ObjectId[0];
m_PosList = new SortedDictionary<string, List<ObjectId>>();
m_CountList = new SortedDictionary<string, List<ObjectId>>();
m_DiameterList = new SortedDictionary<string, List<ObjectId>>();
m_SpacingList = new SortedDictionary<string, List<ObjectId>>();
m_NoteList = new SortedDictionary<string, List<ObjectId>>();
m_MultiplierList = new SortedDictionary<int, List<ObjectId>>();
m_ShapeList = new SortedDictionary<string, List<ObjectId>>();
m_PosProperties = new Dictionary<string, SelectedPos>();
m_FindShape = string.Empty;
m_ReplaceShape = string.Empty;
m_FindFields = 0;
m_ReplaceFields = 0;
psvFind.BackColor = DWGUtility.ModelBackgroundColor();
psvReplace.BackColor = DWGUtility.ModelBackgroundColor();
init = false;
}
示例6: Process
public void Process(RayCollection rayBuffer)
{
var topLevelHits = new SortedDictionary<uint, List<Tuple<Ray, PrimitiveHit>>>();
rtDevice.TraceBuffer(rayBuffer);
for (int index = 0; index < rayBuffer.rayHits.Length; index++)
{
if (!topLevelHits.ContainsKey(rayBuffer.rayHits[index].PrimitiveId))
{
topLevelHits.Add(rayBuffer.rayHits[index].PrimitiveId, new List<Tuple<Ray, PrimitiveHit>>());
}
topLevelHits[rayBuffer.rayHits[index].PrimitiveId].Add(new Tuple<Ray, PrimitiveHit>(rayBuffer.RaysInfo[index], rayBuffer.rayHits[index]));
}
//Process Top Level Hits
foreach (var topLevelHit in topLevelHits)
{
var prim = GetMesh(topLevelHit.Key);
var rays = topLevelHit.Value.Select(item => item.Item1).ToArray();
var buffer = new RayCollection(rays.Length);
rtDevice.SetData(prim.BottomLevelBVH);
rtDevice.TraceBuffer(buffer);
for (int index = 0; index < buffer.rayHits.Length; index++)
{
rayBuffer.UpdateHit(buffer.RaysInfo[index].Id, ref buffer.rayHits[index]);
}
}
}
示例7: cycle_check
public string cycle_check(SortedDictionary<char, char> cycle)
{
cycle_str = "A";
cycle_key = 'A';
cycle_value = cycle['A'];
cycle_length = "";
while (cycle.Count != 1)
{
if (cycle_str.IndexOf(cycle_value) != -1)
{
cycle.Remove(cycle_key);
cycle_key = cycle.ElementAt(0).Key;
cycle_value = cycle[cycle_key];
cycle_str += " " + cycle_key.ToString();
}
else
{
cycle_str += cycle_value.ToString();
cycle.Remove(cycle_key);
cycle_key = cycle_value;
cycle_value = cycle[cycle_key];
}
}
foreach (var el in cycle_str.Split(' '))
cycle_length += el.Length + " ";
return cycle_length;
}
示例8: PrintArtists
private static void PrintArtists(SortedDictionary<string, int> artists)
{
foreach (var artist in artists)
{
Console.WriteLine("Artist name: {0}, Number of albums: {1}", artist.Key, artist.Value);
}
}
示例9: GetSolution
protected override object GetSolution()
{
SortedDictionary<long, long> decomposition = new SortedDictionary<long, long>();
for (var i = 1; i <= MAX; i++)
{
var currentDecomposition = GetDecomposition(i);
foreach (KeyValuePair<long, long> kvp in currentDecomposition)
{
if (!decomposition.Keys.Contains(kvp.Key))
{
decomposition.Add(kvp.Key, kvp.Value);
}
else
{
var value = decomposition[kvp.Key];
if (value < kvp.Value)
{
decomposition[kvp.Key] = kvp.Value;
}
}
}
}
double returnValue = 1;
foreach (KeyValuePair<long, long> kvp in decomposition)
{
returnValue *= Math.Pow((double)kvp.Key, (double)kvp.Value);
}
return returnValue;
}
示例10: GetData
public List<SpreadPeriod> GetData()
{
var results = new SortedDictionary<long, SpreadPeriod>();
this.AddValues(results, this.max, (x, y) => x.max = y);
this.AddValues(results, this.min, (x, y) => x.min = y);
this.AddValues(results, this.avg, (x, y) => x.avg = y);
double lastMax = 0;
double lastMin = 0;
double lastAvg = 0;
foreach (var period in results.Select(pair => pair.Value))
{
if (period.max == 0)
{
period.max = lastMax;
}
if (period.min == 0)
{
period.min = lastMin;
}
if (period.avg == 0)
{
period.avg = lastAvg;
}
lastMax = period.max;
lastMin = period.min;
lastAvg = period.avg;
}
return results.Values.ToList();
}
示例11: GenerateAuthString
public static string GenerateAuthString(string httpmethod, string url, SortedDictionary<string, string> parameters, string callback, string oauthToken = "")
{
byte[] nonceBuffer = new byte[32];
random.NextBytes(nonceBuffer);
string oauth_nonce = Convert.ToBase64String(nonceBuffer);
string oauth_signature_method = "HMAC-SHA1";
string oauth_timestamp = UnixTime().ToString();
string oauth_callback = callback;
string oauth_version = "1.0";
if(callback != null)
{
parameters.Add("oauth_callback", oauth_callback);
}
parameters.Add("oauth_consumer_key", oauth_consumer_key);
parameters.Add("oauth_nonce", oauth_nonce);
parameters.Add("oauth_signature_method", oauth_signature_method);
parameters.Add("oauth_timestamp", oauth_timestamp);
if(oauthToken != "")
{
parameters.Add("oauth_token", oauthToken);
}
parameters.Add("oauth_version", oauth_version);
string parameterString = ParameterString(parameters);
parameters.Add("oauth_signature", Signature(httpmethod, url, parameterString, oauthToken));
return "OAuth " + AuthenticationString(parameters);
}
示例12: Main
private static void Main()
{
SortedDictionary<string, List<Student>> courses = new SortedDictionary<string, List<Student>>();
string studentsFilePath = "../../Resources/students.txt";
using (StreamReader reader = new StreamReader(studentsFilePath))
{
string line;
while ((line = reader.ReadLine()) != null)
{
string[] recordData = line.Split('|');
string firstName = recordData[0].Trim();
string lastName = recordData[1].Trim();
string course = recordData[2].Trim();
List<Student> students;
if (!courses.TryGetValue(course, out students))
{
students = new List<Student>();
courses.Add(course, students);
}
Student student = new Student(firstName, lastName);
students.Add(student);
}
}
foreach (var pair in courses)
{
Console.WriteLine("{0,15}:\n\t\t{1}", pair.Key, string.Join("\n\t\t", pair.Value));
}
}
示例13: SendGetInfo
/// <summary>
/// 构造模拟远程HTTP的GET请求,获取支付宝的返回XML处理结果
/// </summary>
/// <param name="sParaTemp">请求参数数组</param>
/// <param name="gateway">网关地址</param>
/// <returns>支付宝返回XML处理结果</returns>
public static XmlDocument SendGetInfo(SortedDictionary<string, string> sParaTemp, string gateway)
{
//待请求参数数组字符串
Encoding code = Encoding.GetEncoding(_input_charset);
string strRequestData = BuildRequestParaToString(sParaTemp, code);
//构造请求地址
string strUrl = gateway + strRequestData;
//请求远程HTTP
XmlDocument xmlDoc = new XmlDocument();
try
{
//设置HttpWebRequest基本信息
HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(strUrl);
myReq.Method = "get";
//发送POST数据请求服务器
HttpWebResponse HttpWResp = (HttpWebResponse)myReq.GetResponse();
Stream myStream = HttpWResp.GetResponseStream();
//获取服务器返回信息
XmlTextReader Reader = new XmlTextReader(myStream);
xmlDoc.Load(Reader);
}
catch (Exception exp)
{
string strXmlError = "<error>" + exp.Message + "</error>";
xmlDoc.LoadXml(strXmlError);
}
return xmlDoc;
}
示例14: AlipayUrl
public ActionResult AlipayUrl()
{
var shop = YunShop.Web.CommonMethod.GetSeoInfo();
string partners = "";
string return_url = "";
try
{
partners = shop.FirstOrDefault(e => e.Key == "alipaykey").Value;
if (string.IsNullOrWhiteSpace(shop.FirstOrDefault(e => e.Key == "alipayvalue").Value))
{
return Json(false);
}
return_url = shop.FirstOrDefault(e => e.Key == "alipayurl").Value;
}
catch
{
return Json(false);
}
string target_service = "user.auth.quick.login";
//必填
//必填,页面跳转同步通知页面路径
//需http://格式的完整路径,不允许加?id=123这类自定义参数
//把请求参数打包成数组
SortedDictionary<string, string> sParaTemp = new SortedDictionary<string, string>();
sParaTemp.Add("partner", partners);
sParaTemp.Add("_input_charset", Config.Input_charset.ToLower());
sParaTemp.Add("service", "alipay.auth.authorize");
sParaTemp.Add("target_service", target_service);
sParaTemp.Add("return_url", return_url);
//建立请求
return Json(Submit.BuildRequestUrl(sParaTemp, shop.FirstOrDefault(e => e.Key == "alipayvalue").Value));
}
示例15: ParseAreaCodeMap
public static AreaCodeMap ParseAreaCodeMap(Stream stream)
{
SortedDictionary<int, String> areaCodeMapTemp = new SortedDictionary<int, String>();
using (var lines = new StreamReader(stream, Encoding.UTF8))
{
String line;
while ((line = lines.ReadLine()) != null)
{
line = line.Trim();
if (line.Length <= 0 || line[0] == '#')
continue;
var indexOfPipe = line.IndexOf('|');
if (indexOfPipe == -1)
{
continue;
}
String areaCode = line.Substring(0, indexOfPipe);
String location = line.Substring(indexOfPipe + 1);
areaCodeMapTemp[int.Parse(areaCode)] = location;
}
// Build the corresponding area code map and serialize it to the binary format.
AreaCodeMap areaCodeMap = new AreaCodeMap();
areaCodeMap.readAreaCodeMap(areaCodeMapTemp);
return areaCodeMap;
}
}