- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4930 | 13년 전 | 668 | ||
| 4929 | 13년 전 | 2025 | ||
| 4928 | 13년 전 | 638 | ||
| 4927 |
|
13년 전 | 794 | |
| 4926 | 13년 전 | 1118 | ||
| 4925 |
techer
|
13년 전 | 1279 | |
| 4924 |
techer
|
13년 전 | 2891 | |
| 4923 |
techer
|
13년 전 | 3109 | |
| 4922 | 13년 전 | 604 | ||
| 4921 | 13년 전 | 1104 | ||
| 4920 |
StyleRoot
|
13년 전 | 585 | |
| 4919 | 13년 전 | 1164 | ||
| 4918 |
onlymilk74
|
13년 전 | 944 | |
| 4917 |
하나데이타
|
13년 전 | 831 | |
| 4916 |
하나데이타
|
13년 전 | 1158 | |
| 4915 | 13년 전 | 434 | ||
| 4914 | 13년 전 | 1831 | ||
| 4913 | 13년 전 | 1566 | ||
| 4912 | 13년 전 | 1299 | ||
| 4911 | 13년 전 | 747 | ||
| 4910 | 13년 전 | 1221 | ||
| 4909 |
성민꼬르꼬
|
13년 전 | 1450 | |
| 4908 | 13년 전 | 1045 | ||
| 4907 | 13년 전 | 2231 | ||
| 4906 | 13년 전 | 891 | ||
| 4905 |
kinyenug1
|
13년 전 | 610 | |
| 4904 |
kinyenug1
|
13년 전 | 786 | |
| 4903 | 13년 전 | 3593 | ||
| 4902 | 13년 전 | 2468 | ||
| 4901 | 13년 전 | 1025 | ||
| 4900 | 13년 전 | 1195 | ||
| 4899 | 13년 전 | 2594 | ||
| 4898 | 13년 전 | 1589 | ||
| 4897 |
다케미카코
|
13년 전 | 756 | |
| 4896 |
안뇽하어영
|
13년 전 | 816 | |
| 4895 |
baek83
|
13년 전 | 2212 | |
| 4894 | 13년 전 | 697 | ||
| 4893 | 13년 전 | 945 | ||
| 4892 | 13년 전 | 444 | ||
| 4891 | 13년 전 | 597 | ||
| 4890 | 13년 전 | 1341 | ||
| 4889 |
Black
|
13년 전 | 2883 | |
| 4888 |
techer
|
13년 전 | 639 | |
| 4887 |
techer
|
13년 전 | 906 | |
| 4886 |
visualp
|
13년 전 | 1300 | |
| 4885 | 13년 전 | 701 | ||
| 4884 |
너는나의봄이다
|
13년 전 | 2320 | |
| 4883 | 13년 전 | 923 | ||
| 4882 | 13년 전 | 1602 | ||
| 4881 | 13년 전 | 1847 | ||
| 4880 | 13년 전 | 1654 | ||
| 4879 | 13년 전 | 966 | ||
| 4878 |
|
13년 전 | 1265 | |
| 4877 | 13년 전 | 770 | ||
| 4876 |
꿈을꾸는너구리
|
13년 전 | 633 | |
| 4875 |
성민꼬르꼬
|
13년 전 | 1290 | |
| 4874 | 13년 전 | 979 | ||
| 4873 | 13년 전 | 832 | ||
| 4872 | 13년 전 | 755 | ||
| 4871 | 13년 전 | 916 | ||
| 4870 | 13년 전 | 706 | ||
| 4869 | 13년 전 | 1226 | ||
| 4868 | 13년 전 | 933 | ||
| 4867 | 13년 전 | 629 | ||
| 4866 | 13년 전 | 1239 | ||
| 4865 | 13년 전 | 876 | ||
| 4864 |
기획자정군
|
13년 전 | 1614 | |
| 4863 |
꼬꼬아부지
|
13년 전 | 1040 | |
| 4862 | 13년 전 | 3510 | ||
| 4861 |
|
13년 전 | 1572 | |
| 4860 |
|
13년 전 | 2167 | |
| 4859 | 13년 전 | 790 | ||
| 4858 | 13년 전 | 442 | ||
| 4857 | 13년 전 | 1119 | ||
| 4856 |
크라운엠버서더
|
13년 전 | 1920 | |
| 4855 | 13년 전 | 831 | ||
| 4854 | 13년 전 | 2046 | ||
| 4853 | 13년 전 | 743 | ||
| 4852 | 13년 전 | 1092 | ||
| 4851 |
꼬꼬아부지
|
13년 전 | 1800 | |
| 4850 | 13년 전 | 1113 | ||
| 4849 |
|
13년 전 | 779 | |
| 4848 | 13년 전 | 1474 | ||
| 4847 |
|
13년 전 | 3791 | |
| 4846 | 13년 전 | 518 | ||
| 4845 | 13년 전 | 582 | ||
| 4844 | 13년 전 | 767 | ||
| 4843 | 13년 전 | 3914 | ||
| 4842 | 13년 전 | 1256 | ||
| 4841 | 13년 전 | 1428 | ||
| 4840 | 13년 전 | 1437 | ||
| 4839 | 13년 전 | 744 | ||
| 4838 | 13년 전 | 620 | ||
| 4837 | 13년 전 | 767 | ||
| 4836 |
TIAMO
|
13년 전 | 1579 | |
| 4835 | 13년 전 | 948 | ||
| 4834 | 13년 전 | 1283 | ||
| 4833 | 13년 전 | 2481 | ||
| 4832 |
|
13년 전 | 945 | |
| 4831 | 13년 전 | 1259 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기