本文整理汇总了C#中StringDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# StringDictionary.ContainsKey方法的具体用法?C# StringDictionary.ContainsKey怎么用?C# StringDictionary.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringDictionary
的用法示例。
在下文中一共展示了StringDictionary.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add
public void Add()
{
int count = 10;
StringDictionary stringDictionary = new StringDictionary();
for (int i = 0; i < count; i++)
{
string key = "Key_" + i;
string value = "Value_" + i;
stringDictionary.Add(key, value);
Assert.Equal(i + 1, stringDictionary.Count);
Assert.True(stringDictionary.ContainsKey(key));
Assert.True(stringDictionary.ContainsValue(value));
Assert.Equal(value, stringDictionary[key]);
}
Assert.False(stringDictionary.ContainsValue(null));
stringDictionary.Add("nullkey", null);
Assert.Equal(count + 1, stringDictionary.Count);
Assert.True(stringDictionary.ContainsKey("nullkey"));
Assert.True(stringDictionary.ContainsValue(null));
Assert.Null(stringDictionary["nullkey"]);
}
示例2: ContainsKey_IsCaseInsensitive
public void ContainsKey_IsCaseInsensitive()
{
StringDictionary stringDictionary = new StringDictionary();
stringDictionary.Add("key", "value");
Assert.True(stringDictionary.ContainsKey("KEY"));
Assert.True(stringDictionary.ContainsKey("kEy"));
Assert.True(stringDictionary.ContainsKey("key"));
}
示例3: Remove_DuplicateValues
public void Remove_DuplicateValues()
{
StringDictionary stringDictionary = new StringDictionary();
stringDictionary.Add("key1", "value");
stringDictionary.Add("key2", "value");
stringDictionary.Remove("key1");
Assert.Equal(1, stringDictionary.Count);
Assert.False(stringDictionary.ContainsKey("key1"));
Assert.True(stringDictionary.ContainsValue("value"));
stringDictionary.Remove("key2");
Assert.Equal(0, stringDictionary.Count);
Assert.False(stringDictionary.ContainsKey("key2"));
Assert.False(stringDictionary.ContainsValue("value"));
}
示例4: BindCountries
/// <summary>
/// Binds the country dropdown list with countries retrieved
/// from the .NET Framework.
/// </summary>
public void BindCountries()
{
StringDictionary dic = new StringDictionary();
List<string> col = new List<string>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo ri = new RegionInfo(ci.Name);
if (!dic.ContainsKey(ri.EnglishName))
dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());
if (!col.Contains(ri.EnglishName))
col.Add(ri.EnglishName);
}
// Add custom cultures
if (!dic.ContainsValue("bd"))
{
dic.Add("Bangladesh", "bd");
col.Add("Bangladesh");
}
col.Sort();
ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
foreach (string key in col)
{
ddlCountry.Items.Add(new ListItem(key, dic[key]));
}
SetDefaultCountry();
}
示例5: BindCountries
/// <summary>
/// Binds the country dropdown list with countries retrieved
/// from the .NET Framework.
/// </summary>
public void BindCountries()
{
StringDictionary dic = new StringDictionary();
List<string> col = new List<string>();
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo ri = new RegionInfo(ci.Name);
if (!dic.ContainsKey(ri.EnglishName))
dic.Add(ri.EnglishName, ri.TwoLetterISORegionName.ToLowerInvariant());
if (!col.Contains(ri.EnglishName))
col.Add(ri.EnglishName);
}
// Add custom cultures
if (!dic.ContainsValue("bd"))
{
dic.Add("Bangladesh", "bd");
col.Add("Bangladesh");
}
col.Sort();
ddlCountry.Items.Add(new ListItem("[Not specified]", ""));
foreach (string key in col)
{
ddlCountry.Items.Add(new ListItem(key, dic[key]));
}
if (ddlCountry.SelectedIndex == 0 && Request.UserLanguages != null && Request.UserLanguages[0].Length == 5)
{
ddlCountry.SelectedValue = Request.UserLanguages[0].Substring(3);
SetFlagImageUrl();
}
}
示例6: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringDictionary sd;
string ind;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"one",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
int cnt = 0;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sd = new StringDictionary();
Console.WriteLine("1. Check for empty dictionary");
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
if (sd.ContainsValue(values[i]))
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}, returned true for empty dictionary", i);
}
}
Console.WriteLine("2. add simple strings and verify ContainsValue()");
strLoc = "Loc_002oo";
iCountTestcases++;
cnt = values.Length;
for (int i = 0; i < cnt; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != cnt)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, cnt);
}
for (int i = 0; i < cnt; i++)
{
iCountTestcases++;
if (!sd.ContainsValue(values[i]))
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}b, collection doesn't contain value \"{1}\"", i, values[i]);
}
iCountTestcases++;
if (!sd.ContainsKey(keys[i]))
{
iCountErrors++;
Console.WriteLine("Err_0002_{0}c, collection doesn't contain key \"{1}\"", i, keys[i]);
}
}
Console.WriteLine("3. add intl strings and verify ContainsValue()");
strLoc = "Loc_003oo";
int len = values.Length;
string [] intlValues = new string [len*2];
for (int i = 0; i < len*2; i++)
{
string val = intl.GetString(MAX_LEN, true, true, true);
while (Array.IndexOf(intlValues, val) != -1 )
val = intl.GetString(MAX_LEN, true, true, true);
intlValues[i] = val;
}
Boolean caseInsensitive = false;
for (int i = 0; i < len * 2; i++)
{
if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
caseInsensitive = true;
}
//.........这里部分代码省略.........
示例7: runTest
//.........这里部分代码省略.........
strLoc = "Loc_002oo";
iCountTestcases++;
for (int i = 0; i < values.Length; i++)
{
sd.Add(keys[i], values[i]);
}
Console.WriteLine(" - get type");
iCountTestcases++;
en = sd.GetEnumerator();
type = en.GetType().ToString();
if ( type.IndexOf("Enumerator", 0) == 0 )
{
iCountErrors++;
Console.WriteLine("Err_0002a, type is not Enumerator");
}
Console.WriteLine(" - MoveNext and Current within collection");
for (int i = 0; i < sd.Count; i++)
{
iCountTestcases++;
res = en.MoveNext();
if ( !res )
{
iCountErrors++;
Console.WriteLine("Err_0002b_{0}, MoveNext returned false", i);
}
iCountTestcases++;
curr = (DictionaryEntry)en.Current;
if (! sd.ContainsValue(curr.Value.ToString()) )
{
iCountErrors++;
Console.WriteLine("Err_0002c_{0}, Current dictionary doesn't contain value from enumerator", i);
}
iCountTestcases++;
if (! sd.ContainsKey(curr.Key.ToString()) )
{
iCountErrors++;
Console.WriteLine("Err_0002d_{0}, Current dictionary doesn't contain key from enumerator", i);
}
iCountTestcases++;
if ( String.Compare(sd[curr.Key.ToString()], curr.Value.ToString(), false) != 0 )
{
iCountErrors++;
Console.WriteLine("Err_0002e_{0}, Value for current Key is different in dictionary", i);
}
iCountTestcases++;
DictionaryEntry curr1 = (DictionaryEntry)en.Current;
if (! curr.Equals(curr1) )
{
iCountErrors++;
Console.WriteLine("Err_0002f_{0}, second call of Current returned different result", i);
}
}
res = en.MoveNext();
Console.WriteLine(" - MoveNext outside of the collection");
iCountTestcases++;
res = en.MoveNext();
if ( res )
{
iCountErrors++;
Console.WriteLine("Err_0002g, MoveNext returned true");
}
Console.WriteLine(" - Current outside of the collection");
iCountTestcases++;
try
{
curr = (DictionaryEntry)en.Current;
示例8: RenderPosts
private string RenderPosts(List<Post> posts, StringDictionary settings)
{
if (posts.Count == 0)
{
//HttpRuntime.Cache.Insert("widget_recentposts", "<p>" + Resources.labels.none + "</p>");
return "<p>" + Resources.labels.none + "</p>";
}
StringBuilder sb = new StringBuilder();
sb.Append("<ul class=\"recentPosts\" id=\"recentPosts\">");
bool showComments = DEFAULT_SHOW_COMMENTS;
bool showRating = DEFAULT_SHOW_RATING;
if (settings.ContainsKey("showcomments"))
{
bool.TryParse(settings["showcomments"], out showComments);
}
if (settings.ContainsKey("showrating"))
{
bool.TryParse(settings["showrating"], out showRating);
}
foreach (Post post in posts)
{
if (!post.IsVisibleToPublic)
continue;
string rating = Math.Round(post.Rating, 1).ToString(System.Globalization.CultureInfo.InvariantCulture);
string link = "<li><a href=\"{0}\">{1}</a>{2}{3}</li>";
string comments = string.Format("<span>{0}: {1}</span>", Resources.labels.comments, post.ApprovedComments.Count);
if(BlogSettings.Instance.ModerationType == BlogSettings.Moderation.Disqus)
comments = string.Format("<span><a href=\"{0}#disqus_thread\">{1}</a></span>", post.PermaLink, Resources.labels.comments);
string rate = string.Format("<span>{0}: {1} / {2}</span>", Resources.labels.rating, rating, post.Raters);
if (!showComments || !BlogSettings.Instance.IsCommentsEnabled)
comments = null;
if (!showRating || !BlogSettings.Instance.EnableRating)
rate = null;
if (post.Raters == 0)
rating = Resources.labels.notRatedYet;
sb.AppendFormat(link, post.RelativeLink, HttpUtility.HtmlEncode(post.Title), comments, rate);
}
sb.Append("</ul>");
//HttpRuntime.Cache.Insert("widget_recentposts", sb.ToString());
return sb.ToString();
}
示例9: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringDictionary sd;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"one",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
int cnt = 0;
string ind;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create collection ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sd = new StringDictionary();
Console.WriteLine("1. add simple strings");
for (int i = 0; i < values.Length; i++)
{
iCountTestcases++;
cnt = sd.Count;
sd.Add(keys[i], values[i]);
if (sd.Count != cnt+1)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}a, count is {1} instead of {2}", i, sd.Count, cnt+1);
}
iCountTestcases++;
if (!sd.ContainsValue(values[i]))
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}b, collection doesn't contain value of new item", i);
}
iCountTestcases++;
if (!sd.ContainsKey(keys[i]))
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}c, collection doesn't contain key of new item", i);
}
iCountTestcases++;
if (String.Compare(sd[keys[i]], values[i], false) != 0)
{
iCountErrors++;
Console.WriteLine("Err_0001_{0}d, returned item \"{1}\" instead of \"{2}\"", i, sd[keys[i]], values[i]);
}
}
Console.WriteLine("2. add intl strings");
int len = values.Length;
string [] intlValues = new string [len * 2];
for (int i = 0; i < len * 2; i++)
{
string val = intl.GetString(MAX_LEN, true, true, true);
while (Array.IndexOf(intlValues, val) != -1 )
val = intl.GetString(MAX_LEN, true, true, true);
intlValues[i] = val;
}
Boolean caseInsensitive = false;
for (int i = 0; i < len * 2; i++)
{
if(intlValues[i].Length!=0 && intlValues[i].ToLower()==intlValues[i].ToUpper())
caseInsensitive = true;
}
Console.WriteLine(" initial number of items: " + sd.Count);
strLoc = "Loc_002oo";
for (int i = 0; i < len; i++)
{
iCountTestcases++;
cnt = sd.Count;
sd.Add(intlValues[i+len], intlValues[i]);
if (sd.Count != cnt+1)
{
//.........这里部分代码省略.........
示例10: runTest
public virtual bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
IntlStrings intl;
String strLoc = "Loc_000oo";
StringDictionary sd;
string [] values =
{
"",
" ",
"a",
"aa",
"text",
" spaces",
"1",
"$%^#",
"2222222222222222222222222",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
string [] keys =
{
"zero",
"one",
" ",
"",
"aa",
"1",
System.DateTime.Today.ToString(),
"$%^#",
Int32.MaxValue.ToString(),
" spaces",
"2222222222222222222222222"
};
int cnt = 0;
try
{
intl = new IntlStrings();
Console.WriteLine("--- create dictionary ---");
strLoc = "Loc_001oo";
iCountTestcases++;
sd = new StringDictionary();
Console.WriteLine("1. Remove() from empty dictionary");
iCountTestcases++;
if (sd.Count > 0)
sd.Clear();
for (int i = 0; i < keys.Length; i++)
{
sd.Remove(keys[0]);
}
Console.WriteLine("2. Remove() on filled dictionary");
strLoc = "Loc_002oo";
int len = values.Length;
iCountTestcases++;
sd.Clear();
for (int i = 0; i < len; i++)
{
sd.Add(keys[i], values[i]);
}
if (sd.Count != len)
{
iCountErrors++;
Console.WriteLine("Err_0002a, count is {0} instead of {1}", sd.Count, len);
}
for (int i = 0; i < len; i++)
{
iCountTestcases++;
cnt = sd.Count;
sd.Remove(keys[i]);
if (sd.Count != cnt - 1)
{
iCountErrors++;
Console.WriteLine("Err_0002b_{0}, didn't remove element with {0} key", i);
}
iCountTestcases++;
if ( sd.ContainsValue(values[i]) )
{
iCountErrors++;
Console.WriteLine("Err_0002c_{0}, removed wrong value", i);
}
iCountTestcases++;
if ( sd.ContainsKey(keys[i]) )
{
iCountErrors++;
Console.WriteLine("Err_0002d_{0}, removed wrong value", i);
}
}
Console.WriteLine("3. Remove() on dictionary with duplicate values ");
strLoc = "Loc_003oo";
iCountTestcases++;
sd.Clear();
string intlStr = intl.GetString(MAX_LEN, true, true, true);
sd.Add("keykey1", intlStr);
for (int i = 0; i < len; i++)
{
sd.Add(keys[i], values[i]);
}
sd.Add("keykey2", intlStr);
//.........这里部分代码省略.........
示例11: InitializeMappings
private void InitializeMappings()
{
using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "InitializeMappings"))
{
IDictionary<string, IMonitorHandler> handlerInstances = null;
try
{
_handlerMappings = new StringDictionary<IMonitorHandler>();
handlerInstances = new StringDictionary<IMonitorHandler>();
foreach (var mappingType in _handlerMappingTypes.AsParallel())
{
MonitorHandlerBase handler = null;
string mappingTypeKey = mappingType.Value.FullName;
if (handlerInstances.ContainsKey(mappingTypeKey))
{
handler = handlerInstances[mappingTypeKey] as MonitorHandlerBase;
}
else
{
handler = Activator.CreateInstance(mappingType.Value, true) as MonitorHandlerBase;
handlerInstances.Add(mappingTypeKey, handler);
}
if (handler == null) continue;
if (!_handlerMappings.ContainsKey(mappingType.Key))
{
_handlerMappings.Add(mappingType.Key, handler);
}
}
const string faultKey = "-1_-1";
_faultHandler = _handlerMappings[faultKey];
}
catch (Exception ex)
{
method.Exception(ex);
}
finally
{
if (handlerInstances != null)
{
handlerInstances.Clear();
handlerInstances = null;
}
}
}
}
示例12: ArrangeExecutionSteps
private static void ArrangeExecutionSteps(this ExecutionStepDictionary execSteps,
IDictionary<string, ExecutionStepCollection> messageWiseSteps,
IDictionary<int, ExecutionStepCollection> groupedSteps)
{
using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ArrangeExecutionSteps"))
{
try
{
Stack<IExecutionStep> st = new Stack<IExecutionStep>();
st.Push(execSteps.Start);
IDictionary<string, IExecutionStep> steps = new StringDictionary<IExecutionStep>();
while (st.Count != 0)
{
IExecutionStep step = st.Pop();
int level = Math.Max(0, (from p in step.PrevSteps
select p.Level).DefaultIfEmpty().Max()) + 1;
if (!steps.ContainsKey(step.UniqueKey))
{
step.Level = level;
steps.Add(step.UniqueKey, step);
}
foreach (var step2 in step.NextSteps)
{
if (!steps.ContainsKey(step2.UniqueKey))
{
st.Push(step2);
}
}
}
// last step
execSteps.End.Level = Math.Max(0, (from p in steps.Values
select p.Level).DefaultIfEmpty().Max()) + 1;
// Ordered projects
groupedSteps.Clear();
var orderedSteps = (from p in execSteps.Values
orderby p.Level
group p by p.Level);
foreach (var orderedStep in orderedSteps)
{
ExecutionStepCollection stepsList = new ExecutionStepCollection();
groupedSteps.Add(orderedStep.Key, stepsList);
foreach (var step in orderedStep)
{
stepsList.Add(step);
}
}
}
catch (Exception ex)
{
method.Exception(ex);
}
}
}
示例13: BuildQuotientMDP
public MDP BuildQuotientMDP(VerificationOutput VerificationOutput)
{
//return this;
MDP toReturn = new MDP(Precision, MAX_DIFFERENCE);
//todo change to set
List<KeyValuePair<string, string>> BoundaryOneTransition = new List<KeyValuePair<string, string>>();
//todo change to set
List<Distribution> ProbTransitions = new List<Distribution>();
Dictionary<string, List<Distribution>> GlobalProbTransitions = new Dictionary<string, List<Distribution>>();
StringDictionary<bool> visited = new StringDictionary<bool>(States.Count);
List<KeyValuePair<HashSet<string>, MDPState>> sccs = new List<KeyValuePair<HashSet<string>, MDPState>>();
Dictionary<string, int> preorder = new Dictionary<string, int>();
Dictionary<string, int> lowlink = new Dictionary<string, int>();
//HashSet<string> scc_found = new HashSet<string>();
Stack<MDPState> TaskStack = new Stack<MDPState>();
//Dictionary<string, List<string>> OutgoingTransitionTable = new Dictionary<string, List<string>>();
Stack<MDPState> stepStack = new Stack<MDPState>(1024);
visited.Add(InitState.ID, false);
TaskStack.Push(InitState);
//# Preorder counter
int preor = 0;
do
{
while (TaskStack.Count > 0)
{
MDPState pair = TaskStack.Peek();
string v = pair.ID;
if (visited.GetContainsKey(v) && visited.GetContainsKey(v))
{
TaskStack.Pop();
continue;
}
if (!preorder.ContainsKey(v))
{
preorder.Add(v, preor);
preor++;
}
bool done = true;
List<Distribution> list = pair.Distributions;
List<MDPState> nonProbTrans = new List<MDPState>();
List<Distribution> ProbTrans = new List<Distribution>();
for (int i = 0; i < list.Count; i++)
{
if (list[i].IsTrivial())
{
nonProbTrans.Add(list[i].States[0].Value);
}
else
{
ProbTrans.Add(list[i]);
}
}
if (ProbTrans.Count > 0 && !GlobalProbTransitions.ContainsKey(v))
{
GlobalProbTransitions.Add(v, ProbTrans);
ProbTransitions.AddRange(ProbTrans);
}
for (int k = nonProbTrans.Count - 1; k >= 0; k--)
{
MDPState step = nonProbTrans[k];
string tmp = step.ID;
if (visited.ContainsKey(tmp))
{
//if this node is still not visited
if (!preorder.ContainsKey(tmp))
{
//only put the first one to the work list stack.
//if there are more than one node to be visited,
//simply ignore them and keep its event step in the list.
if (done)
{
TaskStack.Push(step);
done = false;
}
}
}
else
{
visited.Add(tmp, false);
//OutgoingTransitionTable.Add(tmp, new List<string>(8));
//only put the first one into the stack.
//.........这里部分代码省略.........
示例14: Arguments
// Constructor
public Arguments(string[] args)
{
parameters = new StringDictionary();
Regex splitter = new Regex(@"^-{1,2}|^/|=|:", RegexOptions.IgnoreCase | RegexOptions.Compiled);
Regex remover = new Regex(@"^['""]?(.*?)['""]?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
string parameter = null;
string[] parts;
// Valid parameters forms:
// {-,/,--}param{ ,=,:}((",')value(",'))
// Examples:
// -param1 value1 --param2 /param3:"Test-:-work"
// /param4=happy -param5 '--=nice=--'
foreach (string txt in args)
{
// Look for new parameters (-,/ or --) and a
// possible enclosed value (=,:)
parts = splitter.Split(txt, 3);
switch (parts.Length)
{
// Found a value (for the last parameter
// found (space separator))
case 1:
if (parameter != null)
{
if (!parameters.ContainsKey(parameter))
{
parts[0] =
remover.Replace(parts[0], "$1");
parameters.Add(parameter, parts[0]);
}
parameter = null;
}
// else Error: no parameter waiting for a value (skipped)
break;
// Found just a parameter
case 2:
// The last parameter is still waiting.
// With no value, set it to true.
if (parameter != null)
{
if (!parameters.ContainsKey(parameter))
parameters.Add(parameter, "true");
}
parameter = parts[1];
break;
// Parameter with enclosed value
case 3:
// The last parameter is still waiting.
// With no value, set it to true.
if (parameter != null)
{
if (!parameters.ContainsKey(parameter))
parameters.Add(parameter, "true");
}
parameter = parts[1];
// Remove possible enclosing characters (",')
if (!parameters.ContainsKey(parameter))
{
parts[2] = remover.Replace(parts[2], "$1");
parameters.Add(parameter, parts[2]);
}
parameter = null;
break;
}
}
// In case a parameter is still waiting
if (parameter != null)
{
if (!parameters.ContainsKey(parameter))
parameters.Add(parameter, "true");
}
}
示例15: localImprovedTarjanGeldenhuysValmari
/// <summary>
/// The local function of each process running Improved MultiCore Tarjan algorithm
/// </summary>
/// <returns></returns>
public void localImprovedTarjanGeldenhuysValmari()
{
//local data for on-the-fly and Tarjan algorithm
Dictionary<string, List<string>> outgoingTransitionTable = new Dictionary<string, List<string>>(Ultility.Ultility.MC_INITIAL_SIZE);
StringDictionary<int[]> dfsData = new StringDictionary<int[]>(5000);
Dictionary<string, List<LocalPair>> expendedNodes = new Dictionary<string, List<LocalPair>>(1024);
Stack<LocalPair> callStack = new Stack<LocalPair>(5000);
Stack<LocalPair> currentStack = new Stack<LocalPair>(1024);
int counter = 0;
string goal = null;
int[] goalData = new int[2] { -2, 0 };
//--------------------------
//create initial states
List<LocalPair> initialStates = LocalPair.GetInitialPairsLocal(BA, InitialStep);
if (initialStates.Count == 0 || !BA.HasAcceptState)
{
VerificationOutput.VerificationResult = VerificationResultType.VALID;
return;
}
//create random variable for each process
Random rand = null;
lock (MultiCoreLock)
{
rand = new Random(MultiCoreSeed);
MultiCoreSeed++;
}
//put all initial states to callStack in different order & init data
int[] initPermutation = generatePermutation(initialStates.Count, rand);
for (int i = 0; i < initPermutation.Length; i++)
{
//get data from initialStates
LocalPair tmp = initialStates[initPermutation[i]];
callStack.Push(tmp);
string tmpID = tmp.GetCompressedState();
dfsData.Add(tmpID, new int[] { VISITED_NOPREORDER, 0 });
outgoingTransitionTable.Add(tmpID, new List<string>(8));
}
//start loop
while (callStack.Count > 0)
{
//cancel if too long action
if (CancelRequested || StopMutliCoreThreads)
{
return;
}
//get the top of callStack
LocalPair pair = callStack.Peek();
ConfigurationBase LTSState = pair.configuration;
string BAState = pair.state;
string v = pair.GetCompressedState();
//get local data of the top
List<string> outgoing = outgoingTransitionTable[v];
int[] vData = dfsData.GetContainsKey(v);
//if not expended then expend to next states from v
if (!expendedNodes.ContainsKey(v))
{
//create next states of v
//ConfigurationBase[] nextLTSStates = LTSState.MakeOneMove().ToArray();
IEnumerable<ConfigurationBase> nextLTSStates = LTSState.MakeOneMove(); //.ToArray()
pair.SetEnabled(nextLTSStates, FairnessType);
List<LocalPair> nextStates = LocalPair.NextLocal(BA, nextLTSStates, BAState);
expendedNodes.Add(v, nextStates);
//update outgoing of v and set initial data for successors
//no need to use inverse for statement and use nextStates
foreach (LocalPair next in nextStates)
{
string w = next.GetCompressedState();
outgoing.Add(w);
if (!dfsData.ContainsKey(w))
{
dfsData.Add(w, new int[] { VISITED_NOPREORDER, 0 });
outgoingTransitionTable.Add(w, new List<string>(8));
}
}
}
//get successors of v
List<LocalPair> successors = expendedNodes[v];
//process if v is not numbered yet
if (vData[0] == VISITED_NOPREORDER)
{
vData[0] = counter;
vData[1] = counter;
counter = counter + 1;
//push to currentStack
currentStack.Push(pair);
//.........这里部分代码省略.........