v

[ActionScript 3.0] HashMap

· 14년 전 · 1830
 
 - 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년 전 조회 3,183
14년 전 조회 3,065
14년 전 조회 2,032
14년 전 조회 2,501
14년 전 조회 4,996
14년 전 조회 1,736
14년 전 조회 3,712
14년 전 조회 2,448
14년 전 조회 2,920
14년 전 조회 2,123
14년 전 조회 1,889
14년 전 조회 1,910
14년 전 조회 2,049
14년 전 조회 2,114
14년 전 조회 3,017
14년 전 조회 4,235
14년 전 조회 3,311
14년 전 조회 2,012
14년 전 조회 2,598
14년 전 조회 2,859
14년 전 조회 1,670
14년 전 조회 2,911
14년 전 조회 4,154
14년 전 조회 2,817
14년 전 조회 3,744
14년 전 조회 4,905
14년 전 조회 5,117
14년 전 조회 3,493
14년 전 조회 1,916
14년 전 조회 2,260
14년 전 조회 5,034
14년 전 조회 3,349
14년 전 조회 2,512
14년 전 조회 4,905
14년 전 조회 3,544
14년 전 조회 1,642
14년 전 조회 3,553
14년 전 조회 1,669
14년 전 조회 1,943
14년 전 조회 2,787
14년 전 조회 2,427
14년 전 조회 2,654
14년 전 조회 2,187
14년 전 조회 3,201
14년 전 조회 1,870
14년 전 조회 1,899
14년 전 조회 1,706
14년 전 조회 2,490
14년 전 조회 2,131
14년 전 조회 1,831
14년 전 조회 6,375
14년 전 조회 2,984
14년 전 조회 2,238
14년 전 조회 1,734
14년 전 조회 1.1만
14년 전 조회 2,639
14년 전 조회 1,657
14년 전 조회 1,694
14년 전 조회 2,530
14년 전 조회 3,081
14년 전 조회 2,608
14년 전 조회 1,837
14년 전 조회 3,131
14년 전 조회 3,083
14년 전 조회 4,092
14년 전 조회 2,194
14년 전 조회 2,346
14년 전 조회 1,885
14년 전 조회 1,942
14년 전 조회 3,194
14년 전 조회 1,970
14년 전 조회 3,485
14년 전 조회 1,695
14년 전 조회 4,579
14년 전 조회 1,748
14년 전 조회 3,162
14년 전 조회 4,536
14년 전 조회 1,794
14년 전 조회 1,990
14년 전 조회 2,341
14년 전 조회 1,885
14년 전 조회 2,429
14년 전 조회 2,293
14년 전 조회 2,443
14년 전 조회 2,168
14년 전 조회 1,774
14년 전 조회 2,224
14년 전 조회 2,228
14년 전 조회 2,114
14년 전 조회 1,675
14년 전 조회 1,617
14년 전 조회 2,031
14년 전 조회 1,558
14년 전 조회 4,120
14년 전 조회 1,573
14년 전 조회 1,950
14년 전 조회 1,613
14년 전 조회 1,632
14년 전 조회 2,877
14년 전 조회 1,944