Skip to content

Conversation

IronSublimate
Copy link

In OpenCV, cv::FileNode::operator and cv::FileNodeIterator::operator+=(int) has O(n) time complexity. So I changed fn[i] to iterator.The total time complexity is changed from O(n^2) to O(n)
The OpenCV FileNode code can find here.
In OpenCV4, the FileNode::operator calls FileNodeIterator::operator+=(int):

FileNode FileNode::operator[](int i) const
{
    if(!fs)
        return FileNode();

    CV_Assert( isSeq() );

    int sz = (int)size();
    CV_Assert( 0 <= i && i < sz );

    FileNodeIterator it = begin();
    it += i; //Here OpenCV use operator+=

    return *it;
}

but the FileNodeIterator::operator+=(int) is not O(1) .It uses FOR to get i.

FileNodeIterator& FileNodeIterator::operator += (int _ofs)
{
    CV_Assert( _ofs >= 0 );
    for( ; _ofs > 0; _ofs-- )
        this->operator ++();
    return *this;
}

@llschloesser
Copy link

@IronSublimate and @yhabib29 This same fix can be applied to improve database loading as well, yeah?

Copy link

@adishimoni8 adishimoni8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants