1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/zhoutk-jsDataStructs

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
Dictionary.js 1.4 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
zhoutk Отправлено 27.09.2015 12:49 a035738
/***************************************************************************
> File Name : Dictionary.js
> Author : zhoutk
> Mail : zhoutk@189.cn
> Create Time : 2015-09-25 19:58
***************************************************************************/
(function(){
"use strict";
function Dictionary(){
this._size = 0;
this.datastore = Object.create(null);
}
Dictionary.prototype.isEmpty = function(){
return this._size === 0;
};
Dictionary.prototype.size = function(){
return this._size;
};
Dictionary.prototype.clear = function(){
for(var key in this.datastore){
delete this.datastore[key];
}
this._size = 0;
};
Dictionary.prototype.add = function(key, value){
this.datastore[key] = value;
this._size++;
};
Dictionary.prototype.find = function(key){
return this.datastore[key];
};
Dictionary.prototype.count = function(){
var n = 0;
for(var key in this.datastore){
n++;
}
return n;
};
Dictionary.prototype.remove = function(key){
delete this.datastore[key];
this._size--;
};
Dictionary.prototype.showAll = function(){
for(var key in this.datastore){
console.log(key + "->" + this.datastore[key]);
}
};
module.exports = Dictionary;
})();

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/zhoutk-jsDataStructs.git
git@api.gitlife.ru:oschina-mirror/zhoutk-jsDataStructs.git
oschina-mirror
zhoutk-jsDataStructs
zhoutk-jsDataStructs
master