- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4830 |
임페리얼웹
|
13년 전 | 1368 | |
| 4829 |
임페리얼웹
|
13년 전 | 720 | |
| 4828 | 13년 전 | 3483 | ||
| 4827 |
|
13년 전 | 1240 | |
| 4826 | 13년 전 | 2748 | ||
| 4825 | 13년 전 | 1081 | ||
| 4824 |
gnuskin쩜net
|
13년 전 | 769 | |
| 4823 | 13년 전 | 818 | ||
| 4822 |
visualp
|
13년 전 | 683 | |
| 4821 |
다케미카코
|
13년 전 | 1261 | |
| 4820 | 13년 전 | 1347 | ||
| 4819 | 13년 전 | 2662 | ||
| 4818 |
크라이스트
|
13년 전 | 4238 | |
| 4817 |
임페리얼웹
|
13년 전 | 714 | |
| 4816 | 13년 전 | 3261 | ||
| 4815 |
하모니칼수
|
13년 전 | 651 | |
| 4814 | 13년 전 | 1112 | ||
| 4813 | 13년 전 | 710 | ||
| 4812 |
임페리얼웹
|
13년 전 | 1087 | |
| 4811 |
임페리얼웹
|
13년 전 | 1834 | |
| 4810 | 13년 전 | 1151 | ||
| 4809 | 13년 전 | 630 | ||
| 4808 | 13년 전 | 1285 | ||
| 4807 |
너는나의봄이다
|
13년 전 | 896 | |
| 4806 | 13년 전 | 1294 | ||
| 4805 | 13년 전 | 1773 | ||
| 4804 | 13년 전 | 1073 | ||
| 4803 |
한번잘해보자
|
13년 전 | 717 | |
| 4802 | 13년 전 | 1905 | ||
| 4801 |
꼬꼬아부지
|
13년 전 | 1186 | |
| 4800 | 13년 전 | 777 | ||
| 4799 |
|
13년 전 | 725 | |
| 4798 | 13년 전 | 1075 | ||
| 4797 |
한번잘해보자
|
13년 전 | 615 | |
| 4796 | 13년 전 | 1723 | ||
| 4795 | 13년 전 | 1002 | ||
| 4794 |
|
13년 전 | 1017 | |
| 4793 |
|
13년 전 | 655 | |
| 4792 | 13년 전 | 1291 | ||
| 4791 | 13년 전 | 2100 | ||
| 4790 |
|
13년 전 | 621 | |
| 4789 |
한번잘해보자
|
13년 전 | 514 | |
| 4788 |
|
13년 전 | 689 | |
| 4787 | 13년 전 | 3286 | ||
| 4786 |
한번잘해보자
|
13년 전 | 758 | |
| 4785 | 13년 전 | 1307 | ||
| 4784 | 13년 전 | 1077 | ||
| 4783 |
|
13년 전 | 725 | |
| 4782 | 13년 전 | 7735 | ||
| 4781 |
크라운엠버서더
|
13년 전 | 1107 | |
| 4780 | 13년 전 | 1754 | ||
| 4779 | 13년 전 | 755 | ||
| 4778 | 13년 전 | 1088 | ||
| 4777 | 13년 전 | 919 | ||
| 4776 | 13년 전 | 1887 | ||
| 4775 | 13년 전 | 3318 | ||
| 4774 | 13년 전 | 1533 | ||
| 4773 | 13년 전 | 3241 | ||
| 4772 | 13년 전 | 1417 | ||
| 4771 | 13년 전 | 3861 | ||
| 4770 | 13년 전 | 1423 | ||
| 4769 | 13년 전 | 911 | ||
| 4768 | 13년 전 | 1885 | ||
| 4767 | 13년 전 | 2661 | ||
| 4766 | 13년 전 | 1571 | ||
| 4765 | 13년 전 | 1380 | ||
| 4764 | 13년 전 | 3140 | ||
| 4763 | 13년 전 | 1163 | ||
| 4762 |
|
13년 전 | 723 | |
| 4761 | 13년 전 | 1611 | ||
| 4760 | 13년 전 | 852 | ||
| 4759 |
NTYPE
|
13년 전 | 5177 | |
| 4758 |
프로프리랜서
|
13년 전 | 828 | |
| 4757 |
프로프리랜서
|
13년 전 | 1214 | |
| 4756 | 13년 전 | 815 | ||
| 4755 |
원시인교주
|
13년 전 | 837 | |
| 4754 |
there007
|
13년 전 | 956 | |
| 4753 | 13년 전 | 1766 | ||
| 4752 |
세상의중심
|
13년 전 | 1575 | |
| 4751 | 13년 전 | 1300 | ||
| 4750 | 13년 전 | 1500 | ||
| 4749 |
또다른세상
|
13년 전 | 3655 | |
| 4748 | 13년 전 | 769 | ||
| 4747 |
cula100jak
|
13년 전 | 1658 | |
| 4746 | 13년 전 | 1478 | ||
| 4745 |
|
13년 전 | 618 | |
| 4744 |
designcity
|
13년 전 | 743 | |
| 4743 | 13년 전 | 621 | ||
| 4742 |
|
13년 전 | 8356 | |
| 4741 | 13년 전 | 849 | ||
| 4740 | 13년 전 | 1654 | ||
| 4739 | 13년 전 | 1324 | ||
| 4738 |
|
13년 전 | 751 | |
| 4737 |
Xerro
|
13년 전 | 491 | |
| 4736 | 13년 전 | 3723 | ||
| 4735 |
keith
|
13년 전 | 542 | |
| 4734 |
|
13년 전 | 697 | |
| 4733 | 13년 전 | 1750 | ||
| 4732 |
|
13년 전 | 1249 | |
| 4731 |
|
13년 전 | 1296 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기