Posts

Showing posts with the label std

Std Sort make std::vector invalid

Image
Clash Royale CLAN TAG #URR8PPP Std Sort make std::vector invalid I found a bug in std::sort and in some implementations of QuickSort in particular, I do not know whether the problem is in the algorithm in general. Essence: When the elements are less than 16 all the norms, because std::sort uses an insertion sort. When there are 17 or more elements, then quick sort is used with a restriction on the depth of recursion from the logarithm of the number of elements, but vector has time to deteriorate at the first __introsort_loop iteration. There is a vector spoilage when many identical elements. Corruption happened by replacement of valid iterators with invalid iterators. Other containers may break too, I did not check. An example for simplicity with a vector of type "int", for more complex objects - crash at the time of sorting, because the invalid object is passed to the comparison function: #include <iostream> #include <vector> #include <algorithm> void quick...

How to get VTK's tuple size from vtkDataArray

Image
Clash Royale CLAN TAG #URR8PPP How to get VTK's tuple size from vtkDataArray I'm trying to read all the data from all the tuples from a vtkDataArray class. However vtkDataArray::GetTuple as can be seen here returns a pointer to a double array. I'm wondering how can I get the size of that array. Seems like I'm missing an obvious solution. Code snipet: void doSomething(vtkSmartPointer<vtkDataArray> dataArray) { vtkIdType numTuples = dataArray->GetNumberOfTuples(); for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx) { double* tuple = dataArray->GetTuple(tupleIdx); for (int j = 0; j < ¿¿¿???; ++j} double var = tuple[j]; //Do something with var //Carefull don't go out of bounds } } 1 Answer 1 You need dataArray->GetNumberOfComponents() . If you know the number of components then it may be easi...

Are C++ std::hash implementations always deterministic?

Image
Clash Royale CLAN TAG #URR8PPP Are C++ std::hash implementations always deterministic? I know that std::hash<T> are implementation dependent, but are they supposed to be deterministic? std::hash<T> I know if I ran the std::hash<T> function on a value in the same process multiple times, I would get the same output. However, if I restarted the process, would I get the same value? Is there a seed that is used for std::hash? Does it depend on the compiler version, or some other factor? std::hash<T> Is there a guarantee that with an input X I will always get output Y regardless of when the process running was started, the machine, or the compiler version? X Y By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.