v

[ActionScript 3.0] HashMap

· 14년 전 · 1570
 
 - 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");

 
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 2,886
14년 전 조회 2,734
14년 전 조회 1,735
14년 전 조회 2,204
14년 전 조회 4,692
14년 전 조회 1,441
14년 전 조회 3,410
14년 전 조회 2,161
14년 전 조회 2,623
14년 전 조회 1,837
14년 전 조회 1,591
14년 전 조회 1,613
14년 전 조회 1,725
14년 전 조회 1,817
14년 전 조회 2,695
14년 전 조회 3,940
14년 전 조회 3,016
14년 전 조회 1,733
14년 전 조회 2,310
14년 전 조회 2,586
14년 전 조회 1,366
14년 전 조회 2,630
14년 전 조회 3,849
14년 전 조회 2,513
14년 전 조회 3,452
14년 전 조회 4,724
14년 전 조회 4,803
14년 전 조회 3,202
14년 전 조회 1,634
14년 전 조회 1,962
14년 전 조회 4,764
14년 전 조회 3,068
14년 전 조회 2,237
14년 전 조회 4,614
14년 전 조회 3,254
14년 전 조회 1,362
14년 전 조회 3,257
14년 전 조회 1,392
14년 전 조회 1,621
14년 전 조회 2,507
14년 전 조회 2,118
14년 전 조회 2,377
14년 전 조회 1,901
14년 전 조회 2,924
14년 전 조회 1,574
14년 전 조회 1,588
14년 전 조회 1,425
14년 전 조회 2,245
14년 전 조회 1,844
14년 전 조회 1,571
14년 전 조회 6,127
14년 전 조회 2,704
14년 전 조회 1,958
14년 전 조회 1,462
14년 전 조회 1만
14년 전 조회 2,377
14년 전 조회 1,380
14년 전 조회 1,386
14년 전 조회 2,254
14년 전 조회 2,813
14년 전 조회 2,332
14년 전 조회 1,562
14년 전 조회 2,868
14년 전 조회 2,825
14년 전 조회 3,816
14년 전 조회 1,949
14년 전 조회 2,062
14년 전 조회 1,610
14년 전 조회 1,695
14년 전 조회 2,926
14년 전 조회 1,709
14년 전 조회 3,212
14년 전 조회 1,420
14년 전 조회 4,312
14년 전 조회 1,498
14년 전 조회 2,862
14년 전 조회 4,283
14년 전 조회 1,543
14년 전 조회 1,724
14년 전 조회 2,092
14년 전 조회 1,600
14년 전 조회 2,148
14년 전 조회 2,017
14년 전 조회 2,135
14년 전 조회 1,891
14년 전 조회 1,503
14년 전 조회 1,969
14년 전 조회 1,976
14년 전 조회 1,834
14년 전 조회 1,411
14년 전 조회 1,347
14년 전 조회 1,760
14년 전 조회 1,257
14년 전 조회 3,855
14년 전 조회 1,293
14년 전 조회 1,692
14년 전 조회 1,310
14년 전 조회 1,361
14년 전 조회 2,604
14년 전 조회 1,649