- ActionsCript 작업중 , hashmap를 이용할 일이 었어서 검색을 하던 중 발견 하여 . 올려 봅니다.
class com.lib.data.holder.map.HashMap
{
public var keys:Array;
public var values:Array;
//
public function HashMap(source)
{
super();
this.keys = new Array();
this.values = new Array();
this.populate(source);
}
public function populate(source)
{
if (source)
{
for (var i in source)
{
this.put(i, source[i]);
}
}
}
public function containsKey(key)
{
return (this.findKey(key) > -1);
}
public function containsValue(value)
{
return (this.findValue(value) > -1);
}
public function getKeys(Void)
{
return (this.keys.slice());
}
public function getValues(Void)
{
return (this.values.slice());
}
public function get(key)
{
return (values[this.findKey(key)]);
}
public function put(key, value)
{
var oldKey;
var theKey = this.findKey(key);
if (theKey < 0)
{
this.keys.push(key);
this.values.push(value);
}
else
{
oldKey = values[theKey];
this.values[theKey] = value;
}
return (oldKey);
}
public function putAll(map)
{
var theValues = map.getValues();
var theKeys = map.getKeys();
var max = keys.length;
for (var i = 0; i < max; i = i - 1)
{
this.put(theKeys[i], theValues[i]);
}
}
public function clear(Void)
{
this.keys = new Array();
this.values = new Array();
}
public function remove(key)
{
var theKey = this.findKey(key);
if (theKey > -1)
{
var theValue = this.values[theKey];
this.values.splice(theKey, 1);
this.keys.splice(theKey, 1);
return (theValue);
}
}
public function size(Void)
{
return (this.keys.length);
}
public function isEmpty(Vois)
{
return (this.size() < 1);
}
public function findKey(key)
{
var index = this.keys.length;
while(this.keys[--index] !== key && index > -1)
{
}
return(index);
}
public function findValue(value)
{
var index = this.values.length;
while(this.values[--index] !== value && index > -1)
{
}
return (index);
}
}
##사용방법##
import com.lib.data.holder.map.*;
/* Add John to your `contact` list */
var myContacts:HashMap = new HashMap();
myContacts.put("John", new HashMap());
/* Get John, and add a `contacts` list */
var contact:HashMap = myContacts.get("John");
contact.put("contacts", new HashMap());
/* Add Johns contacts to the list */
var theContacts:HashMap = contact.get("contacts");
theContacts.put(0, "Mary");
theContacts.put(1, "Alex");
theContacts.put(2, "Julie");
/* Is Alex a contact of John? */
var isContact = myContacts.get("John").get("contacts").containsValue("Alex");
if (isContact) trace("Alex is contact of John");
else trace("Alex is Not a contact of John");
/* Is Mark a contact of John? */
var isContact = myContacts.get("John").get("contacts").containsValue("Mark");
if (isContact) trace("Mark is contact of John");
else trace("Mark is Not a contact of John");
/* Add John to your `contact` list */
var myContacts:HashMap = new HashMap();
myContacts.put("John", new HashMap());
/* Get John, and add a `contacts` list */
var contact:HashMap = myContacts.get("John");
contact.put("contacts", new HashMap());
/* Add Johns contacts to the list */
var theContacts:HashMap = contact.get("contacts");
theContacts.put(0, "Mary");
theContacts.put(1, "Alex");
theContacts.put(2, "Julie");
/* Is Alex a contact of John? */
var isContact = myContacts.get("John").get("contacts").containsValue("Alex");
if (isContact) trace("Alex is contact of John");
else trace("Alex is Not a contact of John");
/* Is Mark a contact of John? */
var isContact = myContacts.get("John").get("contacts").containsValue("Mark");
if (isContact) trace("Mark is contact of John");
else trace("Mark is Not a contact of John");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 130 | 20년 전 | 4016 | ||
| 129 | 20년 전 | 2953 | ||
| 128 | 20년 전 | 3693 | ||
| 127 | 20년 전 | 3533 | ||
| 126 | 20년 전 | 3784 | ||
| 125 | 20년 전 | 8605 | ||
| 124 | 20년 전 | 2608 | ||
| 123 | 20년 전 | 3761 | ||
| 122 | 20년 전 | 3219 | ||
| 121 | 20년 전 | 2621 | ||
| 120 | 20년 전 | 2682 | ||
| 119 | 20년 전 | 2595 | ||
| 118 | 20년 전 | 2870 | ||
| 117 |
|
20년 전 | 3071 | |
| 116 | 20년 전 | 5333 | ||
| 115 | 20년 전 | 3935 | ||
| 114 | 20년 전 | 4985 | ||
| 113 | 20년 전 | 6228 | ||
| 112 | 20년 전 | 7334 | ||
| 111 | 21년 전 | 18445 | ||
| 110 | 21년 전 | 6887 | ||
| 109 | 21년 전 | 2895 | ||
| 108 | 21년 전 | 4151 | ||
| 107 |
prosper
|
21년 전 | 2511 | |
| 106 |
prosper
|
21년 전 | 4330 | |
| 105 |
아우겐나이스
|
21년 전 | 2928 | |
| 104 | 21년 전 | 2274 | ||
| 103 | 21년 전 | 2486 | ||
| 102 | 21년 전 | 2273 | ||
| 101 | 21년 전 | 2588 | ||
| 100 | 21년 전 | 1765 | ||
| 99 | 21년 전 | 1581 | ||
| 98 | 21년 전 | 1629 | ||
| 97 | 21년 전 | 2144 | ||
| 96 | 21년 전 | 1894 | ||
| 95 | 21년 전 | 2392 | ||
| 94 | 21년 전 | 3577 | ||
| 93 | 21년 전 | 1574 | ||
| 92 | 21년 전 | 1769 | ||
| 91 | 21년 전 | 3192 | ||
| 90 | 21년 전 | 2350 | ||
| 89 | 21년 전 | 3188 | ||
| 88 | 21년 전 | 2877 | ||
| 87 | 21년 전 | 3304 | ||
| 86 | 21년 전 | 5152 | ||
| 85 | 21년 전 | 2537 | ||
| 84 | 21년 전 | 4837 | ||
| 83 | 21년 전 | 2516 | ||
| 82 | 21년 전 | 3130 | ||
| 81 | 21년 전 | 7642 | ||
| 80 | 21년 전 | 3842 | ||
| 79 | 21년 전 | 3223 | ||
| 78 | 21년 전 | 4705 | ||
| 77 | 21년 전 | 2915 | ||
| 76 | 21년 전 | 6230 | ||
| 75 | 21년 전 | 4481 | ||
| 74 | 21년 전 | 5798 | ||
| 73 | 21년 전 | 3636 | ||
| 72 | 21년 전 | 5980 | ||
| 71 | 21년 전 | 3132 | ||
| 70 | 21년 전 | 2860 | ||
| 69 | 21년 전 | 2649 | ||
| 68 | 21년 전 | 2458 | ||
| 67 | 21년 전 | 2664 | ||
| 66 | 21년 전 | 2686 | ||
| 65 | 21년 전 | 3796 | ||
| 64 | 21년 전 | 2838 | ||
| 63 | 21년 전 | 2468 | ||
| 62 | 21년 전 | 2277 | ||
| 61 | 21년 전 | 3096 | ||
| 60 | 21년 전 | 3146 | ||
| 59 | 21년 전 | 2528 | ||
| 58 | 21년 전 | 2601 | ||
| 57 | 21년 전 | 2985 | ||
| 56 | 21년 전 | 2345 | ||
| 55 | 21년 전 | 2775 | ||
| 54 | 21년 전 | 2144 | ||
| 53 | 21년 전 | 2373 | ||
| 52 | 21년 전 | 2713 | ||
| 51 |
prosper
|
21년 전 | 2367 | |
| 50 |
prosper
|
21년 전 | 2183 | |
| 49 | 21년 전 | 2195 | ||
| 48 | 21년 전 | 2356 | ||
| 47 | 21년 전 | 1950 | ||
| 46 | 21년 전 | 1937 | ||
| 45 | 21년 전 | 2144 | ||
| 44 | 21년 전 | 2375 | ||
| 43 | 21년 전 | 4589 | ||
| 42 |
prosper
|
21년 전 | 2722 | |
| 41 |
prosper
|
21년 전 | 2124 | |
| 40 | 21년 전 | 2188 | ||
| 39 | 21년 전 | 2160 | ||
| 38 | 21년 전 | 2435 | ||
| 37 | 21년 전 | 2579 | ||
| 36 | 21년 전 | 1788 | ||
| 35 | 21년 전 | 4089 | ||
| 34 | 21년 전 | 3861 | ||
| 33 | 21년 전 | 3001 | ||
| 32 |
prosper
|
21년 전 | 2915 | |
| 31 | 21년 전 | 5303 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기