data-structure-typed 1.46.1 → 1.46.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/benchmark/report.html +1 -46
- package/benchmark/report.json +16 -385
- package/dist/cjs/data-structures/hash/hash-map.d.ts +10 -91
- package/dist/cjs/data-structures/hash/hash-map.js +22 -178
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +358 -24
- package/dist/cjs/data-structures/queue/deque.js +380 -96
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/types/helpers.d.ts +2 -2
- package/dist/mjs/data-structures/hash/hash-map.d.ts +10 -91
- package/dist/mjs/data-structures/hash/hash-map.js +22 -181
- package/dist/mjs/data-structures/queue/deque.d.ts +358 -24
- package/dist/mjs/data-structures/queue/deque.js +376 -94
- package/dist/mjs/types/helpers.d.ts +2 -2
- package/dist/umd/data-structure-typed.js +433 -303
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/hash/hash-map.ts +25 -196
- package/src/data-structures/queue/deque.ts +401 -113
- package/src/types/helpers.ts +2 -2
- package/test/performance/data-structures/hash/hash-map.test.ts +11 -11
- package/test/performance/reportor.ts +6 -3
- package/test/unit/data-structures/hash/hash-map.test.ts +4 -5
- package/test/unit/data-structures/queue/deque.test.ts +28 -0
package/src/types/helpers.ts
CHANGED
|
@@ -16,11 +16,11 @@ export const enum IterateDirection {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export interface IterableWithSize<T> extends Iterable<T> {
|
|
19
|
-
size: number;
|
|
19
|
+
size: number | ((...args: any[]) => number);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
23
|
-
length: number;
|
|
23
|
+
length: number | ((...args: any[]) => number);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>
|
|
@@ -5,42 +5,42 @@ import { magnitude } from '../../../utils';
|
|
|
5
5
|
import { isCompetitor } from '../../../config';
|
|
6
6
|
|
|
7
7
|
const suite = new Benchmark.Suite();
|
|
8
|
-
const {
|
|
8
|
+
const { MILLION } = magnitude;
|
|
9
9
|
|
|
10
|
-
suite.add(`${
|
|
10
|
+
suite.add(`${MILLION.toLocaleString()} set`, () => {
|
|
11
11
|
const hm = new HashMap<number, number>();
|
|
12
12
|
|
|
13
|
-
for (let i = 0; i <
|
|
13
|
+
for (let i = 0; i < MILLION; i++) {
|
|
14
14
|
hm.set(i, i);
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
17
|
if (isCompetitor) {
|
|
18
|
-
suite.add(`${
|
|
18
|
+
suite.add(`${MILLION.toLocaleString()} CPT set`, () => {
|
|
19
19
|
const hm = new CHashMap<number, number>();
|
|
20
20
|
|
|
21
|
-
for (let i = 0; i <
|
|
21
|
+
for (let i = 0; i < MILLION; i++) {
|
|
22
22
|
hm.setElement(i, i);
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
suite.add(`${
|
|
26
|
+
suite.add(`${MILLION.toLocaleString()} set & get`, () => {
|
|
27
27
|
const hm = new HashMap<number, number>();
|
|
28
28
|
|
|
29
|
-
for (let i = 0; i <
|
|
29
|
+
for (let i = 0; i < MILLION; i++) {
|
|
30
30
|
hm.set(i, i);
|
|
31
31
|
}
|
|
32
|
-
for (let i = 0; i <
|
|
32
|
+
for (let i = 0; i < MILLION; i++) {
|
|
33
33
|
hm.get(i);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
if (isCompetitor) {
|
|
37
|
-
suite.add(`${
|
|
37
|
+
suite.add(`${MILLION.toLocaleString()} CPT set & get`, () => {
|
|
38
38
|
const hm = new CHashMap<number, number>();
|
|
39
39
|
|
|
40
|
-
for (let i = 0; i <
|
|
40
|
+
for (let i = 0; i < MILLION; i++) {
|
|
41
41
|
hm.setElement(i, i);
|
|
42
42
|
}
|
|
43
|
-
for (let i = 0; i <
|
|
43
|
+
for (let i = 0; i < MILLION; i++) {
|
|
44
44
|
hm.getElementByKey(i);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
@@ -25,17 +25,20 @@ const reportDistPath = path.join(parentDirectory, 'benchmark');
|
|
|
25
25
|
|
|
26
26
|
const testDir = path.join(__dirname, 'data-structures');
|
|
27
27
|
const allFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts'));
|
|
28
|
-
let testFiles: string[]
|
|
28
|
+
let testFiles: string[];
|
|
29
|
+
|
|
30
|
+
let isIndividual = false;
|
|
29
31
|
if (args.length > 0) {
|
|
30
32
|
console.log(`arguments: ${args.join(' ')}`)
|
|
31
33
|
|
|
32
34
|
testFiles = allFiles.filter(file =>
|
|
33
35
|
args.every(word => file.includes(word))
|
|
34
36
|
);
|
|
35
|
-
|
|
37
|
+
isIndividual = true;
|
|
36
38
|
console.log(`${testFiles.map(file => coloredLabeled('Matched', file)).join(`
|
|
37
39
|
`)}`);
|
|
38
40
|
} else {
|
|
41
|
+
isIndividual = false;
|
|
39
42
|
testFiles = allFiles;
|
|
40
43
|
}
|
|
41
44
|
|
|
@@ -129,7 +132,7 @@ const composeReport = () => {
|
|
|
129
132
|
html += `</div>
|
|
130
133
|
</body>
|
|
131
134
|
</html>`;
|
|
132
|
-
replaceMarkdownContent(
|
|
135
|
+
if (!isIndividual) replaceMarkdownContent(
|
|
133
136
|
'[//]: # (No deletion!!! Start of Replace Section)', // Start tag
|
|
134
137
|
'[//]: # (No deletion!!! End of Replace Section)', // end identifier
|
|
135
138
|
htmlTables // New content to be inserted
|
|
@@ -172,15 +172,14 @@ describe('HashMap', () => {
|
|
|
172
172
|
stdMap.forEach((value, key) => {
|
|
173
173
|
if (index === 0) {
|
|
174
174
|
expect(hashMap.first).toEqual([key, value]);
|
|
175
|
-
expect(hashMap.begin.
|
|
175
|
+
expect(hashMap.begin().next().value).toEqual([key, value]);
|
|
176
176
|
} else if (index === hashMap.size - 1) {
|
|
177
177
|
expect(hashMap.last).toEqual([key, value]);
|
|
178
|
-
expect(hashMap.reverseBegin.
|
|
178
|
+
expect(hashMap.reverseBegin().next().value).toEqual([key, value]);
|
|
179
179
|
} else if (index <= 1000) {
|
|
180
180
|
expect(hashMap.getAt(index)).toEqual([key, value]);
|
|
181
181
|
}
|
|
182
182
|
expect(hashMap.get(key)).toEqual(value);
|
|
183
|
-
expect(hashMap.getIterator(key).current[1]).toEqual(value);
|
|
184
183
|
index++;
|
|
185
184
|
});
|
|
186
185
|
}
|
|
@@ -210,8 +209,8 @@ describe('HashMap', () => {
|
|
|
210
209
|
test('should iterate correctly with reverse iterators', () => {
|
|
211
210
|
hashMap.set('key1', 'value1');
|
|
212
211
|
hashMap.set('key2', 'value2');
|
|
213
|
-
const iterator = hashMap.reverseBegin;
|
|
214
|
-
expect(iterator.next().
|
|
212
|
+
const iterator = hashMap.reverseBegin();
|
|
213
|
+
expect(iterator.next().value).toEqual(['key2', 'value2']);
|
|
215
214
|
});
|
|
216
215
|
|
|
217
216
|
test('should return the last element', () => {
|
|
@@ -419,4 +419,32 @@ describe('Deque', () => {
|
|
|
419
419
|
expect(deque.indexOf(2)).toBe(1);
|
|
420
420
|
expect(deque.indexOf(4)).toBe(-1);
|
|
421
421
|
});
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
//Test begin method
|
|
425
|
+
describe('begin()', () => {
|
|
426
|
+
it('should return an iterator at the beginning of the deque', () => {
|
|
427
|
+
deque.push(1);
|
|
428
|
+
deque.push(2);
|
|
429
|
+
deque.push(3);
|
|
430
|
+
|
|
431
|
+
const iterator = deque.begin();
|
|
432
|
+
|
|
433
|
+
expect(iterator.next().value).toBe(1);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
// Test the reverse Begin method
|
|
438
|
+
describe('reverseBegin()', () => {
|
|
439
|
+
it('should return a reverse iterator at the beginning of the deque', () => {
|
|
440
|
+
deque.push(1);
|
|
441
|
+
deque.push(2);
|
|
442
|
+
deque.push(3);
|
|
443
|
+
|
|
444
|
+
const iterator = deque.reverseBegin();
|
|
445
|
+
|
|
446
|
+
expect(iterator.next().value).toBe(3);
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
|
|
422
450
|
});
|