本文整理汇总了C#中HashMap类的典型用法代码示例。如果您正苦于以下问题:C# HashMap类的具体用法?C# HashMap怎么用?C# HashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HashMap类属于命名空间,在下文中一共展示了HashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Flush
public override void Flush(IDictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> threadsAndFields, SegmentWriteState state)
{
var childThreadsAndFields = new HashMap<InvertedDocConsumerPerThread, ICollection<InvertedDocConsumerPerField>>();
var endChildThreadsAndFields = new HashMap<InvertedDocEndConsumerPerThread, ICollection<InvertedDocEndConsumerPerField>>();
foreach (var entry in threadsAndFields)
{
var perThread = (DocInverterPerThread) entry.Key;
ICollection<InvertedDocConsumerPerField> childFields = new HashSet<InvertedDocConsumerPerField>();
ICollection<InvertedDocEndConsumerPerField> endChildFields = new HashSet<InvertedDocEndConsumerPerField>();
foreach(DocFieldConsumerPerField field in entry.Value)
{
var perField = (DocInverterPerField)field;
childFields.Add(perField.consumer);
endChildFields.Add(perField.endConsumer);
}
childThreadsAndFields[perThread.consumer] = childFields;
endChildThreadsAndFields[perThread.endConsumer] = endChildFields;
}
consumer.Flush(childThreadsAndFields, state);
endConsumer.Flush(endChildThreadsAndFields, state);
}
示例2: Init1
/// <summary>
/// person.dic
/// </summary>
private void Init1()
{
TextReader br = null;
try
{
_personNatureAttrs = new HashMap<string, PersonNatureAttr>();
br = MyStaticValue.GetPersonReader();
string temp;
while ((temp = br.ReadLine()) != null)
{
var strs = temp.Split('\t');
var pna = _personNatureAttrs[strs[0]];
if (pna == null)
{
pna = new PersonNatureAttr();
}
pna.AddFreq(int.Parse(strs[1]), int.Parse(strs[2]));
_personNatureAttrs.Add(strs[0], pna);
}
}
finally
{
if (br != null)
br.Close();
}
}
示例3: DoRandom
public virtual void DoRandom(int iter, bool ignoreCase)
{
CharArrayMap<int?> map = new CharArrayMap<int?>(TEST_VERSION_CURRENT, 1, ignoreCase);
HashMap<string, int?> hmap = new HashMap<string, int?>();
char[] key;
for (int i = 0; i < iter; i++)
{
int len = Random().Next(5);
key = new char[len];
for (int j = 0; j < key.Length; j++)
{
key[j] = (char)Random().Next(127);
}
string keyStr = new string(key);
string hmapKey = ignoreCase ? keyStr.ToLower() : keyStr;
int val = Random().Next();
object o1 = map.Put(key, val);
object o2 = hmap.Put(hmapKey, val);
assertEquals(o1, o2);
// add it again with the string method
assertEquals(val, map.Put(keyStr, val));
assertEquals(val, map.Get(key, 0, key.Length));
assertEquals(val, map.Get(key));
assertEquals(val, map.Get(keyStr));
assertEquals(hmap.Count, map.size());
}
}
示例4: MomentUtil
static MomentUtil()
{
MOMENT_TYPES = new HashMap<String, String>(9);
MOMENT_TYPES.Put("AddActivity",
"https://developers.google.com/+/plugins/snippet/examples/thing");
MOMENT_TYPES.Put("BuyActivity",
"https://developers.google.com/+/plugins/snippet/examples/a-book");
MOMENT_TYPES.Put("CheckInActivity",
"https://developers.google.com/+/plugins/snippet/examples/place");
MOMENT_TYPES.Put("CommentActivity",
"https://developers.google.com/+/plugins/snippet/examples/blog-entry");
MOMENT_TYPES.Put("CreateActivity",
"https://developers.google.com/+/plugins/snippet/examples/photo");
MOMENT_TYPES.Put("ListenActivity",
"https://developers.google.com/+/plugins/snippet/examples/song");
MOMENT_TYPES.Put("ReserveActivity",
"https://developers.google.com/+/plugins/snippet/examples/restaurant");
MOMENT_TYPES.Put("ReviewActivity",
"https://developers.google.com/+/plugins/snippet/examples/widget");
MOMENT_LIST = new ArrayList<String>(MomentUtil.MOMENT_TYPES.KeySet());
Collections.Sort(MOMENT_LIST);
VISIBLE_ACTIVITIES = MOMENT_TYPES.KeySet().ToArray(new String[0]);
int count = VISIBLE_ACTIVITIES.Length;
for (int i = 0; i < count; i++)
{
VISIBLE_ACTIVITIES[i] = "http://schemas.google.com/" + VISIBLE_ACTIVITIES[i];
}
}
示例5: OnCreate
/// <summary>
/// Creates the event for main activity.
/// Sets layout to main, references the main page button,
/// and signIn/signOut button clicks.
/// </summary>
/// <param name="bundle">Bundle.</param>
protected override void OnCreate (Bundle bundle)
{
//For testing purposes
//Allows us to use a self signed server certificate
ServicePointManager.ServerCertificateValidationCallback +=
(sender, certificate, chain, sslPolicyErrors) => true;
//End
base.OnCreate (bundle);
references = new HashMap ();
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
//References for Main Menu Items
mButtonSignUp = FindViewById<Button> (Resource.Id.SignUpButton);
mButtonSignIn = FindViewById<Button> (Resource.Id.SignInButton);
//Click Events
//Sign Up Click
mButtonSignUp.Click += mButtonSignUp_Click;
//Sign in Click opens
mButtonSignIn.Click += MButtonSignIn_Click;
msgText = FindViewById<TextView> (Resource.Id.msgText);
//Check to see if the app can use GCM
if (IsPlayServicesAvailable ())
{
var intent = new Intent (this, typeof(RegistrationIntentService));
StartService (intent);
}
}
示例6: Main
static void Main(string[] args)
{
var listOfIntegers = new LinkedList<int> {0, 1, 2, 3, 4, 5, 6, 7};
listOfIntegers.Remove(2);
foreach (var entry in listOfIntegers)
{
Console.WriteLine(entry);
}
var hashMap = new HashMap<String, Int32>();
hashMap.Put("mike", 4);
hashMap.Put("chris", 7);
Console.WriteLine("KEY: 'mike'\t VALUE:{0}", hashMap.GetValue("mike"));
foreach (var keyValuePair in hashMap)
{
Console.WriteLine(keyValuePair);
}
var tree = new Tree<int> {4, 6, 9, 2};
foreach (var value in tree)
{
Console.Write("{0}\t", value);
}
Console.Read();
}
示例7: GenerateIndexDocuments
private IDictionary<string, Document> GenerateIndexDocuments(int ndocs)
{
IDictionary<string, Document> docs = new HashMap<string, Document>();
for (int i = 0; i < ndocs; i++)
{
Field field = new TextField(FIELD_NAME, "field_" + i, Field.Store.YES);
Field payload = new StoredField(PAYLOAD_FIELD_NAME, new BytesRef("payload_" + i));
Field weight1 = new NumericDocValuesField(WEIGHT_FIELD_NAME_1, 10 + i);
Field weight2 = new NumericDocValuesField(WEIGHT_FIELD_NAME_2, 20 + i);
Field weight3 = new NumericDocValuesField(WEIGHT_FIELD_NAME_3, 30 + i);
Field contexts = new StoredField(CONTEXTS_FIELD_NAME, new BytesRef("ctx_" + i + "_0"));
Document doc = new Document();
doc.Add(field);
doc.Add(payload);
doc.Add(weight1);
doc.Add(weight2);
doc.Add(weight3);
doc.Add(contexts);
for (int j = 1; j < AtLeast(3); j++)
{
contexts.BytesValue = new BytesRef("ctx_" + i + "_" + j);
doc.Add(contexts);
}
docs.Put(field.StringValue, doc);
}
return docs;
}
示例8: getUmbrellaWorld_Xt_to_Xtm1_Map
public static Map<RandomVariable, RandomVariable> getUmbrellaWorld_Xt_to_Xtm1_Map()
{
Map<RandomVariable, RandomVariable> tToTm1StateVarMap = new HashMap<RandomVariable, RandomVariable>();
tToTm1StateVarMap.put(ExampleRV.RAIN_t_RV, ExampleRV.RAIN_tm1_RV);
return tToTm1StateVarMap;
}
示例9: Flush
public override void Flush(IDictionary<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>> threadsAndFields, SegmentWriteState state)
{
var oneThreadsAndFields = new HashMap<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>();
var twoThreadsAndFields = new HashMap<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>();
foreach(var entry in threadsAndFields)
{
DocFieldConsumersPerThread perThread = (DocFieldConsumersPerThread) entry.Key;
ICollection<DocFieldConsumerPerField> fields = entry.Value;
IEnumerator<DocFieldConsumerPerField> fieldsIt = fields.GetEnumerator();
ICollection<DocFieldConsumerPerField> oneFields = new HashSet<DocFieldConsumerPerField>();
ICollection<DocFieldConsumerPerField> twoFields = new HashSet<DocFieldConsumerPerField>();
while (fieldsIt.MoveNext())
{
DocFieldConsumersPerField perField = (DocFieldConsumersPerField) fieldsIt.Current;
oneFields.Add(perField.one);
twoFields.Add(perField.two);
}
oneThreadsAndFields[perThread.one] = oneFields;
twoThreadsAndFields[perThread.two] = twoFields;
}
one.Flush(oneThreadsAndFields, state);
two.Flush(twoThreadsAndFields, state);
}
示例10: addItem
private void addItem(IList<IMap<String, Object>> data, String title, Intent intent)
{
HashMap<String, Object> temp = new HashMap<String, Object>();
temp.Put(TITLE_KEY, title);
temp.Put(INTENT_KEY, intent);
data.Add(temp);
}
示例11: ComputeArticleTfidf
private List<Keyword> ComputeArticleTfidf(string content, int titleLength)
{
var tm = new HashMap<string, Keyword>();
var parse = NlpAnalysis.Parse(content);
foreach (var term in parse)
{
var weight = getWeight(term, content.Length, titleLength);
if (weight == 0)
continue;
var keyword = tm[term.Name];
if (keyword == null)
{
keyword = new Keyword(term.Name, term.Nature.allFrequency, weight);
tm[term.Name] = keyword;
}
else
{
keyword.UpdateWeight(1);
}
}
var treeSet = new SortedSet<Keyword>(tm.Values);
var arrayList = new List<Keyword>(treeSet);
if (treeSet.Count <= _keywordAmount)
{
return arrayList;
}
return arrayList.Take(_keywordAmount).ToList();
}
示例12: Main
public static void Main()
{
Console.Write("Please, enter some text: ");
string text = Console.ReadLine();
var chars = text.AsEnumerable();
var charCounts = new HashMap<char, int>();
foreach (var character in chars)
{
if (charCounts.ContainsKey(character))
{
charCounts[character]++;
}
else
{
charCounts[character] = 1;
}
}
var sortedChars = charCounts.Keys.OrderBy(k => k).ToList();
foreach (var character in sortedChars)
{
Console.WriteLine("{0}: {1} time(s)", character, charCounts[character]);
}
}
示例13: Parse
public static Map<string, string> Parse(string[] args)
{
string[] arr = new string[args.Length];
args.CopyTo(arr, 0);
args = arr;
Map<string, string> options = new HashMap<string, string>();
for (int i = 0; i < args.Length; i++)
{
if (args[i][0] == '-' || args[i][0] == '/') //This start with - or /
{
args[i] = args[i].Substring(1);
if (i + 1 >= args.Length || args[i + 1][0] == '-' || args[i + 1][0] == '/') //Next start with - (or last arg)
{
options.Put(args[i], "null");
}
else
{
options.Put(args[i], args[i + 1]);
i++;
}
}
}
return options;
}
示例14: getListViewExamples
private HashMap getListViewExamples()
{
HashMap examples = new HashMap();
ArrayList examplesSet = new ArrayList();
examplesSet.Add(new ListViewGettingStartedFragment());
examplesSet.Add(new ListViewLayoutsFragment());
examplesSet.Add(new ListViewDeckOfCardsFragment());
examplesSet.Add(new ListViewSlideFragment());
examplesSet.Add(new ListViewWrapFragment());
examplesSet.Add(new ListViewItemAnimationFragment());
examplesSet.Add(new ListViewDataOperationsFragment());
examples.Put("Features", examplesSet);
examplesSet = new ArrayList();
examplesSet.Add(new ListViewReorderFragment());
examplesSet.Add(new ListViewSwipeToExecuteFragment());
examplesSet.Add(new ListViewSwipeToRefreshFragment());
examplesSet.Add(new ListViewManualLoadOnDemandFragment());
examplesSet.Add(new ListViewSelectionFragment());
examplesSet.Add(new ListViewDataAutomaticLoadOnDemandFragment());
examplesSet.Add (new ListViewStickyHeadersFragment ());
examples.Put("Behaviors", examplesSet);
return examples;
}
示例15: getChartExamples
private HashMap getChartExamples()
{
HashMap examples = new HashMap();
ArrayList examplesSet = new ArrayList();
examplesSet.Add(new ListViewGettingStartedFragment());
examples.Put("Binding", examplesSet);
examplesSet = new ArrayList();
examplesSet.Add(new ListViewReorderFragment());
examplesSet.Add(new ListViewSwipeToExecuteFragment());
examplesSet.Add(new ListViewSwipeToRefreshFragment());
examplesSet.Add(new ListViewItemAnimationFragment());
examplesSet.Add(new ListViewManualLoadOnDemandFragment());
examplesSet.Add(new ListViewDataAutomaticLoadOnDemandFragment());
examplesSet.Add(new ListViewDataOperationsFragment());
examplesSet.Add(new ListViewLayoutsFragment());
examples.Put("Features", examplesSet);
return examples;
}