Skip to main content
. 2015 Mar 5;15(3):5474–5503. doi: 10.3390/s150305474
Algorithm 4. Search_Next_Hop (SHi), implemented at each sector head node.
Input: Target SHi, where SHi ∈ [1...S], m- number of tracks (rows) and n- number of sectors per track (columns)
Output: Next Hop SHk, where SHk ∈ [1...S],
1:   //Finding the row and column position of //destination sector head and current head in the //grid
2:   destCol ← SHi%n;
3:   destRow ← SHi/n;
4:   curCol ← nextHopCol ← (SELF_NET_ADDR)%n
5:   curRow ← nextHopRow ← (SELF_NET_ADDR)/n
6:   SHk ← −1
7:    //Moving the packet to the same column where //destination sector lies
8:    if curCol < destcol
9:       /*Move toward right */
10:     then nextHopCol ← nextHopCol + 1 
11:   else if curCol > destcol
12:     /*Move toward left */
13:     then nextHopCol ← nextHopCol − 1
14:   //It is in same column so move toward up or down
15:   else if curCol = destCol
16:     then if curRow < destRow
17:       /*Move vertically up*/
18:       then nextHopRownextHopRow + 1
19:     else if curRow > destRow
20:       /*Move vertically down*/
21:       then nextHopRownextHopRow − 1
22:     end if
23:  end if
24:  /*convert to sector number*/
25:  SHknextHopRow × n + nextHopCol
26:  Return SHk