| 240 | self._histogram_by_domain[domain][tier] += 10 |
| 241 | |
| 242 | def predict_tier(self, domain: str) -> int: |
| 243 | histogram = self._histogram_by_domain[domain] |
| 244 | current_tier = self._current_tier_by_domain[domain] |
| 245 | |
| 246 | for index, value in enumerate(histogram): |
| 247 | if index == current_tier: |
| 248 | continue |
| 249 | if value > 0: |
| 250 | histogram[index] -= 1 |
| 251 | |
| 252 | left = histogram[current_tier - 1] if current_tier > 0 else float('inf') |
| 253 | right = histogram[current_tier + 1] if current_tier < len(histogram) - 1 else float('inf') |
| 254 | |
| 255 | if histogram[current_tier] > min(left, right): |
| 256 | self._current_tier_by_domain[domain] = current_tier - 1 if left <= right else current_tier + 1 |
| 257 | elif histogram[current_tier] == left: |
| 258 | self._current_tier_by_domain[domain] -= 1 |
| 259 | |
| 260 | return self._current_tier_by_domain[domain] |
| 261 | |
| 262 | |
| 263 | class _NewUrlFunction(Protocol): |