1

While studying the Go back n protocol,in a part of the C code its written :

static boolean between(seq _nr a, seq _nr b, seq _nr c)
{
/
* Return true if a <= b < c circularly; false otherwise.*/
if (((a <= b) && (b < c)) || ((c < a) && (a <= b)) || ((b < c) && (c < a)))
return(true);
else
return(false);
}

What does this mean,can you explain it to me?

user3543012
  • 111
  • 2
  • 11

1 Answers1

3

It's a ring buffer containment test. There are a limited number of ordering permutations of 3 positions within a linear memory space, and only 5 of those permutations have position b after or equal to position a and before position c when the linear space is joined at the ends. The condition in the code simply verifies that one of those 5 permutations is in effect.

Ignacio Vazquez-Abrams
  • 48,488
  • 4
  • 73
  • 103