Skip to content

Commit

Permalink
chore: change firefox to 45
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLY201 committed Jun 13, 2023
1 parent 1dc2094 commit 8d25fd1
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
- name: Setup firefox
uses: browser-actions/setup-firefox@latest
with:
firefox-version: '36.0'
firefox-version: '45.0'
- name: Run firefox test
run: FIREFOX_BIN=$(which firefox) yarn test:firefox
browser-edge-test:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ We are benchmarking against other popular data structure libraries. In some ways

| ![][Edge-Icon]<br/>IE / Edge | ![][Firefox-Icon]<br/>Firefox | ![][Chrome-Icon]<br/>Chrome | ![][Safari-Icon]<br/>Safari | ![][Opera-Icon]<br/>Opera | ![][NodeJs-Icon]<br/>NodeJs |
|:----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------:|:-------------------------:|:---------------------------:|
| Edge 12 | 36 | 49 | 10 | 36 | 10 |
| Edge 12 | 45 | 49 | 10 | 36 | 10 |

## 📦 Download

Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

| ![][Edge-Icon]<br/>IE / Edge | ![][Firefox-Icon]<br/>Firefox | ![][Chrome-Icon]<br/>Chrome | ![][Safari-Icon]<br/>Safari | ![][Opera-Icon]<br/>Opera | ![][NodeJs-Icon]<br/>NodeJs |
|:----------------------------:|:-----------------------------:|:---------------------------:|:---------------------------:|:-------------------------:|:---------------------------:|
| Edge 12 | 36 | 49 | 10 | 36 | 10 |
| Edge 12 | 45 | 49 | 10 | 36 | 10 |

## 📦 下载

Expand Down
13 changes: 0 additions & 13 deletions perf/sequential-perf/coomon.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ function testSequentialContainer(container: SequentialContainer<number>, testNum
if (container.constructor.name === 'LinkList') {
_testNum = Math.min(testNum, 1000);
}

startTime = Date.now();
for (let i = 0; i < _testNum; ++i) {
container.unsafe_at(i);
}
endTime = Date.now();
reportList.push({
testFunc: 'unsafe_at',
testNum: _testNum,
containerSize: container.length,
runTime: endTime - startTime
});

startTime = Date.now();
for (let i = 0; i < _testNum; ++i) {
container.at(i);
Expand Down
4 changes: 2 additions & 2 deletions src/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export abstract class Container<T> extends Base {
* container.forEach((item, index) => console.log(item, index));
*/
abstract forEach(callback: (value: T, index: number, container: this) => void): void;
abstract unsafe_at(index: number): T;
protected abstract _at(index: number): T;
/**
* @description Gets the value of the item at the specified position.
* @example
Expand All @@ -121,7 +121,7 @@ export abstract class Container<T> extends Base {
return undefined;
}
}
return this.unsafe_at(index);
return this._at(index);
}
/**
* @description Removes item by iterator and move `iter` to next.
Expand Down
2 changes: 1 addition & 1 deletion src/hash/hash-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class HashMap<K, V> extends HashContainer<K, V> {
const node = this._originMap[<string><unknown>key];
return node ? node._value : undefined;
}
unsafe_at(index: number) {
protected _at(index: number) {
let node = this._head;
while (index--) {
node = node._next;
Expand Down
2 changes: 1 addition & 1 deletion src/hash/hash-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class HashSet<K> extends HashContainer<K, undefined> {
add(key: K, isObject?: boolean) {
return this._set(key, undefined, isObject);
}
unsafe_at(index: number) {
protected _at(index: number) {
let node = this._head;
while (index--) {
node = node._next;
Expand Down
67 changes: 18 additions & 49 deletions src/sequential/deque.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ class Deque<T> extends SequentialContainer<T> {
* @internal
*/
private _map: T[][] = [];
/**
* @description Please clear the cache when `first|bucketSize|bucketNum` changed.
* @internal
*/
// private _positionCache: Record<number, Position | undefined> = {};
constructor(entries: Entries<T> = [], options: {
bucketSize?: number
} = {}) {
Expand All @@ -89,7 +84,6 @@ class Deque<T> extends SequentialContainer<T> {
entries.forEach(function (item) {
self._push(item);
});
// this._positionCache = {};
}
/**
* @description Growth the Deque.
Expand All @@ -114,7 +108,6 @@ class Deque<T> extends SequentialContainer<T> {
newMap[newMap.length] = new Array(this._bucketSize);
}
this._map = newMap;
// this._positionCache = {};
this._bucketNum = newMap.length;
}
private _getPrevPosition(position: Position): Position {
Expand Down Expand Up @@ -158,32 +151,12 @@ class Deque<T> extends SequentialContainer<T> {
y = this._bucketSize - 1;
}
return { x, y };
// const cache = this._positionCache[index];
// if (cache) {
// return cache;
// } else if (this._positionCache[index - 1]) {
// this._positionCache[index] = this._getNextPosition(this._positionCache[index - 1]!);
// } else if (this._positionCache[index + 1]) {
// this._positionCache[index] = this._getPrevPosition(this._positionCache[index + 1]!);
// } else {
// let x, y;
// const realIndex = this._first.y + index + 1;
// x = this._first.x + Math.ceil(realIndex, this._bucketSize) - 1;
// x %= this._bucketNum;
// y = realIndex % this._bucketSize - 1;
// if (y < 0) {
// y = this._bucketSize - 1;
// }
// this._positionCache[index] = { x, y };
// }
// return this._positionCache[index]!;
}
clear() {
this._map = [new Array(this._bucketSize)];
this._bucketNum = 1;
this._first.x = this._last.x = this._length = 0;
this._first.y = this._last.y = this._bucketSize >> 1;
// this._positionCache = {};
}
begin() {
return new DequeIterator<T>({
Expand Down Expand Up @@ -264,7 +237,6 @@ class Deque<T> extends SequentialContainer<T> {
) this._reAllocate();
}
this._length += 1;
// this._positionCache = {};
this._map[this._first.x][this._first.y] = item;
}
unshift(...items: T[]) {
Expand All @@ -286,10 +258,9 @@ class Deque<T> extends SequentialContainer<T> {
this._first = this._getNextPosition(this._first);
}
this._length -= 1;
// this._positionCache = {};
return item;
}
unsafe_at(index: number) {
protected _at(index: number) {
const { x, y } = this._calcPosition(index);
return this._map[x][y]!;
}
Expand Down Expand Up @@ -324,7 +295,7 @@ class Deque<T> extends SequentialContainer<T> {
}
find(item: T, cmp: CompareFn<T> = compareFromS2L) {
for (let i = 0; i < this._length; ++i) {
if (cmp(this.unsafe_at(i), item) === 0) {
if (cmp(this._at(i), item) === 0) {
return new DequeIterator<T>({
node: i,
container: this
Expand All @@ -342,7 +313,6 @@ class Deque<T> extends SequentialContainer<T> {
this._last.x = this._bucketNum - firstX - 1;
this._first.y = this._bucketSize - lastY - 1;
this._last.y = this._bucketSize - firstY - 1;
// this._positionCache = {};
return this;
}
unique(cmp: CompareFn<T> = compareFromS2L) {
Expand All @@ -351,9 +321,9 @@ class Deque<T> extends SequentialContainer<T> {
return length;
}
let index = 1;
let prev = this.unsafe_at(0);
let prev = this._at(0);
for (let i = 1; i < length; ++i) {
const cur = this.unsafe_at(i);
const cur = this._at(i);
if (cmp(cur, prev) !== 0) {
prev = cur;
this._set(index++, cur);
Expand All @@ -366,7 +336,7 @@ class Deque<T> extends SequentialContainer<T> {
const arr: T[] = [];
const length = this._length;
for (let i = 0; i < length; ++i) {
arr.push(this.unsafe_at(i));
arr.push(this._at(i));
}
arr.sort(cmp);
for (let i = 0; i < length; ++i) {
Expand Down Expand Up @@ -397,18 +367,17 @@ class Deque<T> extends SequentialContainer<T> {
this._last.x = newMap.length - 1;
this._bucketNum = newMap.length;
this._map = newMap;
// this._positionCache = {};
}
forEach(callback: (value: T, index: number, container: this) => void) {
const length = this._length;
for (let i = 0; i < length; ++i) {
callback(this.unsafe_at(i), i, this);
callback(this._at(i), i, this);
}
}
* [Symbol.iterator]() {
const length = this._length;
for (let i = 0; i < length; ++i) {
yield this.unsafe_at(i);
yield this._at(i);
}
}
entries(): IterableIterator<[number, T]> {
Expand All @@ -423,7 +392,7 @@ class Deque<T> extends SequentialContainer<T> {
value: undefined as unknown as [number, T]
};
}
const value = <[number, T]>[index, self.unsafe_at(index)];
const value = <[number, T]>[index, self._at(index)];
index += 1;
return {
done,
Expand All @@ -438,7 +407,7 @@ class Deque<T> extends SequentialContainer<T> {
every(callback: (value: T, index: number, container: this) => unknown): boolean {
const length = this._length;
for (let i = 0; i < length; ++i) {
const flag = callback(this.unsafe_at(i), i, this);
const flag = callback(this._at(i), i, this);
if (!flag) return false;
}
return true;
Expand All @@ -449,7 +418,7 @@ class Deque<T> extends SequentialContainer<T> {
});
const length = this._length;
for (let i = 0; i < length; ++i) {
const item = this.unsafe_at(i);
const item = this._at(i);
const flag = callback(item, i, this);
if (flag) filtered._push(item);
}
Expand All @@ -461,7 +430,7 @@ class Deque<T> extends SequentialContainer<T> {
});
const length = this._length;
for (let i = 0; i < length; ++i) {
const item = this.unsafe_at(i);
const item = this._at(i);
const newItem = callback(item, i, this);
mapped._push(newItem);
}
Expand All @@ -483,14 +452,14 @@ class Deque<T> extends SequentialContainer<T> {
if (end < 0) end += length;
else if (end > length) end = length;
for (let i = start; i < end; ++i) {
sliceDeque._push(this.unsafe_at(i));
sliceDeque._push(this._at(i));
}
return sliceDeque;
}
some(callback: (value: T, index: number, container: this) => unknown): boolean {
const length = this._length;
for (let i = 0; i < length; ++i) {
const flag = callback(this.unsafe_at(i), i, this);
const flag = callback(this._at(i), i, this);
if (flag) return true;
}
return false;
Expand Down Expand Up @@ -533,20 +502,20 @@ class Deque<T> extends SequentialContainer<T> {
const delta = addCount - deleteCount;
// record delete items
for (let i = start; i < end; ++i) {
deleteDeque._push(this.unsafe_at(i));
deleteDeque._push(this._at(i));
}
// addCount greater than deleteCount, move back
if (delta > 0) {
for (let i = length - delta; i < length; ++i) {
this._push(this.unsafe_at(i));
this._push(this._at(i));
}
for (let i = length - delta - 1; i >= end; --i) {
this._set(i + delta, this.unsafe_at(i));
this._set(i + delta, this._at(i));
}
} /* else, move front */ else if (delta < 0) {
const endIndex = length + delta - 1;
for (let i = end + delta; i <= endIndex; ++i) {
this._set(i, this.unsafe_at(i - delta));
this._set(i, this._at(i - delta));
}
// change length after delete
this._length += delta;
Expand All @@ -570,7 +539,7 @@ class Deque<T> extends SequentialContainer<T> {
done
};
}
const value = self.unsafe_at(index);
const value = self._at(index);
index += 1;
return {
value,
Expand Down
2 changes: 1 addition & 1 deletion src/sequential/link-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class LinkList<T> extends SequentialContainer<T> {
back(): T | undefined {
return this._tail._value;
}
unsafe_at(index: number) {
_at(index: number) {
let curNode = this._head;
while (index--) {
curNode = curNode._next;
Expand Down
2 changes: 1 addition & 1 deletion src/sequential/vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Vector<T> extends SequentialContainer<T> {
back(): T | undefined {
return this._vector[this._length - 1];
}
unsafe_at(index: number) {
protected _at(index: number) {
return this._vector[index];
}
erase(iter: VectorIterator<T>) {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/ordered-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class OrderedMap<K, V> extends TreeContainer<K, V> {
set(key: K, value: V, hint?: OrderedMapIterator<K, V>) {
return this._set(key, value, hint);
}
unsafe_at(index: number) {
_at(index: number) {
const node = this._inOrderTraversal(index);
return <[K, V]>[node._key, node._value];
}
Expand Down
2 changes: 1 addition & 1 deletion src/tree/ordered-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class OrderedSet<K> extends TreeContainer<K, undefined> {
add(key: K, hint?: OrderedSetIterator<K>) {
return this._set(key, undefined, hint);
}
unsafe_at(index: number) {
_at(index: number) {
const node = this._inOrderTraversal(index);
return node._key as K;
}
Expand Down

0 comments on commit 8d25fd1

Please sign in to comment.