Skip to content

Commit

Permalink
build: publish@4.4.2
Browse files Browse the repository at this point in the history
build: publish@4.4.2
  • Loading branch information
ZLY201 committed Jul 21, 2023
2 parents 9448520 + cd27a06 commit 5662fb7
Show file tree
Hide file tree
Showing 14 changed files with 586 additions and 470 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

## [4.4.2] - 2023.07.21

### Fixed

- The pointer of Adapter container's iterator cannot as array to be deconstructed.

### Added

- Add `isAccessible` function to iterators for iterable containers.

## [4.4.1] - 2023.06.05

### Fixed
Expand Down
14 changes: 7 additions & 7 deletions conf/isolate.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,37 @@
},
{
"name": "vector",
"version": "4.4.0",
"version": "4.4.2",
"sourceRoot": "src/container/SequentialContainer/Vector.ts"
},
{
"name": "link-list",
"version": "4.4.0",
"version": "4.4.2",
"sourceRoot": "src/container/SequentialContainer/LinkList.ts"
},
{
"name": "deque",
"version": "4.4.0",
"version": "4.4.2",
"sourceRoot": "src/container/SequentialContainer/Deque.ts"
},
{
"name": "ordered-set",
"version": "4.4.1",
"version": "4.4.2",
"sourceRoot": "src/container/TreeContainer/OrderedSet.ts"
},
{
"name": "ordered-map",
"version": "4.4.1",
"version": "4.4.2",
"sourceRoot": "src/container/TreeContainer/OrderedMap.ts"
},
{
"name": "hash-set",
"version": "4.4.0",
"version": "4.4.2",
"sourceRoot": "src/container/HashContainer/HashSet.ts"
},
{
"name": "hash-map",
"version": "4.4.0",
"version": "4.4.2",
"sourceRoot": "src/container/HashContainer/HashMap.ts"
}
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-sdsl",
"version": "4.4.1",
"version": "4.4.2",
"description": "javascript standard data structure library which benchmark against C++ STL",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/container/ContainerBase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export abstract class ContainerIterator<T> {
* console.log(next.pointer, iter.pointer); // 2, 1
*/
abstract copy(): ContainerIterator<T>;
abstract isAccessible(): boolean;
}

export abstract class Base {
Expand Down
3 changes: 3 additions & 0 deletions src/container/HashContainer/Base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export abstract class HashContainerIterator<K, V> extends ContainerIterator<K |
};
}
}
isAccessible() {
return this._node !== this._header;
}
// @ts-ignore
pre(): this;
// @ts-ignore
Expand Down
15 changes: 9 additions & 6 deletions src/container/HashContainer/HashMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ class HashMapIterator<K, V> extends HashContainerIterator<K, V> {
}
const self = this;
return new Proxy(<[K, V]><unknown>[], {
get(_, props: '0' | '1') {
if (props === '0') return self._node._key;
else if (props === '1') return self._node._value;
get(target, prop: '0' | '1') {
if (prop === '0') return self._node._key;
else if (prop === '1') return self._node._value;
target[0] = self._node._key;
target[1] = self._node._value;
return target[prop];
},
set(_, props: '1', newValue: V) {
if (props !== '1') {
throw new TypeError('props must be 1');
set(_, prop: '1', newValue: V) {
if (prop !== '1') {
throw new TypeError('prop must be 1');
}
self._node._value = newValue;
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/container/SequentialContainer/Base/RandomIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export abstract class RandomIterator<T> extends ContainerIterator<T> {
set pointer(newValue: T) {
this.container.setElementByPos(this._node, newValue);
}
isAccessible() {
return this._node !== this.container.size();
}
// @ts-ignore
pre(): this;
// @ts-ignore
Expand Down
3 changes: 3 additions & 0 deletions src/container/SequentialContainer/LinkList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class LinkListIterator<T> extends ContainerIterator<T> {
copy() {
return new LinkListIterator<T>(this._node, this._header, this.container, this.iteratorType);
}
isAccessible() {
return this._node !== this._header;
}
// @ts-ignore
equals(iter: LinkListIterator<T>): boolean;
// @ts-ignore
Expand Down
3 changes: 3 additions & 0 deletions src/container/TreeContainer/Base/TreeIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ abstract class TreeIterator<K, V> extends ContainerIterator<K | [K, V]> {
}
return index;
}
isAccessible() {
return this._node !== this._header;
}
// @ts-ignore
pre(): this;
// @ts-ignore
Expand Down
15 changes: 9 additions & 6 deletions src/container/TreeContainer/OrderedMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ class OrderedMapIterator<K, V> extends TreeIterator<K, V> {
}
const self = this;
return new Proxy(<[K, V]><unknown>[], {
get(_, props: '0' | '1') {
if (props === '0') return self._node._key;
else if (props === '1') return self._node._value;
get(target, prop: '0' | '1') {
if (prop === '0') return self._node._key!;
else if (prop === '1') return self._node._value!;
target[0] = self._node._key!;
target[1] = self._node._value!;
return target[prop];
},
set(_, props: '1', newValue: V) {
if (props !== '1') {
throw new TypeError('props must be 1');
set(_, prop: '1', newValue: V) {
if (prop !== '1') {
throw new TypeError('prop must be 1');
}
self._node._value = newValue;
return true;
Expand Down
13 changes: 13 additions & 0 deletions test/HashContainerTest/HashMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ function hashMapTest(generateRandom: () => unknown) {
// @ts-ignore
// eslint-disable-next-line no-return-assign
expect(() => myHashMap.find(myHashMap.front()![0]).pointer[3] = 5).to.throw(TypeError);

expect(() => {
for (let it = myHashMap.begin(); !it.equals(myHashMap.end()); it.next()) {
const pointer = it.pointer;
const [key, value] = pointer;
expect(key).to.equal(pointer[0]);
expect(value).to.equal(pointer[1]);
pointer[1] = 2;
const [_key, _value] = pointer;
expect(_key).to.equal(pointer[0]);
expect(_value).to.equal(2);
}
}).to.not.throw(Error);
});

it('HashMap clear test', () => {
Expand Down
9 changes: 9 additions & 0 deletions test/OtherTest/iterator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,13 @@ describe('iterator test', () => {
expect(() => container.eraseElementByIterator(container.rEnd())).to.throw(RangeError);
}
});

it('isAccessible test', () => {
for (const container of containerArr) {
expect(container.begin().isAccessible()).to.equal(true);
expect(container.begin().next().isAccessible()).to.equal(true);
expect(container.end().isAccessible()).to.equal(false);
expect(container.end().pre().isAccessible()).to.equal(true);
}
});
});
15 changes: 15 additions & 0 deletions test/TreeContainerTest/OrderedMap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ describe('OrderedMap test', () => {
expect(mp.end().index).to.equal(mp.size() - 1);
});

it('OrderedMap iterator iterator test', () => {
expect(() => {
for (let it = myOrderedMap.begin(); !it.equals(myOrderedMap.end()); it.next()) {
const pointer = it.pointer;
const [key, value] = pointer;
expect(key).to.equal(pointer[0]);
expect(value).to.equal(pointer[1]);
pointer[1] = 2;
const [_key, _value] = pointer;
expect(_key).to.equal(pointer[0]);
expect(_value).to.equal(2);
}
}).to.not.throw(Error);
});

it('OrderedMap clear function test', () => {
myOrderedMap.clear();
stdMap.clear();
Expand Down
Loading

0 comments on commit 5662fb7

Please sign in to comment.