- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4530 |
라이언31
|
13년 전 | 614 | |
| 4529 | 13년 전 | 791 | ||
| 4528 |
꼬꼬아부지
|
13년 전 | 1001 | |
| 4527 | 13년 전 | 606 | ||
| 4526 | 13년 전 | 688 | ||
| 4525 |
|
13년 전 | 1004 | |
| 4524 | 13년 전 | 977 | ||
| 4523 | 13년 전 | 2281 | ||
| 4522 | 13년 전 | 612 | ||
| 4521 | 13년 전 | 1255 | ||
| 4520 | 13년 전 | 1547 | ||
| 4519 |
복이219
|
13년 전 | 1203 | |
| 4518 | 13년 전 | 491 | ||
| 4517 | 13년 전 | 1293 | ||
| 4516 |
아이피마스터
|
13년 전 | 550 | |
| 4515 | 13년 전 | 636 | ||
| 4514 | 13년 전 | 634 | ||
| 4513 | 13년 전 | 1067 | ||
| 4512 |
ananom
|
13년 전 | 4358 | |
| 4511 |
ananom
|
13년 전 | 1476 | |
| 4510 | 13년 전 | 1213 | ||
| 4509 | 13년 전 | 678 | ||
| 4508 | 13년 전 | 843 | ||
| 4507 | 13년 전 | 929 | ||
| 4506 | 13년 전 | 697 | ||
| 4505 | 13년 전 | 626 | ||
| 4504 | 13년 전 | 464 | ||
| 4503 | 13년 전 | 497 | ||
| 4502 |
|
13년 전 | 1788 | |
| 4501 | 13년 전 | 1620 | ||
| 4500 |
|
13년 전 | 482 | |
| 4499 | 13년 전 | 1869 | ||
| 4498 | 13년 전 | 1147 | ||
| 4497 |
미션임파썩을
|
13년 전 | 887 | |
| 4496 | 13년 전 | 935 | ||
| 4495 |
공포의니이킥
|
13년 전 | 1103 | |
| 4494 | 13년 전 | 1968 | ||
| 4493 | 13년 전 | 1059 | ||
| 4492 | 13년 전 | 487 | ||
| 4491 |
두근두근따봉
|
13년 전 | 921 | |
| 4490 | 13년 전 | 1365 | ||
| 4489 |
jaein8060
|
13년 전 | 610 | |
| 4488 | 13년 전 | 1035 | ||
| 4487 |
ReeJang
|
13년 전 | 1817 | |
| 4486 | 13년 전 | 977 | ||
| 4485 | 13년 전 | 798 | ||
| 4484 | 13년 전 | 852 | ||
| 4483 | 13년 전 | 517 | ||
| 4482 | 13년 전 | 1177 | ||
| 4481 | 13년 전 | 1047 | ||
| 4480 |
|
13년 전 | 520 | |
| 4479 | 13년 전 | 908 | ||
| 4478 | 13년 전 | 3961 | ||
| 4477 | 13년 전 | 986 | ||
| 4476 |
wangko
|
13년 전 | 2700 | |
| 4475 | 13년 전 | 921 | ||
| 4474 | 13년 전 | 955 | ||
| 4473 | 13년 전 | 756 | ||
| 4472 |
|
13년 전 | 547 | |
| 4471 | 13년 전 | 1559 | ||
| 4470 | 13년 전 | 570 | ||
| 4469 | 13년 전 | 518 | ||
| 4468 | 13년 전 | 843 | ||
| 4467 | 13년 전 | 639 | ||
| 4466 | 13년 전 | 909 | ||
| 4465 | 13년 전 | 657 | ||
| 4464 | 13년 전 | 1713 | ||
| 4463 |
chongho
|
13년 전 | 2168 | |
| 4462 |
chongho
|
13년 전 | 1018 | |
| 4461 |
chongho
|
13년 전 | 1020 | |
| 4460 | 13년 전 | 748 | ||
| 4459 | 13년 전 | 2777 | ||
| 4458 | 13년 전 | 783 | ||
| 4457 | 13년 전 | 492 | ||
| 4456 | 13년 전 | 1317 | ||
| 4455 | 13년 전 | 1721 | ||
| 4454 | 13년 전 | 690 | ||
| 4453 | 13년 전 | 1248 | ||
| 4452 |
aequum
|
13년 전 | 1267 | |
| 4451 | 13년 전 | 1320 | ||
| 4450 |
도토리과자
|
13년 전 | 1422 | |
| 4449 | 13년 전 | 1075 | ||
| 4448 | 13년 전 | 8615 | ||
| 4447 | 13년 전 | 1201 | ||
| 4446 | 13년 전 | 1482 | ||
| 4445 | 13년 전 | 628 | ||
| 4444 |
|
13년 전 | 580 | |
| 4443 | 13년 전 | 686 | ||
| 4442 |
Msoft
|
13년 전 | 1049 | |
| 4441 |
|
13년 전 | 2097 | |
| 4440 | 13년 전 | 611 | ||
| 4439 | 13년 전 | 1649 | ||
| 4438 |
aequum
|
13년 전 | 1833 | |
| 4437 | 13년 전 | 983 | ||
| 4436 | 13년 전 | 915 | ||
| 4435 |
디귿소프트
|
13년 전 | 506 | |
| 4434 | 13년 전 | 1065 | ||
| 4433 | 13년 전 | 989 | ||
| 4432 | 13년 전 | 853 | ||
| 4431 | 13년 전 | 748 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기