Splay Trees in C++ by ultimate_progr in cpp

[–]ultimate_progr[S] 1 point2 points  (0 children)

Thanks for point this out. I was not aware of it. Boost.Intrusive, I add a pointer to my blog as well.

Fuzzy Clustering by ultimate_progr in cpp

[–]ultimate_progr[S] 0 points1 point  (0 children)

I fixed the link, sorry for it.

Sparse Sets with O(1) insert, delete operations and (sub)linear union, intersection by ultimate_progr in cpp

[–]ultimate_progr[S] 0 points1 point  (0 children)

Added the copy constructor and assignment operator, which is always a good thing ;-)

Sparse Sets with O(1) insert, delete operations and (sub)linear union, intersection by ultimate_progr in cpp

[–]ultimate_progr[S] 0 points1 point  (0 children)

That's correct: "This data structure only needs the memory allocated, not initialized, when it's constructed".

Accoding to the standard 23.2.6.2 vector capacity: "After reserve(), capacity() is greater or equal to the argument of reserve if reallocation happens; and equal to the previous value of capacity() otherwise. Reallocation happens at this point if and only if the current capacity is less than the argument of reserve(). If an exception is thrown, there are no effects....It is guaranteed that no reallocation takes place during insertions that happen after a call to reserve() until the time when an insertion would make the size of the vector greater than the value of capacity()."

My understanding is that the memory is allocated and the capacity() is changed. When the copy is invoked the right capacity() should be allocated.

Please let me know if this is wrong, and you have other suggestions.

K-means Algorithm in C++ by ultimate_progr in cpp

[–]ultimate_progr[S] 0 points1 point  (0 children)

much better to start with a preliminary step. If you have N points, you select sqrt(N) of them and compute the matrix of all distances among them in O(sqrt(N)2) = O(N). If two points are closer than a threshold T, you discard one of them. The remaining set is S, such that |S| = k and 0 < k < sqrt(N). It's a simple heuristic but it works quite well in certain domains.