CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How can I make my algorithm for finding duplicates more OpenFOAMic (https://www.cfd-online.com/Forums/openfoam-programming-development/211637-how-can-i-make-my-algorithm-finding-duplicates-more-openfoamic.html)

vkoppejan November 16, 2018 13:11

How can I make my algorithm for finding duplicates more OpenFOAMic
 
Dear All,

I've coded the following algorithm to find duplicate entries in a List or Field of vectors.

I first concatenate the coordinates into a string, compute the hash of this string and then request the uniqueOrder of the container of hashes.

However I can't do this without std::string, std::to_string and std::hash. Any tips on how to do this using builtin OpenFOAM structures and functions?

Thanks in advance,

Victor

Code:

    List<label> pointBasedStencil::findUniquePoints(const Field<vector>& src)
    {
        // create hashes for entries in list using to_string
        List<label> hashlist;
        std::hash<std::string> hf;
        forAll(src,i) {
            std::string s(std::to_string(src[i].x() )
                          + std::to_string(src[i].y() )
                          + std::to_string(src[i].z() )
                            );
            hashlist.append(hf(s) );
        }

        // find unique indices
        List<label> order;
        uniqueOrder(hashlist, order);
        return order;
    }



All times are GMT -4. The time now is 23:11.