- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4130 |
진정한승리v
|
13년 전 | 1054 | |
| 4129 | 13년 전 | 1421 | ||
| 4128 |
onlymilk74
|
13년 전 | 614 | |
| 4127 | 13년 전 | 529 | ||
| 4126 |
visualp
|
13년 전 | 1246 | |
| 4125 |
visualp
|
13년 전 | 1579 | |
| 4124 | 13년 전 | 1651 | ||
| 4123 | 13년 전 | 819 | ||
| 4122 |
visualp
|
13년 전 | 633 | |
| 4121 |
visualp
|
13년 전 | 1789 | |
| 4120 |
visualp
|
13년 전 | 856 | |
| 4119 |
visualp
|
13년 전 | 1230 | |
| 4118 |
그래픽노블
|
13년 전 | 682 | |
| 4117 |
visualp
|
13년 전 | 742 | |
| 4116 | 13년 전 | 731 | ||
| 4115 |
visualp
|
13년 전 | 823 | |
| 4114 |
onlymilk74
|
13년 전 | 4623 | |
| 4113 | 13년 전 | 730 | ||
| 4112 |
그래픽노블
|
13년 전 | 850 | |
| 4111 | 13년 전 | 1505 | ||
| 4110 | 13년 전 | 673 | ||
| 4109 | 13년 전 | 467 | ||
| 4108 | 13년 전 | 841 | ||
| 4107 | 13년 전 | 2112 | ||
| 4106 | 13년 전 | 1584 | ||
| 4105 |
onlymilk74
|
13년 전 | 1406 | |
| 4104 | 14년 전 | 2837 | ||
| 4103 | 14년 전 | 1948 | ||
| 4102 | 14년 전 | 903 | ||
| 4101 | 14년 전 | 971 | ||
| 4100 | 14년 전 | 926 | ||
| 4099 | 14년 전 | 1023 | ||
| 4098 |
Lonnie
|
14년 전 | 519 | |
| 4097 | 14년 전 | 820 | ||
| 4096 | 14년 전 | 970 | ||
| 4095 | 14년 전 | 2521 | ||
| 4094 | 14년 전 | 836 | ||
| 4093 | 14년 전 | 565 | ||
| 4092 |
|
14년 전 | 587 | |
| 4091 | 14년 전 | 2934 | ||
| 4090 | 14년 전 | 722 | ||
| 4089 |
|
14년 전 | 1437 | |
| 4088 | 14년 전 | 1439 | ||
| 4087 | 14년 전 | 634 | ||
| 4086 | 14년 전 | 1356 | ||
| 4085 | 14년 전 | 747 | ||
| 4084 | 14년 전 | 853 | ||
| 4083 | 14년 전 | 1815 | ||
| 4082 | 14년 전 | 1520 | ||
| 4081 | 14년 전 | 2120 | ||
| 4080 |
onlymilk74
|
14년 전 | 854 | |
| 4079 | 14년 전 | 740 | ||
| 4078 | 14년 전 | 2124 | ||
| 4077 |
DreamT
|
14년 전 | 755 | |
| 4076 | 14년 전 | 861 | ||
| 4075 | 14년 전 | 1975 | ||
| 4074 | 14년 전 | 992 | ||
| 4073 | 14년 전 | 900 | ||
| 4072 |
onlymilk74
|
14년 전 | 649 | |
| 4071 | 14년 전 | 896 | ||
| 4070 | 14년 전 | 1911 | ||
| 4069 | 14년 전 | 476 | ||
| 4068 | 14년 전 | 2436 | ||
| 4067 | 14년 전 | 802 | ||
| 4066 | 14년 전 | 509 | ||
| 4065 | 14년 전 | 514 | ||
| 4064 | 14년 전 | 774 | ||
| 4063 | 14년 전 | 683 | ||
| 4062 | 14년 전 | 579 | ||
| 4061 | 14년 전 | 1072 | ||
| 4060 | 14년 전 | 510 | ||
| 4059 | 14년 전 | 1191 | ||
| 4058 | 14년 전 | 1558 | ||
| 4057 | 14년 전 | 519 | ||
| 4056 |
|
14년 전 | 653 | |
| 4055 |
SGFlash
|
14년 전 | 508 | |
| 4054 |
Priere
|
14년 전 | 658 | |
| 4053 | 14년 전 | 1085 | ||
| 4052 | 14년 전 | 782 | ||
| 4051 | 14년 전 | 906 | ||
| 4050 | 14년 전 | 726 | ||
| 4049 | 14년 전 | 863 | ||
| 4048 |
내꿈은대통령
|
14년 전 | 456 | |
| 4047 |
visualp
|
14년 전 | 1265 | |
| 4046 |
visualp
|
14년 전 | 608 | |
| 4045 |
visualp
|
14년 전 | 1369 | |
| 4044 | 14년 전 | 8124 | ||
| 4043 | 14년 전 | 746 | ||
| 4042 | 14년 전 | 1592 | ||
| 4041 | 14년 전 | 1317 | ||
| 4040 | 14년 전 | 1592 | ||
| 4039 | 14년 전 | 1927 | ||
| 4038 | 14년 전 | 526 | ||
| 4037 |
sider
|
14년 전 | 670 | |
| 4036 | 14년 전 | 6463 | ||
| 4035 | 14년 전 | 652 | ||
| 4034 | 14년 전 | 584 | ||
| 4033 |
techer
|
14년 전 | 1731 | |
| 4032 | 14년 전 | 639 | ||
| 4031 | 14년 전 | 634 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기