Add QpackHeaderTable::draining_index().
gfe-relnote: n/a, change to QUIC v99-only code. Protected by existing disabled
gfe2_reloadable_flag_quic_enable_version_99.
PiperOrigin-RevId: 259954990
Change-Id: I896a5b039f2d61e7b4e9f97299b9ebb2234e2820
diff --git a/quic/core/qpack/qpack_header_table.cc b/quic/core/qpack/qpack_header_table.cc
index 6fa6412..92eb072 100644
--- a/quic/core/qpack/qpack_header_table.cc
+++ b/quic/core/qpack/qpack_header_table.cc
@@ -173,6 +173,31 @@
observers_.push({observer, required_insert_count});
}
+uint64_t QpackHeaderTable::draining_index(float draining_fraction) const {
+ DCHECK_LE(0.0, draining_fraction);
+ DCHECK_LE(draining_fraction, 1.0);
+
+ const uint64_t required_space = draining_fraction * dynamic_table_capacity_;
+ uint64_t space_above_draining_index =
+ dynamic_table_capacity_ - dynamic_table_size_;
+
+ if (dynamic_entries_.empty() ||
+ space_above_draining_index >= required_space) {
+ return dropped_entry_count_;
+ }
+
+ auto it = dynamic_entries_.begin();
+ while (space_above_draining_index < required_space) {
+ space_above_draining_index += it->Size();
+ ++it;
+ if (it == dynamic_entries_.end()) {
+ return inserted_entry_count();
+ }
+ }
+
+ return it->InsertionIndex();
+}
+
bool QpackHeaderTable::ObserverWithThreshold::operator>(
const ObserverWithThreshold& other) const {
return required_insert_count > other.required_insert_count;