当前位置: 首页>>代码示例>>C#>>正文


C# HashMap.Remove方法代码示例

本文整理汇总了C#中HashMap.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# HashMap.Remove方法的具体用法?C# HashMap.Remove怎么用?C# HashMap.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HashMap的用法示例。


在下文中一共展示了HashMap.Remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            IMap<string, int> map = new HashMap<string, int>();

            map.Put("yellow", 1);
            map.Put("blue", 10);
            map.Put("red", 67);

            while(true)
            {
                string[] command = Console.ReadLine().Split(' ');
                try
                {
                    switch (command[0].ToLower())
                    {
                        case "clear":
                            map.Clear();
                            break;
                        case "put":
                            map.Put(command[1], Convert.ToInt32(command[2]));
                            break;
                        case "remove":
                            map.Remove(command[1]);
                            break;
                        case "containskey":
                            Console.WriteLine(map.ContainsKey(command[1]));
                            break;
                        case "containsvalue":
                            Console.WriteLine(map.ContainsValue(Convert.ToInt32(command[1])));
                            break;
                        case "list":
                            foreach (IEntry<string, int> e in map)
                                Console.WriteLine(e.ToString());
                            break;
                        case "keys":
                            foreach (string s in map.Keys)
                                Console.WriteLine(s);
                            break;
                        case "values":
                            foreach (int i in map.Values)
                                Console.WriteLine(i.ToString());
                            break;

                        case "testum":  //test
                            UnmutableMap<string, int> um = new UnmutableMap<string, int>(map);
                            Console.WriteLine(um["red"].ToString());
                            um["red"] = 3;
                            break;

                        case "testfind":
                            map = MapUtilsGeneric<string, int>.FindAll(map,
                                new MapUtilsGeneric<string, int>.CheckDelegate( (Entry<string, int> e) => { return e.Key[0] == 'r'; } ),
                                MapUtilsGeneric<string, int>.ArrayMapConstructor);
                            break;

                        default:
                            throw new Exception("Unknown command.");
                    }
                } catch (Exception ex)
                {
                    Console.WriteLine(ex.GetType().ToString() + ": " + ex.Message);
                }
            }
        }
开发者ID:greenflame,项目名称:vsu_map,代码行数:64,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();

#if true
            const int MaxNum = 1024*100;
            keyValue[] keyvalues = new keyValue[MaxNum];

            System.Random random = new Random();
            for(int i=0; i<MaxNum; ++i){
                int len = random.Next()%12+4;
                int notAlnum = len/3;
                keyvalues[i].key_ = System.Web.Security.Membership.GeneratePassword(len, notAlnum);
                keyvalues[i].value_ = string.Format("{0}", i);
            }

            for(int count = 0; count < 2; ++count) {
                {
                    //TinyCollections
                    TinyCollections.Hopscotch<string, string> strToStr = new TinyCollections.Hopscotch<string, string>();
                    stopwatch.Reset();
                    stopwatch.Start();

                    for(int i = 0; i < MaxNum; ++i) {
                        strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_);
                    }

                    for(int i = MaxNum - 2; 0 <= i; i -= 2) {
                        strToStr.Remove(keyvalues[i].key_);
                    }

                    for(int i = 0; i < MaxNum; i += 2) {
                        strToStr.Overwrite(keyvalues[i].key_, keyvalues[i].value_);
                    }
                    stopwatch.Stop();
                    System.Console.WriteLine("Tiny:InsertRemove " + stopwatch.Elapsed);

                    stopwatch.Reset();
                    stopwatch.Start();

                    for(int i = 0; i < MaxNum; ++i) {
                        string value;
                        if(strToStr.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) {
                        } else {
                            System.Console.WriteLine("error");
                        }
                    }
                    stopwatch.Stop();
                    System.Console.WriteLine("Tiny:Find {0} Memory {1}", stopwatch.Elapsed, GC.GetTotalMemory(true));
                }
                {
                    //System.Collections.Generic.Dictionary
                    Dictionary<string, string> direcionary = new Dictionary<string, string>();
                    stopwatch.Reset();
                    stopwatch.Start();

                    for(int i = 0; i < MaxNum; ++i) {
                        direcionary[keyvalues[i].key_] = keyvalues[i].value_;
                    }

                    for(int i = MaxNum - 2; 0 <= i; i -= 2) {
                        direcionary.Remove(keyvalues[i].key_);
                    }

                    for(int i = 0; i < MaxNum; i += 2) {
                        direcionary[keyvalues[i].key_] = keyvalues[i].value_;
                    }
                    stopwatch.Stop();
                    System.Console.WriteLine("Dictionary:InsertRemove " + stopwatch.Elapsed);

                    stopwatch.Reset();
                    stopwatch.Start();

                    for(int i = 0; i < MaxNum; ++i) {
                        string value;
                        if(direcionary.TryGetValue(keyvalues[i].key_, out value) && value == keyvalues[i].value_) {
                        } else {
                            System.Console.WriteLine("error");
                        }
                    }
                    stopwatch.Stop();
                    System.Console.WriteLine("Dictionary:Find {0} Memory {1}", stopwatch.Elapsed, GC.GetTotalMemory(true));
                }
            }
#else
            const int MaxNum = 1024*100;
            keyValueInt[] keyvalues = new keyValueInt[MaxNum];
            System.Random random = new System.Random();

            for(int i=0; i<MaxNum; ++i){
                keyvalues[i].key_ = random.Next();
                keyvalues[i].value_ = i;
            }

            for(int count=0; count<2; ++count) {
                {
                    //TinyCollections
                    TinyCollections.HashMap<int, int> strToStr = new HashMap<int, int>();
                    stopwatch.Reset();
                    stopwatch.Start();
//.........这里部分代码省略.........
开发者ID:taqu,项目名称:TinyCollections,代码行数:101,代码来源:Program.cs


注:本文中的HashMap.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。