Find cell neighbors of a given edge in a 2D grid
There's no need for any special algorithm.  There are only 12 edges, so it's enough to simply use a switch statement with 12 cases.  Or, you can use 12 if statements.  Any of these will have $O(1)$ running time, since there are only finitely many cases, so they are (asymptotically) as good as any other "algorithm".