- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3730 | 14년 전 | 943 | ||
| 3729 | 14년 전 | 762 | ||
| 3728 | 14년 전 | 754 | ||
| 3727 | 14년 전 | 742 | ||
| 3726 | 14년 전 | 1156 | ||
| 3725 | 14년 전 | 861 | ||
| 3724 | 14년 전 | 860 | ||
| 3723 |
올인할거야
|
14년 전 | 879 | |
| 3722 |
berry
|
14년 전 | 684 | |
| 3721 |
Darby
|
14년 전 | 1744 | |
| 3720 | 14년 전 | 1517 | ||
| 3719 | 14년 전 | 947 | ||
| 3718 |
gangjin
|
14년 전 | 764 | |
| 3717 |
플레이디원
|
14년 전 | 1836 | |
| 3716 | 14년 전 | 1207 | ||
| 3715 |
berry
|
14년 전 | 1046 | |
| 3714 | 14년 전 | 807 | ||
| 3713 |
|
14년 전 | 1507 | |
| 3712 | 14년 전 | 3767 | ||
| 3711 | 14년 전 | 2425 | ||
| 3710 |
SGFlash
|
14년 전 | 1120 | |
| 3709 |
프로프리랜서
|
14년 전 | 725 | |
| 3708 |
kavri
|
14년 전 | 779 | |
| 3707 | 14년 전 | 1300 | ||
| 3706 | 14년 전 | 970 | ||
| 3705 | 14년 전 | 1347 | ||
| 3704 | 14년 전 | 1394 | ||
| 3703 | 14년 전 | 1416 | ||
| 3702 |
방황하는중년
|
14년 전 | 638 | |
| 3701 | 14년 전 | 868 | ||
| 3700 | 14년 전 | 2744 | ||
| 3699 | 14년 전 | 765 | ||
| 3698 | 14년 전 | 1227 | ||
| 3697 | 14년 전 | 813 | ||
| 3696 |
|
14년 전 | 696 | |
| 3695 | 14년 전 | 1231 | ||
| 3694 | 14년 전 | 657 | ||
| 3693 |
|
14년 전 | 1340 | |
| 3692 |
아갈갤러리
|
14년 전 | 925 | |
| 3691 | 14년 전 | 1583 | ||
| 3690 | 14년 전 | 1531 | ||
| 3689 | 14년 전 | 1027 | ||
| 3688 | 14년 전 | 1256 | ||
| 3687 | 14년 전 | 943 | ||
| 3686 | 14년 전 | 1646 | ||
| 3685 | 14년 전 | 1224 | ||
| 3684 |
방황하는중년
|
14년 전 | 1230 | |
| 3683 |
휴전합시다
|
14년 전 | 1508 | |
| 3682 | 14년 전 | 1409 | ||
| 3681 | 14년 전 | 835 | ||
| 3680 | 14년 전 | 899 | ||
| 3679 | 14년 전 | 666 | ||
| 3678 | 14년 전 | 842 | ||
| 3677 |
|
14년 전 | 1587 | |
| 3676 |
|
14년 전 | 2340 | |
| 3675 | 14년 전 | 2235 | ||
| 3674 | 14년 전 | 1875 | ||
| 3673 |
|
14년 전 | 1429 | |
| 3672 | 14년 전 | 1497 | ||
| 3671 | 14년 전 | 1269 | ||
| 3670 |
아놔6636
|
14년 전 | 1529 | |
| 3669 | 14년 전 | 656 | ||
| 3668 |
아놔6636
|
14년 전 | 1280 | |
| 3667 | 14년 전 | 642 | ||
| 3666 | 14년 전 | 1083 | ||
| 3665 | 14년 전 | 859 | ||
| 3664 | 14년 전 | 1966 | ||
| 3663 | 14년 전 | 735 | ||
| 3662 | 14년 전 | 2556 | ||
| 3661 | 14년 전 | 976 | ||
| 3660 | 14년 전 | 817 | ||
| 3659 | 14년 전 | 2925 | ||
| 3658 | 14년 전 | 701 | ||
| 3657 | 14년 전 | 950 | ||
| 3656 | 14년 전 | 495 | ||
| 3655 | 14년 전 | 824 | ||
| 3654 |
쉽다zzz
|
14년 전 | 601 | |
| 3653 | 14년 전 | 1289 | ||
| 3652 | 14년 전 | 730 | ||
| 3651 | 14년 전 | 1096 | ||
| 3650 | 14년 전 | 717 | ||
| 3649 | 14년 전 | 654 | ||
| 3648 | 14년 전 | 639 | ||
| 3647 | 14년 전 | 1345 | ||
| 3646 |
|
14년 전 | 801 | |
| 3645 | 14년 전 | 684 | ||
| 3644 | 14년 전 | 704 | ||
| 3643 | 14년 전 | 1378 | ||
| 3642 |
|
14년 전 | 1381 | |
| 3641 |
|
14년 전 | 579 | |
| 3640 | 14년 전 | 2464 | ||
| 3639 | 14년 전 | 471 | ||
| 3638 |
방황하는중년
|
14년 전 | 746 | |
| 3637 | 14년 전 | 3225 | ||
| 3636 | 14년 전 | 670 | ||
| 3635 | 14년 전 | 1096 | ||
| 3634 | 14년 전 | 1446 | ||
| 3633 |
|
14년 전 | 579 | |
| 3632 | 14년 전 | 765 | ||
| 3631 | 14년 전 | 818 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기