<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query(self, rank):
 """Retrieves the value estimate for the requested quantile rank. The requested quantile rank must be registered in the estimator's invariants a priori! Args: rank: A floating point quantile rank along the interval [0, 1]. Returns: A numeric value for the quantile estimate. """

        self._flush()

        current = self._head
        if not current:
          return 0

        mid_rank = math.floor(rank * self._observations)
        max_rank = mid_rank + math.floor(
            self._invariant(mid_rank, self._observations) / 2)

        rank = 0.0
        while current._successor:
            rank += current._rank
            if rank + current._successor._rank + current._successor._delta > max_rank:
                return current._value

            current = current._successor

        return current._value