Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on tree containers inserting element with hint iterator #40

Closed
bpinzone opened this issue Jul 10, 2019 · 1 comment
Closed

Error on tree containers inserting element with hint iterator #40

bpinzone opened this issue Jul 10, 2019 · 1 comment
Assignees
Labels
bug Something isn't working enhancement New feature or request
Projects

Comments

@bpinzone
Copy link

Bug Report

Summary

  • TSTL Version: 2.2.0
  • Expected behavior: Set union should succeed then log 1, 2.
  • Actual behavior: Uncaught exception occurs.

Code incurring the bug

import std = require("tstl");
function test_tstl(){
    let Set1: set<number> = new set<number>()
    let Vector1: vector<number> = new vector<number>()

    Vector1.push_back(1)
    Vector1.push_back(2)

    set_union(Set1.begin(), Set1.end(), Vector1.begin(), Vector1.end(), inserter(Set1, Set1.end()))

    for(let it = Set1.begin(); !it.equals(Set1.end()); it = it.next()){
        console.log(it.value)
    }

}

Stack Trace

Uncaught Exception:
TypeError: Cannot read property 'valueOf' of undefined
    at less (/node_modules/tstl/functional/comparators.js:43:11)
    at _UniqueSetTree.nearest_by_key (/node_modules/tstl/base/tree/_UniqueSetTree.js:49:32)
    at _UniqueSetTree._SetTree.lower_bound (/node_modules/tstl/base/tree/_SetTree.js:72:25)
    at TreeSet.lower_bound (/node_modules/tstl/container/TreeSet.js:100:27)
    at TreeSet.UniqueTreeSet._Insert_by_key (/node_modules/tstl/base/container/UniqueTreeSet.js:69:23)
    at TreeSet.UniqueTreeSet._Insert_by_hint (/node_modules/tstl/base/container/UniqueTreeSet.js:88:25)
    at TreeSet.SetContainer.insert (/node_modules/tstl/base/container/SetContainer.js:117:25)
    at TreeSet.UniqueSet.insert (/node_modules/tstl/base/container/UniqueSet.js:65:40)
    at InsertIterator.set [as value] (/node_modules/tstl/iterator/InsertIterator.js:48:29)
    at Object.copy (/node_modules/tstl/algorithm/modifiers.js:46:22

Desirable Behavior as in C++

int main() {
    set<int> Set1;
    vector<int> Vector1;

    Vector1.push_back(1);
    Vector1.push_back(2);

    set_union(Set1.begin(), Set1.end(), Vector1.begin(), Vector1.end(), inserter(Set1, Set1.end()));

    for(auto it = Set1.begin(); it != Set1.end(); ++it){
        cout << *it << endl;
    }
    // outputs "1\n2\n"

    return 0;
}
@samchon samchon self-assigned this Jul 11, 2019
@samchon samchon added bug Something isn't working enhancement New feature or request labels Jul 11, 2019
@samchon samchon added this to To do in v2.2 Update via automation Jul 11, 2019
@samchon
Copy link
Owner

samchon commented Jul 11, 2019

Thanks for your reporting. By your contribution, I could find an error returning invalid iterator when inserting element on tree based containers with hint iterator: TreeSet<T>.insert(hint: TreeSet.Iterator<T>, val: T).

66fadfa#diff-d7f3ab5398accffb17830e4643a8de65

I'm planning to publish the patch v2.2.1 on this weekend (maybe Sunday). If you can't wait the formal publish, you can consider the beta version:

npm install --save tstl@next

@samchon samchon moved this from To do to In progress in v2.2 Update Jul 11, 2019
@samchon samchon changed the title Inserter for set causing uncaught exception. Error on tree containers inserting element with hint iterator Jul 11, 2019
v2.2 Update automation moved this from In progress to Done Jul 14, 2019
@samchon samchon moved this from Done to Patch in v2.2 Update Jul 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
No open projects
v2.2 Update
  
Patch
Development

No branches or pull requests

2 participants