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.
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):
but the FileNodeIterator::operator+=(int) is not O(1) .It uses FOR to get i.