class Map { private _hashKeys : Dictionary = new Dictionary ( ) ; private _keys : Array < any > = new Array ( ) ; private _datas : Dictionary = new Dictionary ( ) ; constructor ( ) { } public dispose ( ) { this . clear ( ) ; this . _hashKeys = null ; this . _datas = null ; this . _keys = null ; } public addValue ( key , value ) { if ( this . isExist ( key ) ) { this . _datas [ key ] = value ; return ; } this . _hashKeys [ key ] = key ; this . _datas [ key ] = value ; this . _keys . push ( key ) ; } public removeValue ( key ) { var count = this . _keys . length ; for ( var i = 0 ; i < count ; i ++ ) { var curKey = this . _keys [ i ] ; if ( curKey == key ) { this . _keys . splice ( i , 1 ) ; delete this . _datas [ key ] ; delete this . _hashKeys [ key ] ; return ; } } } public isExist ( key ) { if ( key == null ) { return false ; } return ( this . _hashKeys [ key ] != null ) ; } public clear ( ) { var count = this . _keys . length ; for ( var i = 0 ; i < count ; ++ i ) { var key = this . _keys [ i ] ; if ( key != null ) { delete this . _datas [ key ] ; delete this . _hashKeys [ key ] ; } } this . _keys . splice ( 0 , this . _keys . length ) ; } public get length ( ) : number { return this . _keys . length ; } public getKey ( index ) { if ( index >= this . _keys . length ) { return null ; } var key = this . _keys [ index ] ; return key ; } public getKeys ( ) { var keys = new Array ( ) ; var count = this . _keys . length ; for ( var i = 0 ; i < count ; ++ i ) { var key = this . _keys [ i ] ; if ( key != null ) { keys . push ( key ) ; } } return keys ; } public getValueByKey ( key ) { if ( ! this . isExist ( key ) ) { return null ; } return this . _datas [ key ] ; } public getValueByIndex ( index ) { if ( index >= this . _keys . length ) { return null ; } var key = this . _keys [ index ] ; return this . _datas [ key ] ; } }