- 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");
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 330 |
prosper
|
20년 전 | 2287 | |
| 329 |
prosper
|
20년 전 | 1917 | |
| 328 |
prosper
|
20년 전 | 1711 | |
| 327 | 20년 전 | 3777 | ||
| 326 | 20년 전 | 4865 | ||
| 325 |
hwatta
|
20년 전 | 2493 | |
| 324 |
|
20년 전 | 3150 | |
| 323 | 20년 전 | 5875 | ||
| 322 |
hwatta
|
20년 전 | 2856 | |
| 321 |
hwatta
|
20년 전 | 2331 | |
| 320 |
yesmoa
|
20년 전 | 4581 | |
| 319 | 20년 전 | 2695 | ||
| 318 | 20년 전 | 2244 | ||
| 317 |
kyodon
|
20년 전 | 2765 | |
| 316 | 20년 전 | 2588 | ||
| 315 |
|
20년 전 | 2890 | |
| 314 |
|
20년 전 | 3347 | |
| 313 |
|
20년 전 | 2653 | |
| 312 |
yesmoa
|
20년 전 | 4730 | |
| 311 | 20년 전 | 3287 | ||
| 310 |
홀로남은자
|
20년 전 | 4574 | |
| 309 | 20년 전 | 3011 | ||
| 308 | 20년 전 | 4145 | ||
| 307 | 20년 전 | 4380 | ||
| 306 | 20년 전 | 7043 | ||
| 305 | 20년 전 | 3877 | ||
| 304 | 20년 전 | 2776 | ||
| 303 |
크리스탈처럼
|
20년 전 | 4415 | |
| 302 | 20년 전 | 2215 | ||
| 301 |
|
20년 전 | 4332 | |
| 300 | 20년 전 | 3819 | ||
| 299 | 20년 전 | 2636 | ||
| 298 | 20년 전 | 4846 | ||
| 297 |
|
20년 전 | 2536 | |
| 296 | 20년 전 | 4541 | ||
| 295 | 20년 전 | 3573 | ||
| 294 | 20년 전 | 3597 | ||
| 293 | 20년 전 | 3824 | ||
| 292 | 20년 전 | 3220 | ||
| 291 |
yesmoa
|
20년 전 | 5960 | |
| 290 | 20년 전 | 2947 | ||
| 289 | 20년 전 | 5870 | ||
| 288 |
|
20년 전 | 2385 | |
| 287 |
|
20년 전 | 1818 | |
| 286 |
|
20년 전 | 2157 | |
| 285 |
|
20년 전 | 3547 | |
| 284 |
|
20년 전 | 2043 | |
| 283 |
|
20년 전 | 4406 | |
| 282 | 20년 전 | 3386 | ||
| 281 |
|
20년 전 | 2218 | |
| 280 |
|
20년 전 | 7817 | |
| 279 | 20년 전 | 5567 | ||
| 278 | 20년 전 | 3003 | ||
| 277 |
|
20년 전 | 5577 | |
| 276 | 20년 전 | 2367 | ||
| 275 | 20년 전 | 2623 | ||
| 274 | 20년 전 | 2404 | ||
| 273 | 20년 전 | 2238 | ||
| 272 | 20년 전 | 2164 | ||
| 271 | 20년 전 | 2626 | ||
| 270 | 20년 전 | 2675 | ||
| 269 | 20년 전 | 2517 | ||
| 268 | 20년 전 | 2700 | ||
| 267 | 20년 전 | 2383 | ||
| 266 | 20년 전 | 2576 | ||
| 265 | 20년 전 | 3517 | ||
| 264 |
|
20년 전 | 5380 | |
| 263 |
|
20년 전 | 3742 | |
| 262 | 20년 전 | 3202 | ||
| 261 |
허저비
|
20년 전 | 5947 | |
| 260 |
|
20년 전 | 5724 | |
| 259 | 20년 전 | 4149 | ||
| 258 | 20년 전 | 2384 | ||
| 257 | 20년 전 | 3206 | ||
| 256 | 20년 전 | 1918 | ||
| 255 | 20년 전 | 1587 | ||
| 254 | 20년 전 | 3159 | ||
| 253 | 20년 전 | 3551 | ||
| 252 | 20년 전 | 5136 | ||
| 251 | 20년 전 | 5829 | ||
| 250 | 20년 전 | 3687 | ||
| 249 | 20년 전 | 5033 | ||
| 248 | 20년 전 | 3303 | ||
| 247 | 20년 전 | 3659 | ||
| 246 |
|
20년 전 | 7966 | |
| 245 |
|
20년 전 | 5928 | |
| 244 | 20년 전 | 4498 | ||
| 243 |
|
20년 전 | 4077 | |
| 242 | 20년 전 | 2808 | ||
| 241 | 20년 전 | 2754 | ||
| 240 | 20년 전 | 2390 | ||
| 239 | 20년 전 | 1679 | ||
| 238 |
아우겐나이스
|
20년 전 | 2285 | |
| 237 |
email
|
20년 전 | 3700 | |
| 236 | 20년 전 | 4183 | ||
| 235 | 20년 전 | 10476 | ||
| 234 | 20년 전 | 5084 | ||
| 233 | 20년 전 | 3387 | ||
| 232 | 20년 전 | 3229 | ||
| 231 | 20년 전 | 3871 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기