How to implement the function like the "adj" function or how to find its source code

The “adj“ function in mesh connectivity is very useful, which can find the adjacent triangle of the triangle k by edge e using only one statement “Th[k].adj(e)”.

I’m doing a FEM analysis work using Python rather than FreeFem++, and I wonder how to implement the “adj“ function when the mesh information is known, i.e., the mapping between mesh k and the corresponding vertex id is known?

Or is it possible to find the source code which implementing the “adj” function