- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4730 |
제너레이션
|
13년 전 | 997 | |
| 4729 | 13년 전 | 935 | ||
| 4728 | 13년 전 | 693 | ||
| 4727 | 13년 전 | 1242 | ||
| 4726 | 13년 전 | 844 | ||
| 4725 | 13년 전 | 1680 | ||
| 4724 | 13년 전 | 1013 | ||
| 4723 | 13년 전 | 2686 | ||
| 4722 | 13년 전 | 554 | ||
| 4721 |
ECEditor
|
13년 전 | 2232 | |
| 4720 | 13년 전 | 2609 | ||
| 4719 | 13년 전 | 4370 | ||
| 4718 | 13년 전 | 940 | ||
| 4717 | 13년 전 | 1167 | ||
| 4716 | 13년 전 | 1344 | ||
| 4715 |
한번잘해보자
|
13년 전 | 1164 | |
| 4714 | 13년 전 | 1163 | ||
| 4713 | 13년 전 | 2818 | ||
| 4712 | 13년 전 | 1243 | ||
| 4711 |
김준수사랑
|
13년 전 | 1008 | |
| 4710 |
한번잘해보자
|
13년 전 | 1135 | |
| 4709 | 13년 전 | 1133 | ||
| 4708 | 13년 전 | 810 | ||
| 4707 | 13년 전 | 1697 | ||
| 4706 |
프로프리랜서
|
13년 전 | 2081 | |
| 4705 |
프로프리랜서
|
13년 전 | 1369 | |
| 4704 | 13년 전 | 964 | ||
| 4703 |
프로프리랜서
|
13년 전 | 929 | |
| 4702 | 13년 전 | 825 | ||
| 4701 | 13년 전 | 1566 | ||
| 4700 | 13년 전 | 2587 | ||
| 4699 | 13년 전 | 1293 | ||
| 4698 |
|
13년 전 | 1592 | |
| 4697 |
|
13년 전 | 1113 | |
| 4696 |
|
13년 전 | 1130 | |
| 4695 |
|
13년 전 | 1341 | |
| 4694 |
|
13년 전 | 862 | |
| 4693 |
|
13년 전 | 851 | |
| 4692 |
|
13년 전 | 857 | |
| 4691 |
|
13년 전 | 1185 | |
| 4690 |
|
13년 전 | 1268 | |
| 4689 |
|
13년 전 | 1013 | |
| 4688 |
|
13년 전 | 779 | |
| 4687 |
|
13년 전 | 1055 | |
| 4686 |
|
13년 전 | 1007 | |
| 4685 |
|
13년 전 | 938 | |
| 4684 |
|
13년 전 | 1037 | |
| 4683 |
|
13년 전 | 928 | |
| 4682 |
|
13년 전 | 1240 | |
| 4681 |
|
13년 전 | 1015 | |
| 4680 |
|
13년 전 | 1136 | |
| 4679 |
|
13년 전 | 1647 | |
| 4678 |
|
13년 전 | 576 | |
| 4677 | 13년 전 | 2910 | ||
| 4676 |
복이219
|
13년 전 | 613 | |
| 4675 | 13년 전 | 810 | ||
| 4674 | 13년 전 | 604 | ||
| 4673 | 13년 전 | 984 | ||
| 4672 | 13년 전 | 926 | ||
| 4671 | 13년 전 | 1194 | ||
| 4670 | 13년 전 | 706 | ||
| 4669 | 13년 전 | 1776 | ||
| 4668 | 13년 전 | 1417 | ||
| 4667 |
너는나의봄이다
|
13년 전 | 1015 | |
| 4666 | 13년 전 | 6687 | ||
| 4665 | 13년 전 | 606 | ||
| 4664 | 13년 전 | 989 | ||
| 4663 | 13년 전 | 837 | ||
| 4662 | 13년 전 | 960 | ||
| 4661 | 13년 전 | 1234 | ||
| 4660 | 13년 전 | 831 | ||
| 4659 | 13년 전 | 1095 | ||
| 4658 |
소나무닷컴
|
13년 전 | 684 | |
| 4657 | 13년 전 | 702 | ||
| 4656 |
|
13년 전 | 1232 | |
| 4655 | 13년 전 | 3087 | ||
| 4654 | 13년 전 | 667 | ||
| 4653 | 13년 전 | 2096 | ||
| 4652 | 13년 전 | 865 | ||
| 4651 | 13년 전 | 769 | ||
| 4650 | 13년 전 | 1653 | ||
| 4649 | 13년 전 | 1580 | ||
| 4648 | 13년 전 | 600 | ||
| 4647 | 13년 전 | 1495 | ||
| 4646 | 13년 전 | 1927 | ||
| 4645 | 13년 전 | 1326 | ||
| 4644 | 13년 전 | 586 | ||
| 4643 | 13년 전 | 2002 | ||
| 4642 | 13년 전 | 800 | ||
| 4641 |
|
13년 전 | 586 | |
| 4640 | 13년 전 | 555 | ||
| 4639 |
|
13년 전 | 1288 | |
| 4638 |
|
13년 전 | 1662 | |
| 4637 |
|
13년 전 | 1127 | |
| 4636 | 13년 전 | 613 | ||
| 4635 | 13년 전 | 750 | ||
| 4634 | 13년 전 | 1252 | ||
| 4633 | 13년 전 | 1198 | ||
| 4632 |
|
13년 전 | 534 | |
| 4631 | 13년 전 | 3338 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기