Add `ChunkedSortedStringSet::first()`. `LinearSortedStringSet::first()` already exists. The first element is stored contiguously, so a simple accessor returning `absl::string_view` is possible. PiperOrigin-RevId: 901838348
diff --git a/riegeli/containers/chunked_sorted_string_set.h b/riegeli/containers/chunked_sorted_string_set.h index 0d9cd73..1a080a3 100644 --- a/riegeli/containers/chunked_sorted_string_set.h +++ b/riegeli/containers/chunked_sorted_string_set.h
@@ -248,6 +248,13 @@ return chunks_.empty() ? 0 : chunks_.back().cumulative_end_index; } + // Returns the first element. The set must not be empty. + absl::string_view first() const ABSL_ATTRIBUTE_LIFETIME_BOUND { + RIEGELI_ASSERT(!empty()) + << "Failed precondition of ChunkedSortedStringSet::first(): empty set"; + return chunks_.front().set.first(); + } + // Returns `true` if `element` is present in the set. // // If `index != nullptr`, sets `*index` to the index of `element` in the set,
diff --git a/riegeli/containers/linear_sorted_string_set.cc b/riegeli/containers/linear_sorted_string_set.cc index 6166de4..3af424d 100644 --- a/riegeli/containers/linear_sorted_string_set.cc +++ b/riegeli/containers/linear_sorted_string_set.cc
@@ -141,8 +141,7 @@ absl::string_view LinearSortedStringSet::first() const ABSL_ATTRIBUTE_LIFETIME_BOUND { RIEGELI_ASSERT(!empty()) - << "Failed precondition of LinearSortedStringSet::first(): " - "empty set"; + << "Failed precondition of LinearSortedStringSet::first(): empty set"; const absl::string_view encoded_view = encoded_; uint64_t tagged_length; const size_t tagged_length_length =