Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/js-sdsl/js-sdsl into feat/v5
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLY201 committed Jun 8, 2023
2 parents edd8e2d + 9448520 commit 19b114f
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 264 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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.1] - 2023.06.05

### Fixed

- Tree container with less than 3 items reverse iteration infinite loop

## [4.4.0] - 2023.03.17

### Changed
Expand Down
4 changes: 2 additions & 2 deletions conf/isolate.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
},
{
"name": "ordered-set",
"version": "4.4.0",
"version": "4.4.1",
"sourceRoot": "src/tree/ordered-set.ts"
},
{
"name": "ordered-map",
"version": "4.4.0",
"version": ""4.4.1",
"sourceRoot": "src/tree/ordered-map.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.0",
"version": "4.4.1",
"description": "javascript standard data structure library which benchmark against C++ STL",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
10 changes: 6 additions & 4 deletions src/tree/base/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ export class TreeNode<K, V> {
*/
_pre() {
let preNode: TreeNode<K, V> = this;
if (
preNode._color === TreeNodeColor.RED &&
preNode._parent!._parent === preNode
) {
const isRootOrHeader = preNode._parent!._parent === preNode;
if (isRootOrHeader && preNode._color === TreeNodeColor.RED) {
preNode = preNode._right!;
} else if (preNode._left) {
preNode = preNode._left;
while (preNode._right) {
preNode = preNode._right;
}
} else {
// Must be root and left is null
if (isRootOrHeader) {
return preNode._parent!;
}
let pre = preNode._parent!;
while (pre._left === preNode) {
preNode = pre;
Expand Down
16 changes: 16 additions & 0 deletions test/tree-test/ordered-set.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,20 @@ describe('OrderedSet test', () => {
expect(myOrderedSet.length).to.equal(0);
expect(() => myOrderedSet.erase(myOrderedSet.begin())).to.throw(RangeError);
});

it('OrderedSet iterator test', function () {
const st = new OrderedSet([1, 2, 3]);
for (let it = st.begin(), index = 1; !it.equals(st.end()); it.next()) {
expect(it.pointer).to.equal(index);
index += 1;
}
});

it('OrderedSet reverse iterator test', function () {
const st = new OrderedSet([2, 3]);
for (let it = st.rBegin(), index = 3; !it.equals(st.rEnd()); it.next()) {
expect(it.pointer).to.equal(index);
index -= 1;
}
});
});

0 comments on commit 19b114f

Please sign in to comment.