{"id":1097,"date":"2010-02-16T13:15:47","date_gmt":"2010-02-16T04:15:47","guid":{"rendered":"http:\/\/www.gisdeveloper.co.kr\/?p=1097"},"modified":"2017-02-06T14:32:06","modified_gmt":"2017-02-06T05:32:06","slug":"c-c%ec%9d%98-multimap-%ec%bb%a8%ed%85%8c%ec%9d%b4%eb%84%88","status":"publish","type":"post","link":"http:\/\/www.gisdeveloper.co.kr\/?p=1097","title":{"rendered":"[C#] C++\uc758 multimap \ucee8\ud14c\uc774\ub108"},"content":{"rendered":"<p>C++\uc758 STL\uc5d0 multimap\uc774\ub77c\ub294 \ucee8\ud14c\uc774\ub108\uac00 \uc874\uc7ac\ud569\ub2c8\ub2e4. \uc774 \ucee8\ud14c\uc774\ub108\ub294 \ud0a4(key)\uc640 \uac12(value)\uc758 \uc30d\uc73c\ub85c \uad6c\uc131\ub41c \uc694\uc18c\ub97c \uc800\uc7a5\ud558\uace0 \uc788\uc73c\uba70 key \uac12\uc73c\ub85c \uc815\ub82c \ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4. \uc5ec\uae30\uc11c \uc911\uc694\ud55c \uac83\uc740 \uc774 \ud0a4\uac00 \uc720\uc77c\ud558\uc9c0 \uc54a\ub2e4\ub294 \uc810\uc785\ub2c8\ub2e4. \uc989 \uc911\ubcf5\ub420 \uc218 \uc788\ub2e4\ub294 \uc810\uc778\ub370\uc694. \uc774\ub7ec\ud55c C++\uc758 multimap\uc758 \uc131\uc9c8\uc744 \uac16\ub294 \ucee8\ud130\uc774\ub108\uac00 C#\uc5d0\ub294 \uae30\ubcf8\uc801\uc73c\ub85c \uc874\uc7ac\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. \ud574\uc11c \uc774\ub7ec\ud55c \ucee8\ud130\uc774\ub108\ub97c \uc9c1\uc811 \uac1c\ubc1c\uc790\uac00 \ub9cc\ub4e4\uc5b4 \uc368\uc57c \ud558\ub294\ub370.. \ub2e4\ud589\ud788 C#\uc5d0\uc11c \uc5b4\ub835\uc9c0 \uc54a\uac8c \uad6c\ud604\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>C#\uc5d0\uc11c \uc81c\uacf5\ud558\ub294 \ucee8\ud14c\uc774\ub108(NET\uc5d0\uc11c\ub294 \uceec\ub809\uc158(Collection)\uc774\ub77c\ub294 \ub2e4\ub978 \uc774\ub984\uc744 \uc0ac\uc6a9) \uc911\uc5d0 List\uc640 SortedDictionary \uceec\ub809\uc158\uc744 \uc870\ud569\ud558\uc5ec \uc6b0\ub9ac\uac00 \uc6d0\ud558\ub294 C++\uc758 multimap \ucee8\ud14c\uc774\ub108\ub97c \ub9cc\ub4e4 \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc544\ub798\ub294 \uc774\ub807\uac8c \uad6c\ud604\ud55c \uceec\ub809\uc158\uc73c\ub85c \ud074\ub798\uc2a4 \uc774\ub984\uc744 .NET\uc758 \uc774\ub984\uc5d0 \ub9de\uac8c MultiSortedDictionary\ub77c\uace0 \uc9c0\uc5c8\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\r\nclass MultiSortedDictionary<Key, Value>;\r\n{\r\n\u00a0 \u00a0 private SortedDictionary<Key, List> dic_ = null;\r\n\r\n\u00a0 \u00a0 public MultiSortedDictionary() \r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 dic_ = new SortedDictionary<Key, List>();\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public MultiSortedDictionary(IComparer comparer)\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 dic_ = new SortedDictionary<Key, List>(comparer);\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public void Add(Key key, Value value)\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 List list = null;\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 if(dic_.TryGetValue(key, out list))\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 list.Add(value);\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 \u00a0 \u00a0 else\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 list = new List();\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 list.Add(value);\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 dic_.Add(key, list);\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public bool ContainsKey(Key key)\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 return dic_.ContainsKey(key);\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public List this[Key key]\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 get\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 List list = null;\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (!dic_.TryGetValue(key, out list))\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 list = new List();\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 dic_.Add(key, list);\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return list;\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 public IEnumerable keys\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 get\r\n\u00a0 \u00a0 \u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 return dic_.Keys;\r\n\u00a0 \u00a0 \u00a0 \u00a0 }\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>MultiSortedDictionary \ud074\ub798\uc2a4\uc758 \ucf54\ub4dc\uac00 \uadf8\ub9ac \uae38\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. C#\uc740 \uc774\ubbf8 \ub9e4\uc6b0 \uc798 \ub9cc\ub4e4\uc5b4\uc9c4 \uceec\ub809\uc158 \ud074\ub798\uc2a4\ub97c \uac00\uc9c0\uace0 \uc788\uc73c\ubbc0\ub85c \uc774\ub4e4\uc744 \uc870\ud569\ud558\uc5ec \uc27d\uac8c \uad6c\ud604\ud560 \uc218 \uc788\uc5c8\uae30 \ub54c\ubb38\uc785\ub2c8\ub2e4. \uc774\uc81c MultiSortedDictionary \ud074\ub798\uc2a4\ub97c \uc0ac\uc6a9\ud574 \ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uba3c\uc800 \uc694\uc18c\ub97c \ucd94\uac00\ud569\ub2c8\ub2e4. \uc694\uc18c\uc758 \ud0a4\ub294 \uc815\uc218(int)\uc774\uace0 \uac12(value)\uc740 POINT\ub77c\ub294 \uc0ac\uc6a9\uc790 \uc815\uc758 \uad6c\uc870\uccb4\ub85c \ud558\uaca0\uc2b5\ub2c8\ub2e4. \uba3c\uc800 POINT \ud0c0\uc785\uc758 \uad6c\uc870\uccb4\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\r\nstruct POINT\r\n{\r\n\u00a0 \u00a0 public int x;\r\n\u00a0 \u00a0 public int y;\r\n\r\n\u00a0 \u00a0 public POINT(int x, int y) \r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 this.x = x;\r\n\u00a0 \u00a0 \u00a0 \u00a0 this.y = y;\r\n\u00a0 \u00a0 }\r\n\r\n\u00a0 \u00a0 override public string ToString()\r\n\u00a0 \u00a0 {\r\n\u00a0 \u00a0 \u00a0 \u00a0 return String.Format(\"({0:D},{1:D})\", x, y);\r\n\u00a0 \u00a0 }\r\n}<\/pre>\n<p>\uc774\uc81c MuiltiSortedDictionary \ud074\ub798\uc2a4\uc758 \uc778\uc2a4\ud134\uc2a4\ub97c \uc0dd\uc131\ud558\uace0 \uba87\uac00\uc9c0 \uc694\uc18c\ub97c \ucd94\uac00\ud558\ub294 \ucf54\ub4dc\ub97c \uc791\uc131\ud574 \ubcf4\uba74 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\r\nstatic void Main(string[] args)\r\n{\r\n\u00a0 \u00a0 MultiSortedDictionary<int, POINT> msd_ \r\n\u00a0 \u00a0 \u00a0 \u00a0 = new MultiSortedDictionary<int, POINT>();\r\n\r\n\u00a0 \u00a0 POINT pt1 = new POINT(100, 100);\r\n\u00a0 \u00a0 POINT pt2 = new POINT(100, 200);\r\n\u00a0 \u00a0 POINT pt3 = new POINT(100, 300);\r\n\u00a0 \u00a0 POINT pt4 = new POINT(100, 100);\r\n\u00a0 \u00a0 POINT pt5 = new POINT(100, 200);\r\n\u00a0 \u00a0 POINT pt6 = new POINT(100, 300);\r\n\r\n\u00a0 \u00a0 msd_.Add(30, pt6);\r\n\u00a0 \u00a0 msd_.Add(20, pt4);\r\n\u00a0 \u00a0 msd_.Add(10, pt1);\r\n\u00a0 \u00a0 msd_.Add(10, pt3);\r\n\u00a0 \u00a0 msd_.Add(20, pt5);\r\n\u00a0 \u00a0 msd_.Add(10, pt2);<\/pre>\n<p>\uc2e4\uc81c\ub85c \ud0a4\uc5d0 \ub300\ud574 \uc815\ub82c\uc774 \ub418\uc5b4 \uc788\ub294\uc9c0\ub97c \uc0b4\ud3b4\ubcf4\uae30 \uc704\ud574 \uc784\uc758\ub85c \uc694\uc18c\ub97c \ucd94\uac00\ud560\ub54c \ud0a4\uc758 \uc21c\uc11c\ub97c \uc815\ub82c\ub418\uc9c0 \uc54a\uc740 \ud0a4\uac12 \uc21c\uc11c\ub85c \ucd94\uac00\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. \uc2e4\uc81c\ub85c \ud0a4 \uac12\uc774 \uc815\ub82c\ub418\uc5b4 \uc788\ub294\uc9c0 \ud30c\uc545\ud558\ub294 \ucf54\ub4dc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\r\nIEnumerator iter = msd_.keys.GetEnumerator();\r\niter.Reset();\r\nConsole.Write(\"key list : \");\r\nwhile(iter.MoveNext()) \r\n{\r\n\u00a0 \u00a0 Console.Write(iter.Current + \" \");\r\n}\r\nConsole.WriteLine();<\/pre>\n<p>\uc2e4\ud589 \uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1052745026.jpg\" alt=\"\uc0ac\uc6a9\uc790 \uc0bd\uc785 \uc774\ubbf8\uc9c0\" width=\"320\" height=\"64\" \/><br \/>\n\uacb0\uacfc\ub97c \ubcf4\uba74 \uc694\uc18c\uc5d0 \ub300\ud55c \ud0a4\uc758 \uc21c\uc11c\uac00 \uc633\ubc14\ub974\uac8c \uc815\ub82c\ub418\uc5b4 \uc788\ub2e4\ub294 \uac83\uc744 \uc54c \uc218 \uc788\uc2b5\ub2c8\ub2e4. \uc5fc\ub450\ud560 \uc810\uc740 C++\uc758 \uacbd\uc6b0\ub77c\uba74 \uadf8 \uacb0\uacfc\uac00 10 10 10 20 20 30 \uc774\ub77c\ub294 \uc810\uc785\ub2c8\ub2e4.\u00a0 \uc774\uc81c \uc774\ub807\uac8c \uc800\uc7a5\ub41c \uc694\uc18c \uc911\uc5d0 \ud0a4\uac00 10\uc778 \uc694\uc18c\uc5d0 \ub300\ud55c \uac12\uc744 \uc5bb\ub294 \ucf54\ub4dc\ub97c \uc0b4\ud3b4\ubcf4\uba74 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<pre>\r\nList list = msd_[10];\r\nConsole.Write(\"key 10 [ \");\r\nfor(int i=0; i<list.Count; i++)\r\n{\r\n\u00a0 \u00a0 Console.Write(list[i] + \" \");\r\n}\r\nConsole.WriteLine(\"]\");<\/pre>\n<p>\uc2e4\ud589 \uacb0\uacfc\ub294 \uc544\ub798\uc640 \uac19\uc2b5\ub2c8\ub2e4.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.gisdeveloper.co.kr\/wp-content\/uploads\/1\/1029197003.jpg\" alt=\"\uc0ac\uc6a9\uc790 \uc0bd\uc785 \uc774\ubbf8\uc9c0\" width=\"345\" height=\"58\" \/><\/p>\n<p>\ud0a4\uac00 10\uc778 \uc694\uc18c\uc5d0 \ub300\ud55c \uac12\uc774 \ubaa8\ub450 3\uac1c\uc778\ub370, \uc0dd\uac01\ud588\ub358 \uc62c\ubc14\ub978 \uacb0\uacfc\uac00 \ub098\uc628 \uac83\uc744 \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4. C#\uc5d0\uc11c .NET\uc744 \uc0b4\ud3b4\ubcf4\uba74 \ubcfc\uc218\ub85d \ucc38\uc73c\ub85c \uccb4\uacc4\uc801\uc774\uace0 \uba4b\uc9c4 \uc5b8\uc5b4 \uadf8\ub9ac\uace0 \ud504\ub808\uc784\uc6cc\ud06c\ub77c\uace0 \uc0dd\uac01\ub429\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>C++\uc758 STL\uc5d0 multimap\uc774\ub77c\ub294 \ucee8\ud14c\uc774\ub108\uac00 \uc874\uc7ac\ud569\ub2c8\ub2e4. \uc774 \ucee8\ud14c\uc774\ub108\ub294 \ud0a4(key)\uc640 \uac12(value)\uc758 \uc30d\uc73c\ub85c \uad6c\uc131\ub41c \uc694\uc18c\ub97c \uc800\uc7a5\ud558\uace0 \uc788\uc73c\uba70 key \uac12\uc73c\ub85c \uc815\ub82c \ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4. \uc5ec\uae30\uc11c \uc911\uc694\ud55c \uac83\uc740 \uc774 \ud0a4\uac00 \uc720\uc77c\ud558\uc9c0 \uc54a\ub2e4\ub294 \uc810\uc785\ub2c8\ub2e4. \uc989 \uc911\ubcf5\ub420 \uc218 \uc788\ub2e4\ub294 \uc810\uc778\ub370\uc694. \uc774\ub7ec\ud55c C++\uc758 multimap\uc758 \uc131\uc9c8\uc744 \uac16\ub294 \ucee8\ud130\uc774\ub108\uac00 C#\uc5d0\ub294 \uae30\ubcf8\uc801\uc73c\ub85c \uc874\uc7ac\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. \ud574\uc11c \uc774\ub7ec\ud55c \ucee8\ud130\uc774\ub108\ub97c \uc9c1\uc811 \uac1c\ubc1c\uc790\uac00 \ub9cc\ub4e4\uc5b4 \uc368\uc57c \ud558\ub294\ub370.. \ub2e4\ud589\ud788 C#\uc5d0\uc11c \uc5b4\ub835\uc9c0 \uc54a\uac8c \uad6c\ud604\ud560 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/www.gisdeveloper.co.kr\/?p=1097\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;[C#] C++\uc758 multimap \ucee8\ud14c\uc774\ub108&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[118,1],"tags":[14],"class_list":["post-1097","post","type-post","status-publish","format-standard","hentry","category-csharp","category-uncategorized","tag-c"],"_links":{"self":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1097"}],"version-history":[{"count":3,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1097\/revisions"}],"predecessor-version":[{"id":4414,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=\/wp\/v2\/posts\/1097\/revisions\/4414"}],"wp:attachment":[{"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1097"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gisdeveloper.co.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}