@cmu-eberly-center/eberly-ontopic-visualization
Version:
Writing tasks require countless composing decisions that are typically beyond the conscious grasp of student writers. Much of the skill of being “text-aware” is to understand that texts are composed of highly structured and often highly predictive composi
179 lines (152 loc) • 3.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
/**
*
*/
var HashTable = /*#__PURE__*/function () {
/**
*
*/
function HashTable(obj) {
_classCallCheck(this, HashTable);
this.length = 0;
this.items = {};
if (obj) {
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
this.items[p] = obj[p];
this.length++;
}
}
}
}
/**
*
*/
_createClass(HashTable, [{
key: "getItems",
value: function getItems() {
return this.items;
}
/**
*
*/
}, {
key: "getLength",
value: function getLength() {
return this.length;
}
/**
*
*/
}, {
key: "setItems",
value: function setItems(aValue, aLength) {
this.items = aValue;
this.length = aLength;
}
/**
*
*/
}, {
key: "setItem",
value: function setItem(key, value) {
var previous = undefined;
if (this.hasItem(key)) {
previous = this.items[key];
} else {
this.length++;
}
this.items[key] = value;
return previous;
}
/**
*
*/
}, {
key: "getItem",
value: function getItem(key) {
return this.hasItem(key) ? this.items[key] : undefined;
}
/**
*
*/
}, {
key: "hasItem",
value: function hasItem(key) {
return this.items.hasOwnProperty(key);
}
/**
*
*/
}, {
key: "removeItem",
value: function removeItem(key) {
if (this.hasItem(key)) {
previous = this.items[key];
this.length--;
delete this.items[key];
return previous;
} else {
return undefined;
}
}
/**
*
*/
}, {
key: "keys",
value: function keys() {
var keys = [];
for (var k in this.items) {
if (this.hasItem(k)) {
keys.push(k);
}
}
return keys;
}
/**
*
*/
}, {
key: "values",
value: function values() {
var values = [];
for (var k in this.items) {
if (this.hasItem(k)) {
values.push(this.items[k]);
}
}
return values;
}
/**
*
*/
}, {
key: "each",
value: function each(fn) {
for (var k in this.items) {
if (this.hasItem(k)) {
fn(k, this.items[k]);
}
}
}
/**
*
*/
}, {
key: "clear",
value: function clear() {
this.items = {};
this.length = 0;
}
}]);
return HashTable;
}();
exports["default"] = HashTable;