개발자의 노트
반응형

https://code.google.com/p/suas-map-server/source/browse/trunk/+suas-map-server/suas4/cssjs/lib/jquery/js/plugin/jQuery.Hashtable-1.1.js


특별한 설명은 필요없을 듯..


사용법 


해쉬테이블 생성 : var ht = new jQuery.Hashtable();

키-값 추가 : ht.add("item1","hello");

값 얻기 : var val = ht.get("item1");

키 삭제 : ht.remove("item1");

키가 있는지 여부 : ht.containsKey("item1");

값이 있는지 여부 : ht.containsValue("hello"); 

키나 값이 있는지 여부 : ht.contains("item1"); / ht.contains("hello");

해쉬테이블 모두 지우기 : ht.clear();

해쉬테이블 크기 구하기 : ht.size();

해쉬테이블이 비어있는지 여부 : ht.isEmpty();


 

단, 원본 소스상에서 remove에 해당 키가 없으면 throw를 던지는데.. 굳이 그럴 필요는 없을 듯..

키가 있어서 삭제하면 리턴값 true, 키가 없으면 false 를 반환하는 걸로 수정해서 쓰는게 좋겠다.


this.remove = function(key) { if(this.containsKey(key)) { delete this.items[key]; this.itemsCount--; } else throw "key '"+key+"' does not exists." }



=>


this.remove = function(key)

        {

                if(this.containsKey(key))

                {

                        delete this.items[key];

                        this.itemsCount--;

return true;

                }

                else

                        return false;

        }


profile

개발자의 노트

@곽코딩

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!