dict: Remove is_empty method.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg 2020-02-02 23:04:28 -08:00 committed by Tim Abbott
parent 60fac80c8e
commit 61de2e8192
7 changed files with 7 additions and 31 deletions

View File

@ -4,13 +4,13 @@ const Dict = zrequire('dict').Dict;
run_test('basic', () => { run_test('basic', () => {
const d = new Dict(); const d = new Dict();
assert(d.is_empty()); assert.equal(d.size, 0);
assert.deepEqual(d.keys(), []); assert.deepEqual(d.keys(), []);
d.set('foo', 'bar'); d.set('foo', 'bar');
assert.equal(d.get('foo'), 'bar'); assert.equal(d.get('foo'), 'bar');
assert(!d.is_empty()); assert.notEqual(d.size, 0);
d.set('foo', 'baz'); d.set('foo', 'baz');
assert.equal(d.get('foo'), 'baz'); assert.equal(d.get('foo'), 'baz');
@ -113,15 +113,12 @@ run_test('each', () => {
run_test('num_items', () => { run_test('num_items', () => {
const d = new Dict(); const d = new Dict();
assert.equal(d.size, 0); assert.equal(d.size, 0);
assert(d.is_empty());
d.set('foo', 1); d.set('foo', 1);
assert.equal(d.size, 1); assert.equal(d.size, 1);
assert(!d.is_empty());
d.set('foo', 2); d.set('foo', 2);
assert.equal(d.size, 1); assert.equal(d.size, 1);
assert(!d.is_empty());
d.set('bar', 1); d.set('bar', 1);
assert.equal(d.size, 2); assert.equal(d.size, 2);
@ -162,13 +159,11 @@ run_test('clear', () => {
populate(); populate();
assert.equal(d.size, 2); assert.equal(d.size, 2);
assert(!d.is_empty());
d.clear(); d.clear();
assert.equal(d.get('foo'), undefined); assert.equal(d.get('foo'), undefined);
assert.equal(d.get('bar'), undefined); assert.equal(d.get('bar'), undefined);
assert.equal(d.size, 0); assert.equal(d.size, 0);
assert(d.is_empty());
// make sure it still works after clearing // make sure it still works after clearing
populate(); populate();

View File

@ -4,13 +4,13 @@ set_global('blueslip', global.make_zblueslip());
run_test('basic', () => { run_test('basic', () => {
const d = new FoldDict(); const d = new FoldDict();
assert(d.is_empty()); assert.equal(d.size, 0);
assert.deepEqual(d.keys(), []); assert.deepEqual(d.keys(), []);
d.set('foo', 'bar'); d.set('foo', 'bar');
assert.equal(d.get('foo'), 'bar'); assert.equal(d.get('foo'), 'bar');
assert(!d.is_empty()); assert.notEqual(d.size, 0);
d.set('foo', 'baz'); d.set('foo', 'baz');
assert.equal(d.get('foo'), 'baz'); assert.equal(d.get('foo'), 'baz');
@ -71,13 +71,11 @@ run_test('clear', () => {
populate(); populate();
assert.equal(d.size, 2); assert.equal(d.size, 2);
assert(!d.is_empty());
d.clear(); d.clear();
assert.equal(d.get('fOO'), undefined); assert.equal(d.get('fOO'), undefined);
assert.equal(d.get('bAR'), undefined); assert.equal(d.get('bAR'), undefined);
assert.equal(d.size, 0); assert.equal(d.size, 0);
assert(d.is_empty());
// make sure it still works after clearing // make sure it still works after clearing
populate(); populate();

View File

@ -4,13 +4,13 @@ const IntDict = zrequire('int_dict').IntDict;
run_test('basic', () => { run_test('basic', () => {
const d = new IntDict(); const d = new IntDict();
assert(d.is_empty()); assert.equal(d.size, 0);
assert.deepEqual(d.keys(), []); assert.deepEqual(d.keys(), []);
d.set(101, 'bar'); d.set(101, 'bar');
assert.equal(d.get(101), 'bar'); assert.equal(d.get(101), 'bar');
assert(!d.is_empty()); assert.notEqual(d.size, 0);
d.set(101, 'baz'); d.set(101, 'baz');
assert.equal(d.get(101), 'baz'); assert.equal(d.get(101), 'baz');
@ -131,15 +131,12 @@ run_test('non integers', () => {
run_test('num_items', () => { run_test('num_items', () => {
const d = new IntDict(); const d = new IntDict();
assert.equal(d.size, 0); assert.equal(d.size, 0);
assert(d.is_empty());
d.set(101, 1); d.set(101, 1);
assert.equal(d.size, 1); assert.equal(d.size, 1);
assert(!d.is_empty());
d.set(101, 2); d.set(101, 2);
assert.equal(d.size, 1); assert.equal(d.size, 1);
assert(!d.is_empty());
d.set(102, 1); d.set(102, 1);
assert.equal(d.size, 2); assert.equal(d.size, 2);
@ -159,13 +156,11 @@ run_test('clear', () => {
populate(); populate();
assert.equal(d.size, 2); assert.equal(d.size, 2);
assert(!d.is_empty());
d.clear(); d.clear();
assert.equal(d.get(101), undefined); assert.equal(d.get(101), undefined);
assert.equal(d.get(102), undefined); assert.equal(d.get(102), undefined);
assert.equal(d.size, 0); assert.equal(d.size, 0);
assert(d.is_empty());
// make sure it still works after clearing // make sure it still works after clearing
populate(); populate();

View File

@ -34,10 +34,6 @@ export class Dict<V> {
return this._items.size; return this._items.size;
} }
is_empty(): boolean {
return this._items.size === 0;
}
each(f: (v: V, k?: string) => void): void { each(f: (v: V, k?: string) => void): void {
this._items.forEach(f); this._items.forEach(f);
} }

View File

@ -54,10 +54,6 @@ export class FoldDict<V> {
return this._items.size; return this._items.size;
} }
is_empty(): boolean {
return this._items.size === 0;
}
each(f: (v: V, k?: string) => void): void { each(f: (v: V, k?: string) => void): void {
this._items.forEach(({k, v}) => f(v, k)); this._items.forEach(({k, v}) => f(v, k));
} }

View File

@ -66,10 +66,6 @@ export class IntDict<V> {
return this._map.size; return this._map.size;
} }
is_empty(): boolean {
return this._map.size === 0;
}
each(f: (v: V, k?: number) => void): void { each(f: (v: V, k?: number) => void): void {
this._map.forEach(f); this._map.forEach(f);
} }

View File

@ -56,7 +56,7 @@ exports.topic_history = function (stream_id) {
const self = {}; const self = {};
self.has_topics = function () { self.has_topics = function () {
return !topics.is_empty(); return topics.size !== 0;
}; };
self.add_or_update = function (opts) { self.add_or_update = function (opts) {