grpc 1.72.0 → 1.73.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1034) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +23 -6
  3. data/include/grpc/event_engine/event_engine.h +125 -8
  4. data/include/grpc/event_engine/internal/write_event.h +34 -0
  5. data/include/grpc/impl/channel_arg_names.h +17 -9
  6. data/include/grpc/impl/compression_types.h +3 -2
  7. data/include/grpc/impl/slice_type.h +1 -1
  8. data/include/grpc/support/json.h +3 -21
  9. data/include/grpc/support/port_platform.h +8 -5
  10. data/src/core/call/call_filters.h +28 -19
  11. data/src/core/call/call_spine.h +2 -0
  12. data/src/core/call/metadata.h +17 -0
  13. data/src/core/channelz/channel_trace.cc +50 -42
  14. data/src/core/channelz/channel_trace.h +35 -4
  15. data/src/core/channelz/channelz.cc +338 -125
  16. data/src/core/channelz/channelz.h +276 -34
  17. data/src/core/channelz/channelz_registry.cc +322 -117
  18. data/src/core/channelz/channelz_registry.h +179 -21
  19. data/src/core/channelz/ztrace_collector.h +315 -0
  20. data/src/core/client_channel/client_channel.cc +30 -29
  21. data/src/core/client_channel/client_channel_filter.cc +21 -20
  22. data/src/core/client_channel/client_channel_filter.h +0 -2
  23. data/src/core/client_channel/connector.h +0 -3
  24. data/src/core/client_channel/global_subchannel_pool.cc +68 -7
  25. data/src/core/client_channel/global_subchannel_pool.h +37 -4
  26. data/src/core/client_channel/subchannel.cc +7 -9
  27. data/src/core/client_channel/subchannel.h +2 -8
  28. data/src/core/client_channel/subchannel_pool_interface.cc +5 -6
  29. data/src/core/client_channel/subchannel_pool_interface.h +11 -1
  30. data/src/core/config/config_vars.cc +11 -1
  31. data/src/core/config/config_vars.h +8 -0
  32. data/src/core/config/core_configuration.cc +50 -11
  33. data/src/core/config/core_configuration.h +89 -7
  34. data/src/core/credentials/call/external/aws_request_signer.cc +3 -2
  35. data/src/core/credentials/call/external/url_external_account_credentials.cc +2 -2
  36. data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.cc +1 -1
  37. data/src/core/credentials/call/jwt/jwt_verifier.cc +4 -4
  38. data/src/core/credentials/call/oauth2/oauth2_credentials.cc +4 -2
  39. data/src/core/credentials/transport/alts/alts_security_connector.cc +9 -8
  40. data/src/core/credentials/transport/google_default/google_default_credentials.cc +3 -3
  41. data/src/core/credentials/transport/ssl/ssl_credentials.cc +2 -2
  42. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +41 -11
  43. data/src/core/credentials/transport/ssl/ssl_security_connector.h +2 -1
  44. data/src/core/credentials/transport/tls/ssl_utils.cc +18 -0
  45. data/src/core/credentials/transport/tls/ssl_utils.h +5 -0
  46. data/src/core/credentials/transport/tls/tls_security_connector.cc +2 -1
  47. data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +6 -3
  48. data/src/core/ext/filters/http/message_compress/compression_filter.h +34 -4
  49. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -1
  50. data/src/core/ext/filters/http/server/http_server_filter.h +14 -3
  51. data/src/core/ext/transport/chttp2/chttp2_plugin.cc +40 -0
  52. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +11 -112
  53. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +3 -0
  54. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +33 -962
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.h +5 -1
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +129 -47
  57. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +0 -3
  58. data/src/core/ext/transport/chttp2/transport/flow_control.h +18 -0
  59. data/src/core/ext/transport/chttp2/transport/frame.cc +213 -105
  60. data/src/core/ext/transport/chttp2/transport/frame.h +78 -6
  61. data/src/core/ext/transport/chttp2/transport/frame_data.cc +10 -0
  62. data/src/core/ext/transport/chttp2/transport/frame_data.h +2 -0
  63. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +15 -3
  64. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +5 -3
  65. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +2 -0
  66. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +11 -4
  67. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +3 -1
  68. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +19 -1
  69. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -0
  70. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +7 -0
  71. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -0
  72. data/src/core/ext/transport/chttp2/transport/http2_settings.h +26 -0
  73. data/src/core/ext/transport/chttp2/transport/http2_status.h +358 -1
  74. data/src/core/ext/transport/chttp2/transport/http2_ztrace_collector.h +252 -0
  75. data/src/core/ext/transport/chttp2/transport/internal.h +29 -5
  76. data/src/core/ext/transport/chttp2/transport/internal_channel_arg_names.h +24 -0
  77. data/src/core/ext/transport/chttp2/transport/parsing.cc +36 -21
  78. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +10 -9
  79. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.h +6 -0
  80. data/src/core/ext/transport/chttp2/transport/writing.cc +60 -49
  81. data/src/core/ext/transport/inproc/inproc_transport.cc +7 -2
  82. data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +6 -2
  83. data/src/core/ext/upb-gen/envoy/admin/v3/certs.upb.h +4 -0
  84. data/src/core/ext/upb-gen/envoy/config/accesslog/v3/accesslog.upb.h +12 -0
  85. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb.h +12 -22
  86. data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +12 -22
  87. data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb.h +28 -22
  88. data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb.h +12 -0
  89. data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb.h +24 -67
  90. data/src/core/ext/upb-gen/envoy/config/core/v3/config_source.upb.h +4 -0
  91. data/src/core/ext/upb-gen/envoy/config/core/v3/event_service_config.upb.h +4 -0
  92. data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb.h +29 -31
  93. data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb_minitable.c +2 -2
  94. data/src/core/ext/upb-gen/envoy/config/core/v3/health_check.upb.h +12 -0
  95. data/src/core/ext/upb-gen/envoy/config/core/v3/http_uri.upb.h +4 -0
  96. data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +8 -0
  97. data/src/core/ext/upb-gen/envoy/config/core/v3/socket_option.upb.h +4 -0
  98. data/src/core/ext/upb-gen/envoy/config/core/v3/substitution_format_string.upb.h +4 -0
  99. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint.upb.h +0 -23
  100. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb.h +8 -0
  101. data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb.h +8 -0
  102. data/src/core/ext/upb-gen/envoy/config/listener/v3/listener_components.upb.h +12 -0
  103. data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb.h +20 -0
  104. data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb.h +12 -0
  105. data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb.h +8 -22
  106. data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb.h +0 -23
  107. data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +64 -66
  108. data/src/core/ext/upb-gen/envoy/config/route/v3/scoped_route.upb.h +4 -0
  109. data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb.h +12 -0
  110. data/src/core/ext/upb-gen/envoy/config/trace/v3/http_tracer.upb.h +4 -0
  111. data/src/core/ext/upb-gen/envoy/config/trace/v3/skywalking.upb.h +4 -0
  112. data/src/core/ext/upb-gen/envoy/data/accesslog/v3/accesslog.upb.h +4 -95
  113. data/src/core/ext/upb-gen/envoy/extensions/filters/common/fault/v3/fault.upb.h +8 -0
  114. data/src/core/ext/upb-gen/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  115. data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb.h +4 -0
  116. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +28 -0
  117. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb.h +4 -0
  118. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb.h +4 -0
  119. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +4 -0
  120. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +12 -0
  121. data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb.h +8 -0
  122. data/src/core/ext/upb-gen/envoy/service/discovery/v3/discovery.upb.h +8 -36
  123. data/src/core/ext/upb-gen/envoy/service/status/v3/csds.upb.h +4 -0
  124. data/src/core/ext/upb-gen/envoy/type/http/v3/path_transformation.upb.h +4 -0
  125. data/src/core/ext/upb-gen/envoy/type/matcher/v3/filter_state.upb.h +4 -0
  126. data/src/core/ext/upb-gen/envoy/type/matcher/v3/metadata.upb.h +4 -0
  127. data/src/core/ext/upb-gen/envoy/type/matcher/v3/number.upb.h +4 -0
  128. data/src/core/ext/upb-gen/envoy/type/matcher/v3/path.upb.h +4 -0
  129. data/src/core/ext/upb-gen/envoy/type/matcher/v3/regex.upb.h +4 -0
  130. data/src/core/ext/upb-gen/envoy/type/matcher/v3/string.upb.h +4 -0
  131. data/src/core/ext/upb-gen/envoy/type/matcher/v3/struct.upb.h +4 -0
  132. data/src/core/ext/upb-gen/envoy/type/matcher/v3/value.upb.h +8 -0
  133. data/src/core/ext/upb-gen/envoy/type/metadata/v3/metadata.upb.h +8 -0
  134. data/src/core/ext/upb-gen/envoy/type/tracing/v3/custom_tag.upb.h +4 -0
  135. data/src/core/ext/upb-gen/envoy/type/v3/hash_policy.upb.h +4 -0
  136. data/src/core/ext/upb-gen/envoy/type/v3/ratelimit_strategy.upb.h +4 -0
  137. data/src/core/ext/upb-gen/google/api/expr/v1alpha1/checked.upb.h +8 -44
  138. data/src/core/ext/upb-gen/google/api/expr/v1alpha1/syntax.upb.h +12 -40
  139. data/src/core/ext/upb-gen/google/api/http.upb.h +4 -0
  140. data/src/core/ext/upb-gen/google/protobuf/descriptor.upb.h +193 -20
  141. data/src/core/ext/upb-gen/google/protobuf/descriptor.upb_minitable.c +59 -21
  142. data/src/core/ext/upb-gen/google/protobuf/descriptor.upb_minitable.h +4 -0
  143. data/src/core/ext/upb-gen/google/protobuf/struct.upb.h +4 -22
  144. data/src/core/ext/upb-gen/src/proto/grpc/gcp/altscontext.upb.h +0 -18
  145. data/src/core/ext/upb-gen/src/proto/grpc/gcp/handshaker.upb.h +113 -53
  146. data/src/core/ext/upb-gen/src/proto/grpc/gcp/handshaker.upb_minitable.c +20 -14
  147. data/src/core/ext/upb-gen/src/proto/grpc/gcp/transport_security_common.upb.h +154 -0
  148. data/src/core/ext/upb-gen/src/proto/grpc/gcp/transport_security_common.upb_minitable.c +40 -2
  149. data/src/core/ext/upb-gen/src/proto/grpc/gcp/transport_security_common.upb_minitable.h +4 -0
  150. data/src/core/ext/upb-gen/src/proto/grpc/lb/v1/load_balancer.upb.h +8 -0
  151. data/src/core/ext/upb-gen/src/proto/grpc/lookup/v1/rls.upb.h +0 -18
  152. data/src/core/ext/upb-gen/src/proto/grpc/lookup/v1/rls_config.upb.h +0 -36
  153. data/src/core/ext/upb-gen/validate/validate.upb.h +12 -0
  154. data/src/core/ext/upb-gen/xds/core/v3/collection_entry.upb.h +4 -0
  155. data/src/core/ext/upb-gen/xds/core/v3/context_params.upb.h +0 -18
  156. data/src/core/ext/upb-gen/xds/core/v3/resource_locator.upb.h +8 -0
  157. data/src/core/ext/upb-gen/xds/data/orca/v3/orca_load_report.upb.h +0 -54
  158. data/src/core/ext/upb-gen/xds/type/matcher/v3/matcher.upb.h +20 -22
  159. data/src/core/ext/upb-gen/xds/type/matcher/v3/regex.upb.h +4 -0
  160. data/src/core/ext/upb-gen/xds/type/matcher/v3/string.upb.h +4 -0
  161. data/src/core/ext/upb-gen/xds/type/v3/cel.upb.h +4 -0
  162. data/src/core/ext/upbdefs-gen/envoy/admin/v3/certs.upbdefs.c +123 -62
  163. data/src/core/ext/upbdefs-gen/envoy/admin/v3/certs.upbdefs.h +5 -1
  164. data/src/core/ext/upbdefs-gen/envoy/admin/v3/clusters.upbdefs.c +200 -101
  165. data/src/core/ext/upbdefs-gen/envoy/admin/v3/clusters.upbdefs.h +5 -1
  166. data/src/core/ext/upbdefs-gen/envoy/admin/v3/config_dump.upbdefs.c +152 -77
  167. data/src/core/ext/upbdefs-gen/envoy/admin/v3/config_dump.upbdefs.h +5 -1
  168. data/src/core/ext/upbdefs-gen/envoy/admin/v3/config_dump_shared.upbdefs.c +524 -255
  169. data/src/core/ext/upbdefs-gen/envoy/admin/v3/config_dump_shared.upbdefs.h +5 -1
  170. data/src/core/ext/upbdefs-gen/envoy/admin/v3/init_dump.upbdefs.c +44 -23
  171. data/src/core/ext/upbdefs-gen/envoy/admin/v3/init_dump.upbdefs.h +5 -1
  172. data/src/core/ext/upbdefs-gen/envoy/admin/v3/listeners.upbdefs.c +66 -34
  173. data/src/core/ext/upbdefs-gen/envoy/admin/v3/listeners.upbdefs.h +5 -1
  174. data/src/core/ext/upbdefs-gen/envoy/admin/v3/memory.upbdefs.c +54 -28
  175. data/src/core/ext/upbdefs-gen/envoy/admin/v3/memory.upbdefs.h +5 -1
  176. data/src/core/ext/upbdefs-gen/envoy/admin/v3/metrics.upbdefs.c +46 -25
  177. data/src/core/ext/upbdefs-gen/envoy/admin/v3/metrics.upbdefs.h +5 -1
  178. data/src/core/ext/upbdefs-gen/envoy/admin/v3/mutex_stats.upbdefs.c +47 -25
  179. data/src/core/ext/upbdefs-gen/envoy/admin/v3/mutex_stats.upbdefs.h +5 -1
  180. data/src/core/ext/upbdefs-gen/envoy/admin/v3/server_info.upbdefs.c +256 -126
  181. data/src/core/ext/upbdefs-gen/envoy/admin/v3/server_info.upbdefs.h +5 -1
  182. data/src/core/ext/upbdefs-gen/envoy/admin/v3/tap.upbdefs.c +50 -28
  183. data/src/core/ext/upbdefs-gen/envoy/admin/v3/tap.upbdefs.h +5 -1
  184. data/src/core/ext/upbdefs-gen/envoy/annotations/deprecation.upbdefs.c +55 -28
  185. data/src/core/ext/upbdefs-gen/envoy/annotations/deprecation.upbdefs.h +5 -1
  186. data/src/core/ext/upbdefs-gen/envoy/annotations/resource.upbdefs.c +34 -18
  187. data/src/core/ext/upbdefs-gen/envoy/annotations/resource.upbdefs.h +5 -1
  188. data/src/core/ext/upbdefs-gen/envoy/config/accesslog/v3/accesslog.upbdefs.c +414 -206
  189. data/src/core/ext/upbdefs-gen/envoy/config/accesslog/v3/accesslog.upbdefs.h +5 -1
  190. data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +831 -413
  191. data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -1
  192. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/circuit_breaker.upbdefs.c +143 -73
  193. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/circuit_breaker.upbdefs.h +5 -1
  194. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +1132 -557
  195. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.h +5 -1
  196. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/filter.upbdefs.c +63 -34
  197. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/filter.upbdefs.h +5 -1
  198. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/outlier_detection.upbdefs.c +255 -127
  199. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/outlier_detection.upbdefs.h +5 -1
  200. data/src/core/ext/upbdefs-gen/envoy/config/common/matcher/v3/matcher.upbdefs.c +363 -178
  201. data/src/core/ext/upbdefs-gen/envoy/config/common/matcher/v3/matcher.upbdefs.h +5 -1
  202. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.c +227 -114
  203. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.h +5 -1
  204. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/backoff.upbdefs.c +57 -31
  205. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/backoff.upbdefs.h +5 -1
  206. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +596 -295
  207. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.h +5 -1
  208. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/config_source.upbdefs.c +271 -137
  209. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/config_source.upbdefs.h +5 -1
  210. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/event_service_config.upbdefs.c +56 -30
  211. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/event_service_config.upbdefs.h +5 -1
  212. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/extension.upbdefs.c +45 -25
  213. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/extension.upbdefs.h +5 -1
  214. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_method_list.upbdefs.c +59 -31
  215. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_method_list.upbdefs.h +5 -1
  216. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_service.upbdefs.c +438 -217
  217. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_service.upbdefs.h +5 -1
  218. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/health_check.upbdefs.c +441 -221
  219. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/health_check.upbdefs.h +5 -1
  220. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_service.upbdefs.c +55 -30
  221. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_service.upbdefs.h +5 -1
  222. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_uri.upbdefs.c +57 -31
  223. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_uri.upbdefs.h +5 -1
  224. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.c +619 -303
  225. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.h +5 -1
  226. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.c +70 -36
  227. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.h +5 -1
  228. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/resolver.upbdefs.c +62 -33
  229. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/resolver.upbdefs.h +5 -1
  230. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_cmsg_headers.upbdefs.c +47 -25
  231. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_cmsg_headers.upbdefs.h +5 -1
  232. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_option.upbdefs.c +97 -49
  233. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/socket_option.upbdefs.h +5 -1
  234. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.c +97 -51
  235. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.h +5 -1
  236. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/udp_socket_config.upbdefs.c +51 -27
  237. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/udp_socket_config.upbdefs.h +5 -1
  238. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint.upbdefs.c +147 -76
  239. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint.upbdefs.h +5 -1
  240. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +230 -116
  241. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +5 -1
  242. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/load_report.upbdefs.c +277 -138
  243. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/load_report.upbdefs.h +5 -1
  244. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/api_listener.upbdefs.c +48 -26
  245. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/api_listener.upbdefs.h +5 -1
  246. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.c +388 -197
  247. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.h +5 -1
  248. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener_components.upbdefs.c +304 -153
  249. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener_components.upbdefs.h +5 -1
  250. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/quic_config.upbdefs.c +173 -90
  251. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/quic_config.upbdefs.h +5 -1
  252. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/udp_listener_config.upbdefs.c +90 -47
  253. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/udp_listener_config.upbdefs.h +5 -1
  254. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/metrics_service.upbdefs.c +98 -51
  255. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/metrics_service.upbdefs.h +5 -1
  256. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/stats.upbdefs.c +196 -99
  257. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/stats.upbdefs.h +5 -1
  258. data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.c +237 -118
  259. data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.h +5 -1
  260. data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.c +418 -210
  261. data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.h +5 -1
  262. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route.upbdefs.c +194 -99
  263. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route.upbdefs.h +5 -1
  264. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +2003 -973
  265. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.h +5 -1
  266. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/scoped_route.upbdefs.c +101 -53
  267. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/scoped_route.upbdefs.h +5 -1
  268. data/src/core/ext/upbdefs-gen/envoy/config/tap/v3/common.upbdefs.c +352 -176
  269. data/src/core/ext/upbdefs-gen/envoy/config/tap/v3/common.upbdefs.h +5 -1
  270. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/datadog.upbdefs.c +79 -42
  271. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/datadog.upbdefs.h +5 -1
  272. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/dynamic_ot.upbdefs.c +67 -37
  273. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/dynamic_ot.upbdefs.h +5 -1
  274. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/http_tracer.upbdefs.c +63 -34
  275. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/http_tracer.upbdefs.h +5 -1
  276. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/lightstep.upbdefs.c +88 -47
  277. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/lightstep.upbdefs.h +5 -1
  278. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.c +80 -43
  279. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.h +5 -1
  280. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/service.upbdefs.c +53 -29
  281. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/service.upbdefs.h +5 -1
  282. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/skywalking.upbdefs.c +86 -46
  283. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/skywalking.upbdefs.h +5 -1
  284. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/trace.upbdefs.c +55 -32
  285. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/trace.upbdefs.h +5 -1
  286. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/xray.upbdefs.c +91 -49
  287. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/xray.upbdefs.h +5 -1
  288. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/zipkin.upbdefs.c +105 -55
  289. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/zipkin.upbdefs.h +5 -1
  290. data/src/core/ext/upbdefs-gen/envoy/data/accesslog/v3/accesslog.upbdefs.c +775 -379
  291. data/src/core/ext/upbdefs-gen/envoy/data/accesslog/v3/accesslog.upbdefs.h +5 -1
  292. data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.c +52 -28
  293. data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h +5 -1
  294. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.c +134 -68
  295. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/common/fault/v3/fault.upbdefs.h +5 -1
  296. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +189 -96
  297. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/fault/v3/fault.upbdefs.h +5 -1
  298. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.c +116 -61
  299. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/gcp_authn/v3/gcp_authn.upbdefs.h +5 -1
  300. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +112 -58
  301. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.h +5 -1
  302. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.c +160 -82
  303. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.h +5 -1
  304. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.c +75 -39
  305. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.h +5 -1
  306. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +1161 -570
  307. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -1
  308. data/src/core/ext/upbdefs-gen/envoy/extensions/http/stateful_session/cookie/v3/cookie.upbdefs.c +52 -28
  309. data/src/core/ext/upbdefs-gen/envoy/extensions/http/stateful_session/cookie/v3/cookie.upbdefs.h +5 -1
  310. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upbdefs.c +55 -29
  311. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/http_11_proxy/v3/upstream_http_11_connect.upbdefs.h +5 -1
  312. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +48 -26
  313. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.h +5 -1
  314. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +390 -194
  315. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +5 -1
  316. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +126 -65
  317. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +5 -1
  318. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +498 -246
  319. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.h +5 -1
  320. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upbdefs.c +74 -38
  321. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls_spiffe_validator_config.upbdefs.h +5 -1
  322. data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.c +221 -110
  323. data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.h +5 -1
  324. data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/ads.upbdefs.c +68 -36
  325. data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/ads.upbdefs.h +5 -1
  326. data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/discovery.upbdefs.c +378 -187
  327. data/src/core/ext/upbdefs-gen/envoy/service/discovery/v3/discovery.upbdefs.h +5 -1
  328. data/src/core/ext/upbdefs-gen/envoy/service/load_stats/v3/lrs.upbdefs.c +100 -52
  329. data/src/core/ext/upbdefs-gen/envoy/service/load_stats/v3/lrs.upbdefs.h +5 -1
  330. data/src/core/ext/upbdefs-gen/envoy/service/status/v3/csds.upbdefs.c +257 -129
  331. data/src/core/ext/upbdefs-gen/envoy/service/status/v3/csds.upbdefs.h +5 -1
  332. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.c +44 -24
  333. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.h +5 -1
  334. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/path_transformation.upbdefs.c +68 -35
  335. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/path_transformation.upbdefs.h +5 -1
  336. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/address.upbdefs.c +38 -20
  337. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/address.upbdefs.h +5 -1
  338. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/filter_state.upbdefs.c +59 -32
  339. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/filter_state.upbdefs.h +5 -1
  340. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/http_inputs.upbdefs.c +65 -34
  341. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/http_inputs.upbdefs.h +5 -1
  342. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/metadata.upbdefs.c +72 -38
  343. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/metadata.upbdefs.h +5 -1
  344. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/node.upbdefs.c +57 -31
  345. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/node.upbdefs.h +5 -1
  346. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/number.upbdefs.c +52 -29
  347. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/number.upbdefs.h +5 -1
  348. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/path.upbdefs.c +51 -28
  349. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/path.upbdefs.h +5 -1
  350. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/regex.upbdefs.c +89 -47
  351. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/regex.upbdefs.h +5 -1
  352. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/status_code_input.upbdefs.c +37 -20
  353. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/status_code_input.upbdefs.h +5 -1
  354. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/string.upbdefs.c +89 -47
  355. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/string.upbdefs.h +5 -1
  356. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/struct.upbdefs.c +67 -35
  357. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/struct.upbdefs.h +5 -1
  358. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/value.upbdefs.c +112 -58
  359. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/value.upbdefs.h +5 -1
  360. data/src/core/ext/upbdefs-gen/envoy/type/metadata/v3/metadata.upbdefs.c +110 -56
  361. data/src/core/ext/upbdefs-gen/envoy/type/metadata/v3/metadata.upbdefs.h +5 -1
  362. data/src/core/ext/upbdefs-gen/envoy/type/tracing/v3/custom_tag.upbdefs.c +123 -62
  363. data/src/core/ext/upbdefs-gen/envoy/type/tracing/v3/custom_tag.upbdefs.h +5 -1
  364. data/src/core/ext/upbdefs-gen/envoy/type/v3/hash_policy.upbdefs.c +59 -31
  365. data/src/core/ext/upbdefs-gen/envoy/type/v3/hash_policy.upbdefs.h +5 -1
  366. data/src/core/ext/upbdefs-gen/envoy/type/v3/http.upbdefs.c +30 -16
  367. data/src/core/ext/upbdefs-gen/envoy/type/v3/http.upbdefs.h +5 -1
  368. data/src/core/ext/upbdefs-gen/envoy/type/v3/http_status.upbdefs.c +143 -72
  369. data/src/core/ext/upbdefs-gen/envoy/type/v3/http_status.upbdefs.h +5 -1
  370. data/src/core/ext/upbdefs-gen/envoy/type/v3/percent.upbdefs.c +61 -32
  371. data/src/core/ext/upbdefs-gen/envoy/type/v3/percent.upbdefs.h +5 -1
  372. data/src/core/ext/upbdefs-gen/envoy/type/v3/range.upbdefs.c +51 -27
  373. data/src/core/ext/upbdefs-gen/envoy/type/v3/range.upbdefs.h +5 -1
  374. data/src/core/ext/upbdefs-gen/envoy/type/v3/ratelimit_strategy.upbdefs.c +85 -45
  375. data/src/core/ext/upbdefs-gen/envoy/type/v3/ratelimit_strategy.upbdefs.h +5 -1
  376. data/src/core/ext/upbdefs-gen/envoy/type/v3/ratelimit_unit.upbdefs.c +35 -19
  377. data/src/core/ext/upbdefs-gen/envoy/type/v3/ratelimit_unit.upbdefs.h +5 -1
  378. data/src/core/ext/upbdefs-gen/envoy/type/v3/semantic_version.upbdefs.c +44 -23
  379. data/src/core/ext/upbdefs-gen/envoy/type/v3/semantic_version.upbdefs.h +5 -1
  380. data/src/core/ext/upbdefs-gen/envoy/type/v3/token_bucket.upbdefs.c +61 -33
  381. data/src/core/ext/upbdefs-gen/envoy/type/v3/token_bucket.upbdefs.h +5 -1
  382. data/src/core/ext/upbdefs-gen/google/api/annotations.upbdefs.c +35 -19
  383. data/src/core/ext/upbdefs-gen/google/api/annotations.upbdefs.h +5 -1
  384. data/src/core/ext/upbdefs-gen/google/api/expr/v1alpha1/checked.upbdefs.c +272 -133
  385. data/src/core/ext/upbdefs-gen/google/api/expr/v1alpha1/checked.upbdefs.h +5 -1
  386. data/src/core/ext/upbdefs-gen/google/api/expr/v1alpha1/syntax.upbdefs.c +315 -154
  387. data/src/core/ext/upbdefs-gen/google/api/expr/v1alpha1/syntax.upbdefs.h +5 -1
  388. data/src/core/ext/upbdefs-gen/google/api/http.upbdefs.c +64 -33
  389. data/src/core/ext/upbdefs-gen/google/api/http.upbdefs.h +5 -1
  390. data/src/core/ext/upbdefs-gen/google/api/httpbody.upbdefs.c +35 -19
  391. data/src/core/ext/upbdefs-gen/google/api/httpbody.upbdefs.h +5 -1
  392. data/src/core/ext/upbdefs-gen/google/protobuf/any.upbdefs.c +26 -15
  393. data/src/core/ext/upbdefs-gen/google/protobuf/any.upbdefs.h +5 -1
  394. data/src/core/ext/upbdefs-gen/google/protobuf/descriptor.upbdefs.c +1106 -508
  395. data/src/core/ext/upbdefs-gen/google/protobuf/descriptor.upbdefs.h +10 -1
  396. data/src/core/ext/upbdefs-gen/google/protobuf/duration.upbdefs.c +28 -16
  397. data/src/core/ext/upbdefs-gen/google/protobuf/duration.upbdefs.h +5 -1
  398. data/src/core/ext/upbdefs-gen/google/protobuf/empty.upbdefs.c +23 -13
  399. data/src/core/ext/upbdefs-gen/google/protobuf/empty.upbdefs.h +5 -1
  400. data/src/core/ext/upbdefs-gen/google/protobuf/struct.upbdefs.c +69 -35
  401. data/src/core/ext/upbdefs-gen/google/protobuf/struct.upbdefs.h +5 -1
  402. data/src/core/ext/upbdefs-gen/google/protobuf/timestamp.upbdefs.c +29 -16
  403. data/src/core/ext/upbdefs-gen/google/protobuf/timestamp.upbdefs.h +5 -1
  404. data/src/core/ext/upbdefs-gen/google/protobuf/wrappers.upbdefs.c +51 -26
  405. data/src/core/ext/upbdefs-gen/google/protobuf/wrappers.upbdefs.h +5 -1
  406. data/src/core/ext/upbdefs-gen/google/rpc/status.upbdefs.c +32 -17
  407. data/src/core/ext/upbdefs-gen/google/rpc/status.upbdefs.h +5 -1
  408. data/src/core/ext/upbdefs-gen/src/proto/grpc/lookup/v1/rls_config.upbdefs.c +161 -79
  409. data/src/core/ext/upbdefs-gen/src/proto/grpc/lookup/v1/rls_config.upbdefs.h +5 -1
  410. data/src/core/ext/upbdefs-gen/udpa/annotations/migrate.upbdefs.c +84 -42
  411. data/src/core/ext/upbdefs-gen/udpa/annotations/migrate.upbdefs.h +5 -1
  412. data/src/core/ext/upbdefs-gen/udpa/annotations/security.upbdefs.c +48 -26
  413. data/src/core/ext/upbdefs-gen/udpa/annotations/security.upbdefs.h +5 -1
  414. data/src/core/ext/upbdefs-gen/udpa/annotations/sensitive.upbdefs.c +26 -14
  415. data/src/core/ext/upbdefs-gen/udpa/annotations/sensitive.upbdefs.h +5 -1
  416. data/src/core/ext/upbdefs-gen/udpa/annotations/status.upbdefs.c +50 -26
  417. data/src/core/ext/upbdefs-gen/udpa/annotations/status.upbdefs.h +5 -1
  418. data/src/core/ext/upbdefs-gen/udpa/annotations/versioning.upbdefs.c +36 -19
  419. data/src/core/ext/upbdefs-gen/udpa/annotations/versioning.upbdefs.h +5 -1
  420. data/src/core/ext/upbdefs-gen/validate/validate.upbdefs.c +538 -261
  421. data/src/core/ext/upbdefs-gen/validate/validate.upbdefs.h +5 -1
  422. data/src/core/ext/upbdefs-gen/xds/annotations/v3/migrate.upbdefs.c +86 -43
  423. data/src/core/ext/upbdefs-gen/xds/annotations/v3/migrate.upbdefs.h +5 -1
  424. data/src/core/ext/upbdefs-gen/xds/annotations/v3/security.upbdefs.c +49 -26
  425. data/src/core/ext/upbdefs-gen/xds/annotations/v3/security.upbdefs.h +5 -1
  426. data/src/core/ext/upbdefs-gen/xds/annotations/v3/sensitive.upbdefs.c +27 -15
  427. data/src/core/ext/upbdefs-gen/xds/annotations/v3/sensitive.upbdefs.h +5 -1
  428. data/src/core/ext/upbdefs-gen/xds/annotations/v3/status.upbdefs.c +87 -44
  429. data/src/core/ext/upbdefs-gen/xds/annotations/v3/status.upbdefs.h +5 -1
  430. data/src/core/ext/upbdefs-gen/xds/annotations/v3/versioning.upbdefs.c +37 -20
  431. data/src/core/ext/upbdefs-gen/xds/annotations/v3/versioning.upbdefs.h +5 -1
  432. data/src/core/ext/upbdefs-gen/xds/core/v3/authority.upbdefs.c +30 -17
  433. data/src/core/ext/upbdefs-gen/xds/core/v3/authority.upbdefs.h +5 -1
  434. data/src/core/ext/upbdefs-gen/xds/core/v3/cidr.upbdefs.c +41 -23
  435. data/src/core/ext/upbdefs-gen/xds/core/v3/cidr.upbdefs.h +5 -1
  436. data/src/core/ext/upbdefs-gen/xds/core/v3/collection_entry.upbdefs.c +62 -33
  437. data/src/core/ext/upbdefs-gen/xds/core/v3/collection_entry.upbdefs.h +5 -1
  438. data/src/core/ext/upbdefs-gen/xds/core/v3/context_params.upbdefs.c +36 -19
  439. data/src/core/ext/upbdefs-gen/xds/core/v3/context_params.upbdefs.h +5 -1
  440. data/src/core/ext/upbdefs-gen/xds/core/v3/extension.upbdefs.c +36 -20
  441. data/src/core/ext/upbdefs-gen/xds/core/v3/extension.upbdefs.h +5 -1
  442. data/src/core/ext/upbdefs-gen/xds/core/v3/resource.upbdefs.c +42 -23
  443. data/src/core/ext/upbdefs-gen/xds/core/v3/resource.upbdefs.h +5 -1
  444. data/src/core/ext/upbdefs-gen/xds/core/v3/resource_locator.upbdefs.c +76 -39
  445. data/src/core/ext/upbdefs-gen/xds/core/v3/resource_locator.upbdefs.h +5 -1
  446. data/src/core/ext/upbdefs-gen/xds/core/v3/resource_name.upbdefs.c +45 -24
  447. data/src/core/ext/upbdefs-gen/xds/core/v3/resource_name.upbdefs.h +5 -1
  448. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/cel.upbdefs.c +41 -23
  449. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/cel.upbdefs.h +5 -1
  450. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/domain.upbdefs.c +53 -29
  451. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/domain.upbdefs.h +5 -1
  452. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/http_inputs.upbdefs.c +29 -16
  453. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/http_inputs.upbdefs.h +5 -1
  454. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/ip.upbdefs.c +58 -32
  455. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/ip.upbdefs.h +5 -1
  456. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/matcher.upbdefs.c +207 -103
  457. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/matcher.upbdefs.h +5 -1
  458. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/range.upbdefs.c +95 -49
  459. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/range.upbdefs.h +5 -1
  460. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/regex.upbdefs.c +38 -20
  461. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/regex.upbdefs.h +5 -1
  462. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/string.upbdefs.c +60 -31
  463. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/string.upbdefs.h +5 -1
  464. data/src/core/ext/upbdefs-gen/xds/type/v3/cel.upbdefs.c +67 -36
  465. data/src/core/ext/upbdefs-gen/xds/type/v3/cel.upbdefs.h +5 -1
  466. data/src/core/ext/upbdefs-gen/xds/type/v3/range.upbdefs.c +31 -17
  467. data/src/core/ext/upbdefs-gen/xds/type/v3/range.upbdefs.h +5 -1
  468. data/src/core/ext/upbdefs-gen/xds/type/v3/typed_struct.upbdefs.c +31 -17
  469. data/src/core/ext/upbdefs-gen/xds/type/v3/typed_struct.upbdefs.h +5 -1
  470. data/src/core/handshaker/http_connect/http_proxy_mapper.cc +7 -22
  471. data/src/core/handshaker/security/legacy_secure_endpoint.cc +596 -0
  472. data/src/core/handshaker/security/secure_endpoint.cc +769 -312
  473. data/src/core/handshaker/security/secure_endpoint.h +17 -0
  474. data/src/core/handshaker/security/security_handshaker.cc +3 -3
  475. data/src/core/lib/address_utils/sockaddr_utils.cc +5 -5
  476. data/src/core/lib/channel/channel_args.h +4 -0
  477. data/src/core/lib/channel/channel_stack.cc +29 -0
  478. data/src/core/lib/channel/channel_stack.h +9 -0
  479. data/src/core/lib/channel/promise_based_filter.h +707 -299
  480. data/src/core/lib/debug/trace_flags.cc +2 -2
  481. data/src/core/lib/debug/trace_flags.h +1 -1
  482. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +6 -2
  483. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +4 -4
  484. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +14 -6
  485. data/src/core/lib/event_engine/default_event_engine_factory.cc +1 -1
  486. data/src/core/lib/event_engine/extensions/blocking_dns.h +46 -0
  487. data/src/core/lib/event_engine/extensions/channelz.h +62 -0
  488. data/src/core/lib/event_engine/extensions/tcp_trace.h +2 -2
  489. data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc +4 -7
  490. data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h +3 -0
  491. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +6 -7
  492. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +28 -22
  493. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +22 -0
  494. data/src/core/lib/event_engine/posix_engine/posix_engine.h +15 -15
  495. data/src/core/lib/event_engine/query_extensions.h +10 -21
  496. data/src/core/lib/event_engine/tcp_socket_utils.cc +10 -9
  497. data/src/core/lib/event_engine/utils.cc +34 -0
  498. data/src/core/lib/event_engine/utils.h +3 -0
  499. data/src/core/lib/event_engine/windows/windows_endpoint.cc +2 -2
  500. data/src/core/lib/event_engine/windows/windows_endpoint.h +9 -2
  501. data/src/core/lib/experiments/experiments.cc +198 -51
  502. data/src/core/lib/experiments/experiments.h +78 -35
  503. data/src/core/lib/iomgr/combiner.cc +3 -2
  504. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  505. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +11 -8
  506. data/src/core/lib/iomgr/fork_posix.cc +0 -7
  507. data/src/core/lib/iomgr/iomgr.cc +0 -3
  508. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +3 -0
  509. data/src/core/lib/iomgr/resolve_address_posix.cc +37 -47
  510. data/src/core/lib/iomgr/resolve_address_posix.h +15 -0
  511. data/src/core/lib/iomgr/resolve_address_windows.cc +22 -45
  512. data/src/core/lib/iomgr/resolve_address_windows.h +15 -2
  513. data/src/core/lib/iomgr/tcp_client_posix.cc +14 -6
  514. data/src/core/lib/iomgr/tcp_posix.cc +14 -12
  515. data/src/core/lib/iomgr/tcp_server_windows.cc +14 -2
  516. data/src/core/lib/promise/detail/promise_like.h +24 -0
  517. data/src/core/lib/promise/detail/seq_state.h +741 -0
  518. data/src/core/lib/promise/map.h +22 -5
  519. data/src/core/lib/promise/promise.h +2 -0
  520. data/src/core/lib/promise/seq.h +2 -0
  521. data/src/core/lib/promise/sleep.cc +6 -3
  522. data/src/core/lib/promise/try_seq.h +2 -0
  523. data/src/core/lib/resource_quota/memory_quota.cc +9 -0
  524. data/src/core/lib/resource_quota/memory_quota.h +1 -3
  525. data/src/core/lib/slice/slice_buffer.h +6 -0
  526. data/src/core/lib/surface/call.cc +4 -0
  527. data/src/core/lib/surface/channel_create.cc +61 -1
  528. data/src/core/lib/surface/init.cc +2 -2
  529. data/src/core/lib/surface/version.cc +2 -2
  530. data/src/core/lib/transport/status_conversion.cc +7 -34
  531. data/src/core/lib/transport/transport.cc +2 -2
  532. data/src/core/lib/transport/transport.h +3 -0
  533. data/src/core/load_balancing/backend_metric_parser.cc +12 -18
  534. data/src/core/load_balancing/grpclb/grpclb.cc +2 -2
  535. data/src/core/load_balancing/health_check_client.cc +2 -4
  536. data/src/core/load_balancing/oob_backend_metric.cc +2 -4
  537. data/src/core/load_balancing/outlier_detection/outlier_detection.cc +4 -3
  538. data/src/core/load_balancing/pick_first/pick_first.cc +3 -3
  539. data/src/core/load_balancing/rls/rls.cc +6 -5
  540. data/src/core/load_balancing/round_robin/round_robin.cc +2 -3
  541. data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +4 -4
  542. data/src/core/load_balancing/weighted_target/weighted_target.cc +3 -9
  543. data/src/core/load_balancing/xds/xds_override_host.cc +55 -34
  544. data/src/core/plugin_registry/grpc_plugin_registry.cc +2 -0
  545. data/src/core/resolver/sockaddr/sockaddr_resolver.cc +2 -1
  546. data/src/core/resolver/xds/xds_resolver.cc +2 -1
  547. data/src/core/server/add_port.cc +87 -0
  548. data/src/core/server/server.cc +48 -53
  549. data/src/core/server/server.h +3 -5
  550. data/src/core/telemetry/call_tracer.cc +2 -2
  551. data/src/core/telemetry/call_tracer.h +1 -1
  552. data/src/core/{ext/transport/chttp2/transport → telemetry}/context_list_entry.h +3 -3
  553. data/src/core/telemetry/default_tcp_tracer.cc +26 -0
  554. data/src/core/telemetry/default_tcp_tracer.h +44 -0
  555. data/src/core/telemetry/stats.h +0 -5
  556. data/src/core/telemetry/stats_data.cc +376 -334
  557. data/src/core/telemetry/stats_data.h +260 -166
  558. data/src/core/telemetry/tcp_tracer.cc +38 -0
  559. data/src/core/telemetry/tcp_tracer.h +14 -16
  560. data/src/core/transport/auth_context.cc +0 -1
  561. data/src/core/transport/auth_context.h +0 -1
  562. data/src/core/transport/endpoint_transport.h +90 -0
  563. data/src/core/transport/endpoint_transport_client_channel_factory.cc +61 -0
  564. data/src/core/transport/endpoint_transport_client_channel_factory.h +57 -0
  565. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +33 -1
  566. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +3 -1
  567. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +76 -22
  568. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +8 -2
  569. data/src/core/tsi/ssl_transport_security.cc +189 -71
  570. data/src/core/tsi/ssl_transport_security.h +6 -1
  571. data/src/core/tsi/transport_security.h +3 -0
  572. data/src/core/tsi/transport_security_grpc.h +7 -3
  573. data/src/core/tsi/transport_security_interface.h +30 -25
  574. data/src/core/util/backoff.cc +7 -14
  575. data/src/core/util/backoff.h +0 -1
  576. data/src/core/util/dual_ref_counted.h +48 -0
  577. data/src/core/util/function_signature.h +66 -0
  578. data/src/core/util/gcp_metadata_query.cc +3 -2
  579. data/src/core/util/http_client/httpcli_security_connector.cc +2 -1
  580. data/src/core/util/json/json_object_loader.h +3 -3
  581. data/src/core/util/latent_see.cc +28 -2
  582. data/src/core/util/latent_see.h +11 -23
  583. data/src/core/util/linux/env.cc +3 -1
  584. data/src/core/util/ref_counted_ptr.h +26 -0
  585. data/src/core/util/shared_bit_gen.cc +21 -0
  586. data/src/core/util/shared_bit_gen.h +44 -0
  587. data/src/core/util/single_set_ptr.h +35 -4
  588. data/src/core/util/uri.cc +75 -17
  589. data/src/core/util/uri.h +13 -8
  590. data/src/core/xds/grpc/xds_common_types_parser.cc +1 -9
  591. data/src/core/xds/grpc/xds_http_filter_registry.cc +1 -3
  592. data/src/core/xds/grpc/xds_http_rbac_filter.cc +10 -17
  593. data/src/core/xds/grpc/xds_metadata_parser.cc +40 -64
  594. data/src/core/xds/grpc/xds_metadata_parser.h +0 -2
  595. data/src/core/xds/grpc/xds_route_config_parser.cc +55 -77
  596. data/src/core/xds/xds_client/xds_client.cc +1 -1
  597. data/src/ruby/ext/grpc/extconf.rb +1 -1
  598. data/src/ruby/lib/grpc/version.rb +1 -1
  599. data/src/ruby/spec/generic/client_stub_spec.rb +2 -6
  600. data/src/ruby/spec/generic/rpc_server_spec.rb +1 -1
  601. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +2 -2
  602. data/third_party/abseil-cpp/absl/algorithm/container.h +79 -48
  603. data/third_party/abseil-cpp/absl/base/attributes.h +66 -16
  604. data/third_party/abseil-cpp/absl/base/call_once.h +8 -5
  605. data/third_party/abseil-cpp/absl/base/config.h +4 -4
  606. data/third_party/abseil-cpp/absl/base/internal/nullability_impl.h +17 -56
  607. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +1 -1
  608. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +14 -0
  609. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +5 -1
  610. data/third_party/abseil-cpp/absl/base/internal/tracing.cc +39 -0
  611. data/third_party/abseil-cpp/absl/base/internal/tracing.h +81 -0
  612. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +0 -10
  613. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +12 -0
  614. data/third_party/abseil-cpp/absl/base/macros.h +35 -4
  615. data/third_party/abseil-cpp/absl/base/nullability.h +72 -16
  616. data/third_party/abseil-cpp/absl/base/optimization.h +8 -12
  617. data/third_party/abseil-cpp/absl/base/options.h +5 -2
  618. data/third_party/abseil-cpp/absl/base/policy_checks.h +2 -0
  619. data/third_party/abseil-cpp/absl/container/btree_map.h +889 -0
  620. data/third_party/abseil-cpp/absl/container/btree_set.h +824 -0
  621. data/third_party/abseil-cpp/absl/container/fixed_array.h +2 -1
  622. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +17 -3
  623. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +17 -3
  624. data/third_party/abseil-cpp/absl/container/inlined_vector.h +2 -1
  625. data/third_party/abseil-cpp/absl/container/internal/btree.h +3046 -0
  626. data/third_party/abseil-cpp/absl/container/internal/btree_container.h +763 -0
  627. data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +9 -0
  628. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +1 -0
  629. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +4 -2
  630. data/third_party/abseil-cpp/absl/container/internal/layout.h +1 -1
  631. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +142 -114
  632. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +397 -231
  633. data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +56 -0
  634. data/third_party/abseil-cpp/absl/crc/internal/non_temporal_memcpy.h +21 -7
  635. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +4 -2
  636. data/third_party/abseil-cpp/absl/debugging/internal/elf_mem_image.h +1 -1
  637. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +17 -1
  638. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +7 -0
  639. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_riscv-inl.inc +9 -6
  640. data/third_party/abseil-cpp/absl/debugging/leak_check.cc +73 -0
  641. data/third_party/abseil-cpp/absl/debugging/leak_check.h +150 -0
  642. data/third_party/abseil-cpp/absl/debugging/symbolize.cc +3 -2
  643. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +48 -9
  644. data/third_party/abseil-cpp/absl/flags/commandlineflag.cc +1 -0
  645. data/third_party/abseil-cpp/absl/flags/commandlineflag.h +7 -0
  646. data/third_party/abseil-cpp/absl/flags/flag.h +14 -12
  647. data/third_party/abseil-cpp/absl/flags/internal/flag.cc +12 -4
  648. data/third_party/abseil-cpp/absl/flags/internal/flag.h +16 -5
  649. data/third_party/abseil-cpp/absl/flags/internal/private_handle_accessor.cc +4 -0
  650. data/third_party/abseil-cpp/absl/flags/internal/private_handle_accessor.h +3 -0
  651. data/third_party/abseil-cpp/absl/flags/internal/program_name.cc +13 -12
  652. data/third_party/abseil-cpp/absl/flags/usage_config.cc +9 -4
  653. data/third_party/abseil-cpp/absl/hash/hash.h +26 -2
  654. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +17 -17
  655. data/third_party/abseil-cpp/absl/hash/internal/hash.h +196 -91
  656. data/third_party/abseil-cpp/absl/hash/internal/low_level_hash.cc +2 -4
  657. data/third_party/abseil-cpp/absl/log/absl_vlog_is_on.h +2 -0
  658. data/third_party/abseil-cpp/absl/log/internal/check_op.cc +27 -22
  659. data/third_party/abseil-cpp/absl/log/internal/check_op.h +102 -80
  660. data/third_party/abseil-cpp/absl/log/internal/log_message.cc +90 -38
  661. data/third_party/abseil-cpp/absl/log/internal/log_message.h +80 -48
  662. data/third_party/abseil-cpp/absl/log/internal/proto.cc +0 -3
  663. data/third_party/abseil-cpp/absl/log/internal/proto.h +25 -15
  664. data/third_party/abseil-cpp/absl/log/internal/structured_proto.cc +115 -0
  665. data/third_party/abseil-cpp/absl/log/internal/structured_proto.h +107 -0
  666. data/third_party/abseil-cpp/absl/log/internal/vlog_config.cc +8 -1
  667. data/third_party/abseil-cpp/absl/log/log_sink_registry.h +5 -2
  668. data/third_party/abseil-cpp/absl/log/vlog_is_on.h +2 -0
  669. data/third_party/abseil-cpp/absl/meta/type_traits.h +16 -6
  670. data/third_party/abseil-cpp/absl/numeric/int128.h +15 -3
  671. data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +6 -4
  672. data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +6 -3
  673. data/third_party/abseil-cpp/absl/random/bernoulli_distribution.h +3 -1
  674. data/third_party/abseil-cpp/absl/random/beta_distribution.h +3 -1
  675. data/third_party/abseil-cpp/absl/random/bit_gen_ref.h +2 -1
  676. data/third_party/abseil-cpp/absl/random/discrete_distribution.cc +10 -0
  677. data/third_party/abseil-cpp/absl/random/discrete_distribution.h +4 -2
  678. data/third_party/abseil-cpp/absl/random/exponential_distribution.h +1 -0
  679. data/third_party/abseil-cpp/absl/random/gaussian_distribution.h +2 -1
  680. data/third_party/abseil-cpp/absl/random/internal/distribution_caller.h +3 -1
  681. data/third_party/abseil-cpp/absl/random/internal/iostream_state_saver.h +5 -2
  682. data/third_party/abseil-cpp/absl/random/internal/platform.h +12 -12
  683. data/third_party/abseil-cpp/absl/random/internal/randen_detect.cc +56 -5
  684. data/third_party/abseil-cpp/absl/random/internal/randen_engine.h +2 -1
  685. data/third_party/abseil-cpp/absl/random/internal/uniform_helper.h +2 -2
  686. data/third_party/abseil-cpp/absl/random/internal/wide_multiply.h +0 -1
  687. data/third_party/abseil-cpp/absl/random/log_uniform_int_distribution.h +1 -4
  688. data/third_party/abseil-cpp/absl/random/poisson_distribution.h +4 -3
  689. data/third_party/abseil-cpp/absl/random/seed_gen_exception.cc +2 -3
  690. data/third_party/abseil-cpp/absl/random/seed_sequences.h +1 -2
  691. data/third_party/abseil-cpp/absl/random/uniform_int_distribution.h +2 -1
  692. data/third_party/abseil-cpp/absl/random/uniform_real_distribution.h +2 -0
  693. data/third_party/abseil-cpp/absl/random/zipf_distribution.h +5 -4
  694. data/third_party/abseil-cpp/absl/status/internal/status_internal.cc +8 -4
  695. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +1 -1
  696. data/third_party/abseil-cpp/absl/status/status.h +1 -1
  697. data/third_party/abseil-cpp/absl/strings/ascii.cc +41 -26
  698. data/third_party/abseil-cpp/absl/strings/ascii.h +48 -8
  699. data/third_party/abseil-cpp/absl/strings/charconv.cc +4 -7
  700. data/third_party/abseil-cpp/absl/strings/charset.h +3 -4
  701. data/third_party/abseil-cpp/absl/strings/cord.h +5 -19
  702. data/third_party/abseil-cpp/absl/strings/escaping.cc +56 -48
  703. data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +1 -1
  704. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +48 -15
  705. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +3 -2
  706. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +35 -0
  707. data/third_party/abseil-cpp/absl/strings/match.h +21 -11
  708. data/third_party/abseil-cpp/absl/strings/numbers.cc +2 -1
  709. data/third_party/abseil-cpp/absl/strings/str_cat.h +11 -0
  710. data/third_party/abseil-cpp/absl/strings/str_split.h +18 -1
  711. data/third_party/abseil-cpp/absl/strings/string_view.h +20 -19
  712. data/third_party/abseil-cpp/absl/strings/strip.h +11 -8
  713. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.cc +16 -10
  714. data/third_party/abseil-cpp/absl/synchronization/blocking_counter.h +6 -0
  715. data/third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc +5 -1
  716. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +38 -12
  717. data/third_party/abseil-cpp/absl/synchronization/notification.cc +10 -2
  718. data/third_party/abseil-cpp/absl/synchronization/notification.h +11 -1
  719. data/third_party/abseil-cpp/absl/time/duration.cc +6 -51
  720. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_fixed.cc +1 -1
  721. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +1 -1
  722. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_if.cc +3 -3
  723. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.cc +2 -2
  724. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_impl.h +2 -2
  725. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +3 -3
  726. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.h +2 -2
  727. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +1 -1
  728. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.h +1 -1
  729. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_lookup.cc +3 -2
  730. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_posix.cc +1 -1
  731. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +6 -4
  732. data/third_party/abseil-cpp/absl/time/time.h +84 -23
  733. data/third_party/abseil-cpp/absl/types/internal/span.h +3 -2
  734. data/third_party/abseil-cpp/absl/types/optional.h +4 -2
  735. data/third_party/abseil-cpp/absl/types/span.h +85 -43
  736. data/third_party/boringssl-with-bazel/src/crypto/aes/aes.cc +41 -0
  737. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.cc +16 -0
  738. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.cc +15 -0
  739. data/third_party/boringssl-with-bazel/src/crypto/asn1/internal.h +19 -3
  740. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.cc +79 -48
  741. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.cc +11 -19
  742. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_typ.cc +3 -7
  743. data/third_party/boringssl-with-bazel/src/crypto/bcm_support.h +0 -35
  744. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.cc +0 -2
  745. data/third_party/boringssl-with-bazel/src/crypto/bio/internal.h +3 -5
  746. data/third_party/boringssl-with-bazel/src/crypto/bio/socket.cc +0 -3
  747. data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.cc +0 -2
  748. data/third_party/boringssl-with-bazel/src/crypto/bn/convert.cc +31 -47
  749. data/third_party/boringssl-with-bazel/src/crypto/bn/div.cc +100 -0
  750. data/third_party/boringssl-with-bazel/src/crypto/bn/exponentiation.cc +166 -0
  751. data/third_party/boringssl-with-bazel/src/crypto/bn/sqrt.cc +93 -0
  752. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbb.cc +14 -8
  753. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.cc +1 -1
  754. data/third_party/boringssl-with-bazel/src/crypto/bytestring/internal.h +3 -3
  755. data/third_party/boringssl-with-bazel/src/crypto/chacha/internal.h +4 -4
  756. data/third_party/boringssl-with-bazel/src/crypto/cipher/derive_key.cc +13 -15
  757. data/third_party/boringssl-with-bazel/src/crypto/cipher/e_aeseax.cc +289 -0
  758. data/third_party/boringssl-with-bazel/src/crypto/cipher/e_aesgcmsiv.cc +179 -102
  759. data/third_party/boringssl-with-bazel/src/crypto/cipher/internal.h +3 -3
  760. data/third_party/boringssl-with-bazel/src/crypto/cms/cms.cc +172 -0
  761. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.cc +28 -5
  762. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_linux.h +11 -9
  763. data/third_party/boringssl-with-bazel/src/crypto/cpu_intel.cc +0 -6
  764. data/third_party/boringssl-with-bazel/src/crypto/crypto.cc +1 -1
  765. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +3 -3
  766. data/third_party/boringssl-with-bazel/src/crypto/des/internal.h +3 -3
  767. data/third_party/boringssl-with-bazel/src/crypto/dh/dh_asn1.cc +13 -14
  768. data/third_party/boringssl-with-bazel/src/crypto/dh/params.cc +27 -61
  769. data/third_party/boringssl-with-bazel/src/crypto/digest/digest_extra.cc +16 -8
  770. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.cc +112 -122
  771. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa_asn1.cc +23 -35
  772. data/third_party/boringssl-with-bazel/src/crypto/dsa/internal.h +3 -3
  773. data/third_party/boringssl-with-bazel/src/crypto/ec/ec_asn1.cc +47 -63
  774. data/third_party/boringssl-with-bazel/src/crypto/ec/hash_to_curve.cc +60 -68
  775. data/third_party/boringssl-with-bazel/src/crypto/ec/internal.h +3 -3
  776. data/third_party/boringssl-with-bazel/src/crypto/ecdsa/ecdsa_asn1.cc +11 -17
  777. data/third_party/boringssl-with-bazel/src/crypto/err/err.cc +0 -2
  778. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_asn1.cc +10 -11
  779. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_ctx.cc +10 -11
  780. data/third_party/boringssl-with-bazel/src/crypto/evp/internal.h +3 -3
  781. data/third_party/boringssl-with-bazel/src/crypto/evp/p_dsa_asn1.cc +6 -6
  782. data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec_asn1.cc +6 -6
  783. data/third_party/boringssl-with-bazel/src/crypto/evp/p_ed25519_asn1.cc +6 -6
  784. data/third_party/boringssl-with-bazel/src/crypto/evp/p_rsa_asn1.cc +6 -6
  785. data/third_party/boringssl-with-bazel/src/crypto/evp/p_x25519_asn1.cc +6 -6
  786. data/third_party/boringssl-with-bazel/src/crypto/evp/sign.cc +23 -42
  787. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/aes.cc.inc +29 -18
  788. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/gcm.cc.inc +10 -10
  789. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/internal.h +16 -45
  790. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/key_wrap.cc.inc +5 -4
  791. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/mode_wrappers.cc.inc +15 -6
  792. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.cc +3 -3
  793. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm_interface.h +101 -5
  794. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.cc.inc +96 -187
  795. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.cc.inc +24 -512
  796. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd.cc.inc +58 -80
  797. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd_extra.cc.inc +29 -45
  798. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +27 -25
  799. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/jacobi.cc.inc +7 -16
  800. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.cc.inc +27 -48
  801. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.cc.inc +34 -34
  802. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.cc.inc +102 -154
  803. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/rsaz_exp.h +3 -3
  804. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/shift.cc.inc +3 -8
  805. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/sqrt.cc.inc +1 -78
  806. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.cc.inc +10 -17
  807. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/internal.h +3 -3
  808. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/delocate.h +15 -8
  809. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/check.cc.inc +40 -53
  810. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.cc.inc +57 -76
  811. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.cc.inc +4 -10
  812. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/internal.h +3 -3
  813. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +3 -3
  814. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.cc.inc +37 -52
  815. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.cc.inc +13 -20
  816. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +3 -3
  817. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.cc.inc +28 -39
  818. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-nistz.h +3 -3
  819. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.cc.inc +6 -11
  820. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/keccak/internal.h +3 -3
  821. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/mldsa/fips_known_values.inc +1345 -0
  822. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/mldsa/mldsa.cc.inc +335 -28
  823. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/mlkem/fips_known_values.inc +411 -0
  824. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/mlkem/mlkem.cc.inc +265 -33
  825. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +3 -3
  826. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.cc.inc +1 -1
  827. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +3 -3
  828. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/padding.cc.inc +19 -26
  829. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.cc.inc +7 -7
  830. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.cc.inc +121 -138
  831. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.cc.inc +96 -83
  832. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/service_indicator/internal.h +3 -3
  833. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/internal.h +8 -20
  834. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/slhdsa/fips_known_values.inc +674 -0
  835. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/slhdsa/slhdsa.cc.inc +235 -60
  836. data/third_party/boringssl-with-bazel/src/crypto/fuzzer_mode.cc +30 -0
  837. data/third_party/boringssl-with-bazel/src/crypto/hrss/internal.h +3 -3
  838. data/third_party/boringssl-with-bazel/src/crypto/internal.h +39 -30
  839. data/third_party/boringssl-with-bazel/src/crypto/lhash/internal.h +3 -3
  840. data/third_party/boringssl-with-bazel/src/crypto/md5/internal.h +3 -3
  841. data/third_party/boringssl-with-bazel/src/crypto/mem.cc +0 -2
  842. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.cc +2 -8
  843. data/third_party/boringssl-with-bazel/src/crypto/pem/internal.h +3 -3
  844. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_lib.cc +8 -13
  845. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/internal.h +22 -8
  846. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7.cc +19 -17
  847. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.cc +134 -136
  848. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/internal.h +14 -8
  849. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/p5_pbev2.cc +25 -21
  850. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.cc +36 -52
  851. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.cc +97 -79
  852. data/third_party/boringssl-with-bazel/src/crypto/poly1305/internal.h +3 -3
  853. data/third_party/boringssl-with-bazel/src/crypto/pool/internal.h +3 -3
  854. data/third_party/boringssl-with-bazel/src/crypto/rand/deterministic.cc +1 -1
  855. data/third_party/boringssl-with-bazel/src/crypto/rand/fork_detect.cc +2 -2
  856. data/third_party/boringssl-with-bazel/src/crypto/rand/getentropy.cc +1 -1
  857. data/third_party/boringssl-with-bazel/src/crypto/rand/{sysrand_internal.h → internal.h} +22 -4
  858. data/third_party/boringssl-with-bazel/src/crypto/rand/ios.cc +1 -1
  859. data/third_party/boringssl-with-bazel/src/crypto/rand/trusty.cc +1 -1
  860. data/third_party/boringssl-with-bazel/src/crypto/rand/urandom.cc +1 -1
  861. data/third_party/boringssl-with-bazel/src/crypto/rand/windows.cc +1 -5
  862. data/third_party/boringssl-with-bazel/src/crypto/rsa/internal.h +3 -3
  863. data/third_party/boringssl-with-bazel/src/crypto/rsa/rsa_crypt.cc +14 -22
  864. data/third_party/boringssl-with-bazel/src/crypto/spake2plus/internal.h +3 -3
  865. data/third_party/boringssl-with-bazel/src/crypto/thread_win.cc +0 -2
  866. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +3 -3
  867. data/third_party/boringssl-with-bazel/src/crypto/x509/a_sign.cc +3 -5
  868. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.cc +8 -12
  869. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +15 -3
  870. data/third_party/boringssl-with-bazel/src/crypto/x509/v3_conf.cc +16 -24
  871. data/third_party/boringssl-with-bazel/src/crypto/x509/v3_info.cc +18 -21
  872. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.cc +10 -3
  873. data/third_party/boringssl-with-bazel/src/crypto/x509/x_algor.cc +9 -0
  874. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.cc +10 -1
  875. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.cc +64 -85
  876. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.cc +16 -32
  877. data/third_party/boringssl-with-bazel/src/gen/crypto/err_data.cc +576 -567
  878. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +16 -8
  879. data/third_party/boringssl-with-bazel/src/include/openssl/aes.h +1 -1
  880. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +6 -54
  881. data/third_party/boringssl-with-bazel/src/include/openssl/asn1t.h +1 -1
  882. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +8 -4
  883. data/third_party/boringssl-with-bazel/src/include/openssl/base64.h +1 -1
  884. data/third_party/boringssl-with-bazel/src/include/openssl/bcm_public.h +1 -1
  885. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +1 -1
  886. data/third_party/boringssl-with-bazel/src/include/openssl/blake2.h +1 -1
  887. data/third_party/boringssl-with-bazel/src/include/openssl/blowfish.h +1 -1
  888. data/third_party/boringssl-with-bazel/src/include/openssl/bn.h +1 -1
  889. data/third_party/boringssl-with-bazel/src/include/openssl/buf.h +1 -1
  890. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +7 -1
  891. data/third_party/boringssl-with-bazel/src/include/openssl/cast.h +1 -1
  892. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  893. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +1 -1
  894. data/third_party/boringssl-with-bazel/src/include/openssl/cmac.h +1 -1
  895. data/third_party/boringssl-with-bazel/src/include/openssl/cms.h +146 -0
  896. data/third_party/boringssl-with-bazel/src/include/openssl/conf.h +1 -1
  897. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +23 -3
  898. data/third_party/boringssl-with-bazel/src/include/openssl/ctrdrbg.h +1 -1
  899. data/third_party/boringssl-with-bazel/src/include/openssl/curve25519.h +1 -1
  900. data/third_party/boringssl-with-bazel/src/include/openssl/des.h +1 -1
  901. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +1 -1
  902. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +19 -7
  903. data/third_party/boringssl-with-bazel/src/include/openssl/dsa.h +1 -1
  904. data/third_party/boringssl-with-bazel/src/include/openssl/e_os2.h +1 -1
  905. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +1 -1
  906. data/third_party/boringssl-with-bazel/src/include/openssl/ec_key.h +1 -1
  907. data/third_party/boringssl-with-bazel/src/include/openssl/ecdh.h +1 -1
  908. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +1 -1
  909. data/third_party/boringssl-with-bazel/src/include/openssl/engine.h +1 -1
  910. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +2 -1
  911. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +1 -1
  912. data/third_party/boringssl-with-bazel/src/include/openssl/ex_data.h +1 -1
  913. data/third_party/boringssl-with-bazel/src/include/openssl/experimental/kyber.h +1 -1
  914. data/third_party/boringssl-with-bazel/src/include/openssl/hkdf.h +1 -1
  915. data/third_party/boringssl-with-bazel/src/include/openssl/hmac.h +1 -1
  916. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +4 -4
  917. data/third_party/boringssl-with-bazel/src/include/openssl/hrss.h +1 -1
  918. data/third_party/boringssl-with-bazel/src/include/openssl/kdf.h +1 -1
  919. data/third_party/boringssl-with-bazel/src/include/openssl/lhash.h +1 -1
  920. data/third_party/boringssl-with-bazel/src/include/openssl/md4.h +1 -1
  921. data/third_party/boringssl-with-bazel/src/include/openssl/md5.h +1 -1
  922. data/third_party/boringssl-with-bazel/src/include/openssl/mem.h +1 -1
  923. data/third_party/boringssl-with-bazel/src/include/openssl/mldsa.h +1 -1
  924. data/third_party/boringssl-with-bazel/src/include/openssl/mlkem.h +1 -1
  925. data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +1 -1
  926. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +1 -1
  927. data/third_party/boringssl-with-bazel/src/include/openssl/obj_mac.h +1 -1
  928. data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +10 -4
  929. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +1 -1
  930. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +19 -6
  931. data/third_party/boringssl-with-bazel/src/include/openssl/poly1305.h +1 -1
  932. data/third_party/boringssl-with-bazel/src/include/openssl/pool.h +1 -1
  933. data/third_party/boringssl-with-bazel/src/include/openssl/posix_time.h +1 -1
  934. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +2 -2
  935. data/third_party/boringssl-with-bazel/src/include/openssl/rc4.h +1 -1
  936. data/third_party/boringssl-with-bazel/src/include/openssl/ripemd.h +1 -1
  937. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +2 -2
  938. data/third_party/boringssl-with-bazel/src/include/openssl/service_indicator.h +1 -1
  939. data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +1 -1
  940. data/third_party/boringssl-with-bazel/src/include/openssl/siphash.h +1 -1
  941. data/third_party/boringssl-with-bazel/src/include/openssl/slhdsa.h +1 -1
  942. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +1 -1
  943. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +291 -40
  944. data/third_party/boringssl-with-bazel/src/include/openssl/stack.h +1 -1
  945. data/third_party/boringssl-with-bazel/src/include/openssl/target.h +0 -5
  946. data/third_party/boringssl-with-bazel/src/include/openssl/thread.h +1 -1
  947. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +9 -1
  948. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +1 -1
  949. data/third_party/boringssl-with-bazel/src/include/openssl/type_check.h +1 -1
  950. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +7 -4
  951. data/third_party/boringssl-with-bazel/src/ssl/dtls_method.cc +2 -0
  952. data/third_party/boringssl-with-bazel/src/ssl/dtls_record.cc +32 -26
  953. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +49 -49
  954. data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +253 -50
  955. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +12 -12
  956. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +7 -5
  957. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +2 -1
  958. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +24 -32
  959. data/third_party/boringssl-with-bazel/src/ssl/internal.h +93 -4
  960. data/third_party/boringssl-with-bazel/src/ssl/ssl_aead_ctx.cc +6 -12
  961. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +18 -4
  962. data/third_party/boringssl-with-bazel/src/ssl/ssl_credential.cc +83 -7
  963. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +1 -1
  964. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +173 -19
  965. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +5 -18
  966. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +28 -15
  967. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +1 -1
  968. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +31 -7
  969. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +13 -1
  970. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +7 -11
  971. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +13 -11
  972. data/third_party/boringssl-with-bazel/src/ssl/tls_record.cc +2 -5
  973. data/third_party/upb/upb/hash/common.c +310 -189
  974. data/third_party/upb/upb/hash/common.h +44 -43
  975. data/third_party/upb/upb/hash/int_table.h +29 -5
  976. data/third_party/upb/upb/hash/str_table.h +6 -0
  977. data/third_party/upb/upb/mem/arena.c +180 -57
  978. data/third_party/upb/upb/mem/arena.h +10 -0
  979. data/third_party/upb/upb/mem/internal/arena.h +62 -24
  980. data/third_party/upb/upb/message/accessors.c +1 -5
  981. data/third_party/upb/upb/message/array.c +7 -6
  982. data/third_party/upb/upb/message/array.h +4 -4
  983. data/third_party/upb/upb/message/internal/accessors.h +3 -3
  984. data/third_party/upb/upb/message/internal/extension.c +0 -12
  985. data/third_party/upb/upb/message/internal/extension.h +0 -4
  986. data/third_party/upb/upb/message/internal/iterator.h +3 -3
  987. data/third_party/upb/upb/message/internal/map.h +75 -20
  988. data/third_party/upb/upb/message/internal/map_sorter.h +10 -2
  989. data/third_party/upb/upb/message/internal/message.h +53 -5
  990. data/third_party/upb/upb/message/map.c +68 -20
  991. data/third_party/upb/upb/message/map.h +8 -1
  992. data/third_party/upb/upb/message/map_gencode_util.h +3 -45
  993. data/third_party/upb/upb/message/map_sorter.c +32 -8
  994. data/third_party/upb/upb/message/merge.h +3 -3
  995. data/third_party/upb/upb/message/message.c +120 -14
  996. data/third_party/upb/upb/message/message.h +17 -8
  997. data/third_party/upb/upb/mini_descriptor/build_enum.c +15 -5
  998. data/third_party/upb/upb/mini_descriptor/decode.c +18 -2
  999. data/third_party/upb/upb/mini_descriptor/link.c +4 -0
  1000. data/third_party/upb/upb/mini_table/extension.h +8 -1
  1001. data/third_party/upb/upb/mini_table/extension_registry.c +1 -1
  1002. data/third_party/upb/upb/mini_table/internal/enum.h +1 -1
  1003. data/third_party/upb/upb/mini_table/internal/extension.h +24 -1
  1004. data/third_party/upb/upb/mini_table/internal/field.h +4 -4
  1005. data/third_party/upb/upb/mini_table/internal/message.h +1 -1
  1006. data/third_party/upb/upb/port/def.inc +32 -16
  1007. data/third_party/upb/upb/port/undef.inc +1 -0
  1008. data/third_party/upb/upb/reflection/def_pool.h +2 -2
  1009. data/third_party/upb/upb/reflection/descriptor_bootstrap.h +3 -3
  1010. data/third_party/upb/upb/reflection/enum_def.c +4 -4
  1011. data/third_party/upb/upb/reflection/enum_reserved_range.c +1 -1
  1012. data/third_party/upb/upb/reflection/enum_value_def.c +9 -8
  1013. data/third_party/upb/upb/reflection/extension_range.c +1 -2
  1014. data/third_party/upb/upb/reflection/field_def.c +3 -5
  1015. data/third_party/upb/upb/reflection/field_def.h +1 -1
  1016. data/third_party/upb/upb/reflection/file_def.c +4 -5
  1017. data/third_party/upb/upb/reflection/internal/def_builder.h +35 -10
  1018. data/third_party/upb/upb/reflection/internal/enum_value_def.h +1 -1
  1019. data/third_party/upb/upb/reflection/internal/upb_edition_defaults.h +1 -1
  1020. data/third_party/upb/upb/reflection/message_def.c +4 -7
  1021. data/third_party/upb/upb/reflection/message_reserved_range.c +1 -1
  1022. data/third_party/upb/upb/reflection/method_def.c +1 -1
  1023. data/third_party/upb/upb/reflection/oneof_def.c +3 -3
  1024. data/third_party/upb/upb/reflection/service_def.c +2 -5
  1025. data/third_party/upb/upb/text/encode.c +16 -0
  1026. data/third_party/upb/upb/text/internal/encode.h +2 -1
  1027. data/third_party/upb/upb/wire/decode.c +104 -72
  1028. data/third_party/upb/upb/wire/encode.c +37 -13
  1029. data/third_party/upb/upb/wire/internal/decode_fast.c +2 -2
  1030. data/third_party/upb/upb/wire/internal/decode_fast.h +4 -0
  1031. metadata +43 -7
  1032. data/src/core/lib/iomgr/executor.cc +0 -441
  1033. data/src/core/lib/iomgr/executor.h +0 -119
  1034. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/aes/polyval.cc.inc +0 -89
@@ -0,0 +1,3046 @@
1
+ // Copyright 2018 The Abseil Authors.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // https://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ // A btree implementation of the STL set and map interfaces. A btree is smaller
16
+ // and generally also faster than STL set/map (refer to the benchmarks below).
17
+ // The red-black tree implementation of STL set/map has an overhead of 3
18
+ // pointers (left, right and parent) plus the node color information for each
19
+ // stored value. So a set<int32_t> consumes 40 bytes for each value stored in
20
+ // 64-bit mode. This btree implementation stores multiple values on fixed
21
+ // size nodes (usually 256 bytes) and doesn't store child pointers for leaf
22
+ // nodes. The result is that a btree_set<int32_t> may use much less memory per
23
+ // stored value. For the random insertion benchmark in btree_bench.cc, a
24
+ // btree_set<int32_t> with node-size of 256 uses 5.1 bytes per stored value.
25
+ //
26
+ // The packing of multiple values on to each node of a btree has another effect
27
+ // besides better space utilization: better cache locality due to fewer cache
28
+ // lines being accessed. Better cache locality translates into faster
29
+ // operations.
30
+ //
31
+ // CAVEATS
32
+ //
33
+ // Insertions and deletions on a btree can cause splitting, merging or
34
+ // rebalancing of btree nodes. And even without these operations, insertions
35
+ // and deletions on a btree will move values around within a node. In both
36
+ // cases, the result is that insertions and deletions can invalidate iterators
37
+ // pointing to values other than the one being inserted/deleted. Therefore, this
38
+ // container does not provide pointer stability. This is notably different from
39
+ // STL set/map which takes care to not invalidate iterators on insert/erase
40
+ // except, of course, for iterators pointing to the value being erased. A
41
+ // partial workaround when erasing is available: erase() returns an iterator
42
+ // pointing to the item just after the one that was erased (or end() if none
43
+ // exists).
44
+
45
+ #ifndef ABSL_CONTAINER_INTERNAL_BTREE_H_
46
+ #define ABSL_CONTAINER_INTERNAL_BTREE_H_
47
+
48
+ #include <algorithm>
49
+ #include <cassert>
50
+ #include <cstddef>
51
+ #include <cstdint>
52
+ #include <cstring>
53
+ #include <functional>
54
+ #include <iterator>
55
+ #include <limits>
56
+ #include <string>
57
+ #include <type_traits>
58
+ #include <utility>
59
+
60
+ #include "absl/base/config.h"
61
+ #include "absl/base/internal/raw_logging.h"
62
+ #include "absl/base/macros.h"
63
+ #include "absl/container/internal/common.h"
64
+ #include "absl/container/internal/common_policy_traits.h"
65
+ #include "absl/container/internal/compressed_tuple.h"
66
+ #include "absl/container/internal/container_memory.h"
67
+ #include "absl/container/internal/layout.h"
68
+ #include "absl/memory/memory.h"
69
+ #include "absl/meta/type_traits.h"
70
+ #include "absl/strings/cord.h"
71
+ #include "absl/strings/string_view.h"
72
+ #include "absl/types/compare.h"
73
+
74
+ namespace absl {
75
+ ABSL_NAMESPACE_BEGIN
76
+ namespace container_internal {
77
+
78
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
79
+ #error ABSL_BTREE_ENABLE_GENERATIONS cannot be directly set
80
+ #elif (defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
81
+ defined(ABSL_HAVE_HWADDRESS_SANITIZER) || \
82
+ defined(ABSL_HAVE_MEMORY_SANITIZER)) && \
83
+ !defined(NDEBUG_SANITIZER) // If defined, performance is important.
84
+ // When compiled in sanitizer mode, we add generation integers to the nodes and
85
+ // iterators. When iterators are used, we validate that the container has not
86
+ // been mutated since the iterator was constructed.
87
+ #define ABSL_BTREE_ENABLE_GENERATIONS
88
+ #endif
89
+
90
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
91
+ constexpr bool BtreeGenerationsEnabled() { return true; }
92
+ #else
93
+ constexpr bool BtreeGenerationsEnabled() { return false; }
94
+ #endif
95
+
96
+ template <typename Compare, typename T, typename U>
97
+ using compare_result_t = absl::result_of_t<const Compare(const T &, const U &)>;
98
+
99
+ // A helper class that indicates if the Compare parameter is a key-compare-to
100
+ // comparator.
101
+ template <typename Compare, typename T>
102
+ using btree_is_key_compare_to =
103
+ std::is_convertible<compare_result_t<Compare, T, T>, absl::weak_ordering>;
104
+
105
+ struct StringBtreeDefaultLess {
106
+ using is_transparent = void;
107
+
108
+ StringBtreeDefaultLess() = default;
109
+
110
+ // Compatibility constructor.
111
+ StringBtreeDefaultLess(std::less<std::string>) {} // NOLINT
112
+ StringBtreeDefaultLess(std::less<absl::string_view>) {} // NOLINT
113
+
114
+ // Allow converting to std::less for use in key_comp()/value_comp().
115
+ explicit operator std::less<std::string>() const { return {}; }
116
+ explicit operator std::less<absl::string_view>() const { return {}; }
117
+ explicit operator std::less<absl::Cord>() const { return {}; }
118
+
119
+ absl::weak_ordering operator()(absl::string_view lhs,
120
+ absl::string_view rhs) const {
121
+ return compare_internal::compare_result_as_ordering(lhs.compare(rhs));
122
+ }
123
+ StringBtreeDefaultLess(std::less<absl::Cord>) {} // NOLINT
124
+ absl::weak_ordering operator()(const absl::Cord &lhs,
125
+ const absl::Cord &rhs) const {
126
+ return compare_internal::compare_result_as_ordering(lhs.Compare(rhs));
127
+ }
128
+ absl::weak_ordering operator()(const absl::Cord &lhs,
129
+ absl::string_view rhs) const {
130
+ return compare_internal::compare_result_as_ordering(lhs.Compare(rhs));
131
+ }
132
+ absl::weak_ordering operator()(absl::string_view lhs,
133
+ const absl::Cord &rhs) const {
134
+ return compare_internal::compare_result_as_ordering(-rhs.Compare(lhs));
135
+ }
136
+ };
137
+
138
+ struct StringBtreeDefaultGreater {
139
+ using is_transparent = void;
140
+
141
+ StringBtreeDefaultGreater() = default;
142
+
143
+ StringBtreeDefaultGreater(std::greater<std::string>) {} // NOLINT
144
+ StringBtreeDefaultGreater(std::greater<absl::string_view>) {} // NOLINT
145
+
146
+ // Allow converting to std::greater for use in key_comp()/value_comp().
147
+ explicit operator std::greater<std::string>() const { return {}; }
148
+ explicit operator std::greater<absl::string_view>() const { return {}; }
149
+ explicit operator std::greater<absl::Cord>() const { return {}; }
150
+
151
+ absl::weak_ordering operator()(absl::string_view lhs,
152
+ absl::string_view rhs) const {
153
+ return compare_internal::compare_result_as_ordering(rhs.compare(lhs));
154
+ }
155
+ StringBtreeDefaultGreater(std::greater<absl::Cord>) {} // NOLINT
156
+ absl::weak_ordering operator()(const absl::Cord &lhs,
157
+ const absl::Cord &rhs) const {
158
+ return compare_internal::compare_result_as_ordering(rhs.Compare(lhs));
159
+ }
160
+ absl::weak_ordering operator()(const absl::Cord &lhs,
161
+ absl::string_view rhs) const {
162
+ return compare_internal::compare_result_as_ordering(-lhs.Compare(rhs));
163
+ }
164
+ absl::weak_ordering operator()(absl::string_view lhs,
165
+ const absl::Cord &rhs) const {
166
+ return compare_internal::compare_result_as_ordering(rhs.Compare(lhs));
167
+ }
168
+ };
169
+
170
+ // See below comments for checked_compare.
171
+ template <typename Compare, bool is_class = std::is_class<Compare>::value>
172
+ struct checked_compare_base : Compare {
173
+ using Compare::Compare;
174
+ explicit checked_compare_base(Compare c) : Compare(std::move(c)) {}
175
+ const Compare &comp() const { return *this; }
176
+ };
177
+ template <typename Compare>
178
+ struct checked_compare_base<Compare, false> {
179
+ explicit checked_compare_base(Compare c) : compare(std::move(c)) {}
180
+ const Compare &comp() const { return compare; }
181
+ Compare compare;
182
+ };
183
+
184
+ // A mechanism for opting out of checked_compare for use only in btree_test.cc.
185
+ struct BtreeTestOnlyCheckedCompareOptOutBase {};
186
+
187
+ // A helper class to adapt the specified comparator for two use cases:
188
+ // (1) When using common Abseil string types with common comparison functors,
189
+ // convert a boolean comparison into a three-way comparison that returns an
190
+ // `absl::weak_ordering`. This helper class is specialized for
191
+ // less<std::string>, greater<std::string>, less<string_view>,
192
+ // greater<string_view>, less<absl::Cord>, and greater<absl::Cord>.
193
+ // (2) Adapt the comparator to diagnose cases of non-strict-weak-ordering (see
194
+ // https://en.cppreference.com/w/cpp/named_req/Compare) in debug mode. Whenever
195
+ // a comparison is made, we will make assertions to verify that the comparator
196
+ // is valid.
197
+ template <typename Compare, typename Key>
198
+ struct key_compare_adapter {
199
+ // Inherit from checked_compare_base to support function pointers and also
200
+ // keep empty-base-optimization (EBO) support for classes.
201
+ // Note: we can't use CompressedTuple here because that would interfere
202
+ // with the EBO for `btree::rightmost_`. `btree::rightmost_` is itself a
203
+ // CompressedTuple and nested `CompressedTuple`s don't support EBO.
204
+ // TODO(b/214288561): use CompressedTuple instead once it supports EBO for
205
+ // nested `CompressedTuple`s.
206
+ struct checked_compare : checked_compare_base<Compare> {
207
+ private:
208
+ using Base = typename checked_compare::checked_compare_base;
209
+ using Base::comp;
210
+
211
+ // If possible, returns whether `t` is equivalent to itself. We can only do
212
+ // this for `Key`s because we can't be sure that it's safe to call
213
+ // `comp()(k, k)` otherwise. Even if SFINAE allows it, there could be a
214
+ // compilation failure inside the implementation of the comparison operator.
215
+ bool is_self_equivalent(const Key &k) const {
216
+ // Note: this works for both boolean and three-way comparators.
217
+ return comp()(k, k) == 0;
218
+ }
219
+ // If we can't compare `t` with itself, returns true unconditionally.
220
+ template <typename T>
221
+ bool is_self_equivalent(const T &) const {
222
+ return true;
223
+ }
224
+
225
+ public:
226
+ using Base::Base;
227
+ checked_compare(Compare comp) : Base(std::move(comp)) {} // NOLINT
228
+
229
+ // Allow converting to Compare for use in key_comp()/value_comp().
230
+ explicit operator Compare() const { return comp(); }
231
+
232
+ template <typename T, typename U,
233
+ absl::enable_if_t<
234
+ std::is_same<bool, compare_result_t<Compare, T, U>>::value,
235
+ int> = 0>
236
+ bool operator()(const T &lhs, const U &rhs) const {
237
+ // NOTE: if any of these assertions fail, then the comparator does not
238
+ // establish a strict-weak-ordering (see
239
+ // https://en.cppreference.com/w/cpp/named_req/Compare).
240
+ assert(is_self_equivalent(lhs));
241
+ assert(is_self_equivalent(rhs));
242
+ const bool lhs_comp_rhs = comp()(lhs, rhs);
243
+ assert(!lhs_comp_rhs || !comp()(rhs, lhs));
244
+ return lhs_comp_rhs;
245
+ }
246
+
247
+ template <
248
+ typename T, typename U,
249
+ absl::enable_if_t<std::is_convertible<compare_result_t<Compare, T, U>,
250
+ absl::weak_ordering>::value,
251
+ int> = 0>
252
+ absl::weak_ordering operator()(const T &lhs, const U &rhs) const {
253
+ // NOTE: if any of these assertions fail, then the comparator does not
254
+ // establish a strict-weak-ordering (see
255
+ // https://en.cppreference.com/w/cpp/named_req/Compare).
256
+ assert(is_self_equivalent(lhs));
257
+ assert(is_self_equivalent(rhs));
258
+ const absl::weak_ordering lhs_comp_rhs = comp()(lhs, rhs);
259
+ #ifndef NDEBUG
260
+ const absl::weak_ordering rhs_comp_lhs = comp()(rhs, lhs);
261
+ if (lhs_comp_rhs > 0) {
262
+ assert(rhs_comp_lhs < 0 && "lhs_comp_rhs > 0 -> rhs_comp_lhs < 0");
263
+ } else if (lhs_comp_rhs == 0) {
264
+ assert(rhs_comp_lhs == 0 && "lhs_comp_rhs == 0 -> rhs_comp_lhs == 0");
265
+ } else {
266
+ assert(rhs_comp_lhs > 0 && "lhs_comp_rhs < 0 -> rhs_comp_lhs > 0");
267
+ }
268
+ #endif
269
+ return lhs_comp_rhs;
270
+ }
271
+ };
272
+ using type = absl::conditional_t<
273
+ std::is_base_of<BtreeTestOnlyCheckedCompareOptOutBase, Compare>::value,
274
+ Compare, checked_compare>;
275
+ };
276
+
277
+ template <>
278
+ struct key_compare_adapter<std::less<std::string>, std::string> {
279
+ using type = StringBtreeDefaultLess;
280
+ };
281
+
282
+ template <>
283
+ struct key_compare_adapter<std::greater<std::string>, std::string> {
284
+ using type = StringBtreeDefaultGreater;
285
+ };
286
+
287
+ template <>
288
+ struct key_compare_adapter<std::less<absl::string_view>, absl::string_view> {
289
+ using type = StringBtreeDefaultLess;
290
+ };
291
+
292
+ template <>
293
+ struct key_compare_adapter<std::greater<absl::string_view>, absl::string_view> {
294
+ using type = StringBtreeDefaultGreater;
295
+ };
296
+
297
+ template <>
298
+ struct key_compare_adapter<std::less<absl::Cord>, absl::Cord> {
299
+ using type = StringBtreeDefaultLess;
300
+ };
301
+
302
+ template <>
303
+ struct key_compare_adapter<std::greater<absl::Cord>, absl::Cord> {
304
+ using type = StringBtreeDefaultGreater;
305
+ };
306
+
307
+ // Detects an 'absl_btree_prefer_linear_node_search' member. This is
308
+ // a protocol used as an opt-in or opt-out of linear search.
309
+ //
310
+ // For example, this would be useful for key types that wrap an integer
311
+ // and define their own cheap operator<(). For example:
312
+ //
313
+ // class K {
314
+ // public:
315
+ // using absl_btree_prefer_linear_node_search = std::true_type;
316
+ // ...
317
+ // private:
318
+ // friend bool operator<(K a, K b) { return a.k_ < b.k_; }
319
+ // int k_;
320
+ // };
321
+ //
322
+ // btree_map<K, V> m; // Uses linear search
323
+ //
324
+ // If T has the preference tag, then it has a preference.
325
+ // Btree will use the tag's truth value.
326
+ template <typename T, typename = void>
327
+ struct has_linear_node_search_preference : std::false_type {};
328
+ template <typename T, typename = void>
329
+ struct prefers_linear_node_search : std::false_type {};
330
+ template <typename T>
331
+ struct has_linear_node_search_preference<
332
+ T, absl::void_t<typename T::absl_btree_prefer_linear_node_search>>
333
+ : std::true_type {};
334
+ template <typename T>
335
+ struct prefers_linear_node_search<
336
+ T, absl::void_t<typename T::absl_btree_prefer_linear_node_search>>
337
+ : T::absl_btree_prefer_linear_node_search {};
338
+
339
+ template <typename Compare, typename Key>
340
+ constexpr bool compare_has_valid_result_type() {
341
+ using compare_result_type = compare_result_t<Compare, Key, Key>;
342
+ return std::is_same<compare_result_type, bool>::value ||
343
+ std::is_convertible<compare_result_type, absl::weak_ordering>::value;
344
+ }
345
+
346
+ template <typename original_key_compare, typename value_type>
347
+ class map_value_compare {
348
+ template <typename Params>
349
+ friend class btree;
350
+
351
+ // Note: this `protected` is part of the API of std::map::value_compare. See
352
+ // https://en.cppreference.com/w/cpp/container/map/value_compare.
353
+ protected:
354
+ explicit map_value_compare(original_key_compare c) : comp(std::move(c)) {}
355
+
356
+ original_key_compare comp; // NOLINT
357
+
358
+ public:
359
+ auto operator()(const value_type &lhs, const value_type &rhs) const
360
+ -> decltype(comp(lhs.first, rhs.first)) {
361
+ return comp(lhs.first, rhs.first);
362
+ }
363
+ };
364
+
365
+ template <typename Key, typename Compare, typename Alloc, int TargetNodeSize,
366
+ bool IsMulti, bool IsMap, typename SlotPolicy>
367
+ struct common_params : common_policy_traits<SlotPolicy> {
368
+ using original_key_compare = Compare;
369
+
370
+ // If Compare is a common comparator for a string-like type, then we adapt it
371
+ // to use heterogeneous lookup and to be a key-compare-to comparator.
372
+ // We also adapt the comparator to diagnose invalid comparators in debug mode.
373
+ // We disable this when `Compare` is invalid in a way that will cause
374
+ // adaptation to fail (having invalid return type) so that we can give a
375
+ // better compilation failure in static_assert_validation. If we don't do
376
+ // this, then there will be cascading compilation failures that are confusing
377
+ // for users.
378
+ using key_compare =
379
+ absl::conditional_t<!compare_has_valid_result_type<Compare, Key>(),
380
+ Compare,
381
+ typename key_compare_adapter<Compare, Key>::type>;
382
+
383
+ static constexpr bool kIsKeyCompareStringAdapted =
384
+ std::is_same<key_compare, StringBtreeDefaultLess>::value ||
385
+ std::is_same<key_compare, StringBtreeDefaultGreater>::value;
386
+ static constexpr bool kIsKeyCompareTransparent =
387
+ IsTransparent<original_key_compare>::value || kIsKeyCompareStringAdapted;
388
+
389
+ // A type which indicates if we have a key-compare-to functor or a plain old
390
+ // key-compare functor.
391
+ using is_key_compare_to = btree_is_key_compare_to<key_compare, Key>;
392
+
393
+ using allocator_type = Alloc;
394
+ using key_type = Key;
395
+ using size_type = size_t;
396
+ using difference_type = ptrdiff_t;
397
+
398
+ using slot_policy = SlotPolicy;
399
+ using slot_type = typename slot_policy::slot_type;
400
+ using value_type = typename slot_policy::value_type;
401
+ using init_type = typename slot_policy::mutable_value_type;
402
+ using pointer = value_type *;
403
+ using const_pointer = const value_type *;
404
+ using reference = value_type &;
405
+ using const_reference = const value_type &;
406
+
407
+ using value_compare =
408
+ absl::conditional_t<IsMap,
409
+ map_value_compare<original_key_compare, value_type>,
410
+ original_key_compare>;
411
+ using is_map_container = std::integral_constant<bool, IsMap>;
412
+
413
+ // For the given lookup key type, returns whether we can have multiple
414
+ // equivalent keys in the btree. If this is a multi-container, then we can.
415
+ // Otherwise, we can have multiple equivalent keys only if all of the
416
+ // following conditions are met:
417
+ // - The comparator is transparent.
418
+ // - The lookup key type is not the same as key_type.
419
+ // - The comparator is not a StringBtreeDefault{Less,Greater} comparator
420
+ // that we know has the same equivalence classes for all lookup types.
421
+ template <typename LookupKey>
422
+ constexpr static bool can_have_multiple_equivalent_keys() {
423
+ return IsMulti || (IsTransparent<key_compare>::value &&
424
+ !std::is_same<LookupKey, Key>::value &&
425
+ !kIsKeyCompareStringAdapted);
426
+ }
427
+
428
+ enum {
429
+ kTargetNodeSize = TargetNodeSize,
430
+
431
+ // Upper bound for the available space for slots. This is largest for leaf
432
+ // nodes, which have overhead of at least a pointer + 4 bytes (for storing
433
+ // 3 field_types and an enum).
434
+ kNodeSlotSpace = TargetNodeSize - /*minimum overhead=*/(sizeof(void *) + 4),
435
+ };
436
+
437
+ // This is an integral type large enough to hold as many slots as will fit a
438
+ // node of TargetNodeSize bytes.
439
+ using node_count_type =
440
+ absl::conditional_t<(kNodeSlotSpace / sizeof(slot_type) >
441
+ (std::numeric_limits<uint8_t>::max)()),
442
+ uint16_t, uint8_t>; // NOLINT
443
+ };
444
+
445
+ // An adapter class that converts a lower-bound compare into an upper-bound
446
+ // compare. Note: there is no need to make a version of this adapter specialized
447
+ // for key-compare-to functors because the upper-bound (the first value greater
448
+ // than the input) is never an exact match.
449
+ template <typename Compare>
450
+ struct upper_bound_adapter {
451
+ explicit upper_bound_adapter(const Compare &c) : comp(c) {}
452
+ template <typename K1, typename K2>
453
+ bool operator()(const K1 &a, const K2 &b) const {
454
+ // Returns true when a is not greater than b.
455
+ return !compare_internal::compare_result_as_less_than(comp(b, a));
456
+ }
457
+
458
+ private:
459
+ Compare comp;
460
+ };
461
+
462
+ enum class MatchKind : uint8_t { kEq, kNe };
463
+
464
+ template <typename V, bool IsCompareTo>
465
+ struct SearchResult {
466
+ V value;
467
+ MatchKind match;
468
+
469
+ static constexpr bool HasMatch() { return true; }
470
+ bool IsEq() const { return match == MatchKind::kEq; }
471
+ };
472
+
473
+ // When we don't use CompareTo, `match` is not present.
474
+ // This ensures that callers can't use it accidentally when it provides no
475
+ // useful information.
476
+ template <typename V>
477
+ struct SearchResult<V, false> {
478
+ SearchResult() = default;
479
+ explicit SearchResult(V v) : value(v) {}
480
+ SearchResult(V v, MatchKind /*match*/) : value(v) {}
481
+
482
+ V value;
483
+
484
+ static constexpr bool HasMatch() { return false; }
485
+ static constexpr bool IsEq() { return false; }
486
+ };
487
+
488
+ // A node in the btree holding. The same node type is used for both internal
489
+ // and leaf nodes in the btree, though the nodes are allocated in such a way
490
+ // that the children array is only valid in internal nodes.
491
+ template <typename Params>
492
+ class btree_node {
493
+ using is_key_compare_to = typename Params::is_key_compare_to;
494
+ using field_type = typename Params::node_count_type;
495
+ using allocator_type = typename Params::allocator_type;
496
+ using slot_type = typename Params::slot_type;
497
+ using original_key_compare = typename Params::original_key_compare;
498
+
499
+ public:
500
+ using params_type = Params;
501
+ using key_type = typename Params::key_type;
502
+ using value_type = typename Params::value_type;
503
+ using pointer = typename Params::pointer;
504
+ using const_pointer = typename Params::const_pointer;
505
+ using reference = typename Params::reference;
506
+ using const_reference = typename Params::const_reference;
507
+ using key_compare = typename Params::key_compare;
508
+ using size_type = typename Params::size_type;
509
+ using difference_type = typename Params::difference_type;
510
+
511
+ // Btree decides whether to use linear node search as follows:
512
+ // - If the comparator expresses a preference, use that.
513
+ // - If the key expresses a preference, use that.
514
+ // - If the key is arithmetic and the comparator is std::less or
515
+ // std::greater, choose linear.
516
+ // - Otherwise, choose binary.
517
+ // TODO(ezb): Might make sense to add condition(s) based on node-size.
518
+ using use_linear_search = std::integral_constant<
519
+ bool, has_linear_node_search_preference<original_key_compare>::value
520
+ ? prefers_linear_node_search<original_key_compare>::value
521
+ : has_linear_node_search_preference<key_type>::value
522
+ ? prefers_linear_node_search<key_type>::value
523
+ : std::is_arithmetic<key_type>::value &&
524
+ (std::is_same<std::less<key_type>,
525
+ original_key_compare>::value ||
526
+ std::is_same<std::greater<key_type>,
527
+ original_key_compare>::value)>;
528
+
529
+ // This class is organized by absl::container_internal::Layout as if it had
530
+ // the following structure:
531
+ // // A pointer to the node's parent.
532
+ // btree_node *parent;
533
+ //
534
+ // // When ABSL_BTREE_ENABLE_GENERATIONS is defined, we also have a
535
+ // // generation integer in order to check that when iterators are
536
+ // // used, they haven't been invalidated already. Only the generation on
537
+ // // the root is used, but we have one on each node because whether a node
538
+ // // is root or not can change.
539
+ // uint32_t generation;
540
+ //
541
+ // // The position of the node in the node's parent.
542
+ // field_type position;
543
+ // // The index of the first populated value in `values`.
544
+ // // TODO(ezb): right now, `start` is always 0. Update insertion/merge
545
+ // // logic to allow for floating storage within nodes.
546
+ // field_type start;
547
+ // // The index after the last populated value in `values`. Currently, this
548
+ // // is the same as the count of values.
549
+ // field_type finish;
550
+ // // The maximum number of values the node can hold. This is an integer in
551
+ // // [1, kNodeSlots] for root leaf nodes, kNodeSlots for non-root leaf
552
+ // // nodes, and kInternalNodeMaxCount (as a sentinel value) for internal
553
+ // // nodes (even though there are still kNodeSlots values in the node).
554
+ // // TODO(ezb): make max_count use only 4 bits and record log2(capacity)
555
+ // // to free extra bits for is_root, etc.
556
+ // field_type max_count;
557
+ //
558
+ // // The array of values. The capacity is `max_count` for leaf nodes and
559
+ // // kNodeSlots for internal nodes. Only the values in
560
+ // // [start, finish) have been initialized and are valid.
561
+ // slot_type values[max_count];
562
+ //
563
+ // // The array of child pointers. The keys in children[i] are all less
564
+ // // than key(i). The keys in children[i + 1] are all greater than key(i).
565
+ // // There are 0 children for leaf nodes and kNodeSlots + 1 children for
566
+ // // internal nodes.
567
+ // btree_node *children[kNodeSlots + 1];
568
+ //
569
+ // This class is only constructed by EmptyNodeType. Normally, pointers to the
570
+ // layout above are allocated, cast to btree_node*, and de-allocated within
571
+ // the btree implementation.
572
+ ~btree_node() = default;
573
+ btree_node(btree_node const &) = delete;
574
+ btree_node &operator=(btree_node const &) = delete;
575
+
576
+ protected:
577
+ btree_node() = default;
578
+
579
+ private:
580
+ using layout_type =
581
+ absl::container_internal::Layout<btree_node *, uint32_t, field_type,
582
+ slot_type, btree_node *>;
583
+ using leaf_layout_type = typename layout_type::template WithStaticSizes<
584
+ /*parent*/ 1,
585
+ /*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
586
+ /*position, start, finish, max_count*/ 4>;
587
+ constexpr static size_type SizeWithNSlots(size_type n) {
588
+ return leaf_layout_type(/*slots*/ n, /*children*/ 0).AllocSize();
589
+ }
590
+ // A lower bound for the overhead of fields other than slots in a leaf node.
591
+ constexpr static size_type MinimumOverhead() {
592
+ return SizeWithNSlots(1) - sizeof(slot_type);
593
+ }
594
+
595
+ // Compute how many values we can fit onto a leaf node taking into account
596
+ // padding.
597
+ constexpr static size_type NodeTargetSlots(const size_type begin,
598
+ const size_type end) {
599
+ return begin == end ? begin
600
+ : SizeWithNSlots((begin + end) / 2 + 1) >
601
+ params_type::kTargetNodeSize
602
+ ? NodeTargetSlots(begin, (begin + end) / 2)
603
+ : NodeTargetSlots((begin + end) / 2 + 1, end);
604
+ }
605
+
606
+ constexpr static size_type kTargetNodeSize = params_type::kTargetNodeSize;
607
+ constexpr static size_type kNodeTargetSlots =
608
+ NodeTargetSlots(0, kTargetNodeSize);
609
+
610
+ // We need a minimum of 3 slots per internal node in order to perform
611
+ // splitting (1 value for the two nodes involved in the split and 1 value
612
+ // propagated to the parent as the delimiter for the split). For performance
613
+ // reasons, we don't allow 3 slots-per-node due to bad worst case occupancy of
614
+ // 1/3 (for a node, not a b-tree).
615
+ constexpr static size_type kMinNodeSlots = 4;
616
+
617
+ constexpr static size_type kNodeSlots =
618
+ kNodeTargetSlots >= kMinNodeSlots ? kNodeTargetSlots : kMinNodeSlots;
619
+
620
+ using internal_layout_type = typename layout_type::template WithStaticSizes<
621
+ /*parent*/ 1,
622
+ /*generation*/ BtreeGenerationsEnabled() ? 1 : 0,
623
+ /*position, start, finish, max_count*/ 4, /*slots*/ kNodeSlots,
624
+ /*children*/ kNodeSlots + 1>;
625
+
626
+ // The node is internal (i.e. is not a leaf node) if and only if `max_count`
627
+ // has this value.
628
+ constexpr static field_type kInternalNodeMaxCount = 0;
629
+
630
+ // Leaves can have less than kNodeSlots values.
631
+ constexpr static leaf_layout_type LeafLayout(
632
+ const size_type slot_count = kNodeSlots) {
633
+ return leaf_layout_type(slot_count, 0);
634
+ }
635
+ constexpr static auto InternalLayout() { return internal_layout_type(); }
636
+ constexpr static size_type LeafSize(const size_type slot_count = kNodeSlots) {
637
+ return LeafLayout(slot_count).AllocSize();
638
+ }
639
+ constexpr static size_type InternalSize() {
640
+ return InternalLayout().AllocSize();
641
+ }
642
+
643
+ constexpr static size_type Alignment() {
644
+ static_assert(LeafLayout(1).Alignment() == InternalLayout().Alignment(),
645
+ "Alignment of all nodes must be equal.");
646
+ return InternalLayout().Alignment();
647
+ }
648
+
649
+ // N is the index of the type in the Layout definition.
650
+ // ElementType<N> is the Nth type in the Layout definition.
651
+ template <size_type N>
652
+ inline typename layout_type::template ElementType<N> *GetField() {
653
+ // We assert that we don't read from values that aren't there.
654
+ assert(N < 4 || is_internal());
655
+ return InternalLayout().template Pointer<N>(reinterpret_cast<char *>(this));
656
+ }
657
+ template <size_type N>
658
+ inline const typename layout_type::template ElementType<N> *GetField() const {
659
+ assert(N < 4 || is_internal());
660
+ return InternalLayout().template Pointer<N>(
661
+ reinterpret_cast<const char *>(this));
662
+ }
663
+ void set_parent(btree_node *p) { *GetField<0>() = p; }
664
+ field_type &mutable_finish() { return GetField<2>()[2]; }
665
+ slot_type *slot(size_type i) { return &GetField<3>()[i]; }
666
+ slot_type *start_slot() { return slot(start()); }
667
+ slot_type *finish_slot() { return slot(finish()); }
668
+ const slot_type *slot(size_type i) const { return &GetField<3>()[i]; }
669
+ void set_position(field_type v) { GetField<2>()[0] = v; }
670
+ void set_start(field_type v) { GetField<2>()[1] = v; }
671
+ void set_finish(field_type v) { GetField<2>()[2] = v; }
672
+ // This method is only called by the node init methods.
673
+ void set_max_count(field_type v) { GetField<2>()[3] = v; }
674
+
675
+ public:
676
+ // Whether this is a leaf node or not. This value doesn't change after the
677
+ // node is created.
678
+ bool is_leaf() const { return GetField<2>()[3] != kInternalNodeMaxCount; }
679
+ // Whether this is an internal node or not. This value doesn't change after
680
+ // the node is created.
681
+ bool is_internal() const { return !is_leaf(); }
682
+
683
+ // Getter for the position of this node in its parent.
684
+ field_type position() const { return GetField<2>()[0]; }
685
+
686
+ // Getter for the offset of the first value in the `values` array.
687
+ field_type start() const {
688
+ // TODO(ezb): when floating storage is implemented, return GetField<2>()[1];
689
+ assert(GetField<2>()[1] == 0);
690
+ return 0;
691
+ }
692
+
693
+ // Getter for the offset after the last value in the `values` array.
694
+ field_type finish() const { return GetField<2>()[2]; }
695
+
696
+ // Getters for the number of values stored in this node.
697
+ field_type count() const {
698
+ assert(finish() >= start());
699
+ return finish() - start();
700
+ }
701
+ field_type max_count() const {
702
+ // Internal nodes have max_count==kInternalNodeMaxCount.
703
+ // Leaf nodes have max_count in [1, kNodeSlots].
704
+ const field_type max_count = GetField<2>()[3];
705
+ return max_count == field_type{kInternalNodeMaxCount}
706
+ ? field_type{kNodeSlots}
707
+ : max_count;
708
+ }
709
+
710
+ // Getter for the parent of this node.
711
+ btree_node *parent() const { return *GetField<0>(); }
712
+ // Getter for whether the node is the root of the tree. The parent of the
713
+ // root of the tree is the leftmost node in the tree which is guaranteed to
714
+ // be a leaf.
715
+ bool is_root() const { return parent()->is_leaf(); }
716
+ void make_root() {
717
+ assert(parent()->is_root());
718
+ set_generation(parent()->generation());
719
+ set_parent(parent()->parent());
720
+ }
721
+
722
+ // Gets the root node's generation integer, which is the one used by the tree.
723
+ uint32_t *get_root_generation() const {
724
+ assert(BtreeGenerationsEnabled());
725
+ const btree_node *curr = this;
726
+ for (; !curr->is_root(); curr = curr->parent()) continue;
727
+ return const_cast<uint32_t *>(&curr->GetField<1>()[0]);
728
+ }
729
+
730
+ // Returns the generation for iterator validation.
731
+ uint32_t generation() const {
732
+ return BtreeGenerationsEnabled() ? *get_root_generation() : 0;
733
+ }
734
+ // Updates generation. Should only be called on a root node or during node
735
+ // initialization.
736
+ void set_generation(uint32_t generation) {
737
+ if (BtreeGenerationsEnabled()) GetField<1>()[0] = generation;
738
+ }
739
+ // Updates the generation. We do this whenever the node is mutated.
740
+ void next_generation() {
741
+ if (BtreeGenerationsEnabled()) ++*get_root_generation();
742
+ }
743
+
744
+ // Getters for the key/value at position i in the node.
745
+ const key_type &key(size_type i) const { return params_type::key(slot(i)); }
746
+ reference value(size_type i) { return params_type::element(slot(i)); }
747
+ const_reference value(size_type i) const {
748
+ return params_type::element(slot(i));
749
+ }
750
+
751
+ // Getters/setter for the child at position i in the node.
752
+ btree_node *child(field_type i) const { return GetField<4>()[i]; }
753
+ btree_node *start_child() const { return child(start()); }
754
+ btree_node *&mutable_child(field_type i) { return GetField<4>()[i]; }
755
+ void clear_child(field_type i) {
756
+ absl::container_internal::SanitizerPoisonObject(&mutable_child(i));
757
+ }
758
+ void set_child_noupdate_position(field_type i, btree_node *c) {
759
+ absl::container_internal::SanitizerUnpoisonObject(&mutable_child(i));
760
+ mutable_child(i) = c;
761
+ }
762
+ void set_child(field_type i, btree_node *c) {
763
+ set_child_noupdate_position(i, c);
764
+ c->set_position(i);
765
+ }
766
+ void init_child(field_type i, btree_node *c) {
767
+ set_child(i, c);
768
+ c->set_parent(this);
769
+ }
770
+
771
+ // Returns the position of the first value whose key is not less than k.
772
+ template <typename K>
773
+ SearchResult<size_type, is_key_compare_to::value> lower_bound(
774
+ const K &k, const key_compare &comp) const {
775
+ return use_linear_search::value ? linear_search(k, comp)
776
+ : binary_search(k, comp);
777
+ }
778
+ // Returns the position of the first value whose key is greater than k.
779
+ template <typename K>
780
+ size_type upper_bound(const K &k, const key_compare &comp) const {
781
+ auto upper_compare = upper_bound_adapter<key_compare>(comp);
782
+ return use_linear_search::value ? linear_search(k, upper_compare).value
783
+ : binary_search(k, upper_compare).value;
784
+ }
785
+
786
+ template <typename K, typename Compare>
787
+ SearchResult<size_type, btree_is_key_compare_to<Compare, key_type>::value>
788
+ linear_search(const K &k, const Compare &comp) const {
789
+ return linear_search_impl(k, start(), finish(), comp,
790
+ btree_is_key_compare_to<Compare, key_type>());
791
+ }
792
+
793
+ template <typename K, typename Compare>
794
+ SearchResult<size_type, btree_is_key_compare_to<Compare, key_type>::value>
795
+ binary_search(const K &k, const Compare &comp) const {
796
+ return binary_search_impl(k, start(), finish(), comp,
797
+ btree_is_key_compare_to<Compare, key_type>());
798
+ }
799
+
800
+ // Returns the position of the first value whose key is not less than k using
801
+ // linear search performed using plain compare.
802
+ template <typename K, typename Compare>
803
+ SearchResult<size_type, false> linear_search_impl(
804
+ const K &k, size_type s, const size_type e, const Compare &comp,
805
+ std::false_type /* IsCompareTo */) const {
806
+ while (s < e) {
807
+ if (!comp(key(s), k)) {
808
+ break;
809
+ }
810
+ ++s;
811
+ }
812
+ return SearchResult<size_type, false>{s};
813
+ }
814
+
815
+ // Returns the position of the first value whose key is not less than k using
816
+ // linear search performed using compare-to.
817
+ template <typename K, typename Compare>
818
+ SearchResult<size_type, true> linear_search_impl(
819
+ const K &k, size_type s, const size_type e, const Compare &comp,
820
+ std::true_type /* IsCompareTo */) const {
821
+ while (s < e) {
822
+ const absl::weak_ordering c = comp(key(s), k);
823
+ if (c == 0) {
824
+ return {s, MatchKind::kEq};
825
+ } else if (c > 0) {
826
+ break;
827
+ }
828
+ ++s;
829
+ }
830
+ return {s, MatchKind::kNe};
831
+ }
832
+
833
+ // Returns the position of the first value whose key is not less than k using
834
+ // binary search performed using plain compare.
835
+ template <typename K, typename Compare>
836
+ SearchResult<size_type, false> binary_search_impl(
837
+ const K &k, size_type s, size_type e, const Compare &comp,
838
+ std::false_type /* IsCompareTo */) const {
839
+ while (s != e) {
840
+ const size_type mid = (s + e) >> 1;
841
+ if (comp(key(mid), k)) {
842
+ s = mid + 1;
843
+ } else {
844
+ e = mid;
845
+ }
846
+ }
847
+ return SearchResult<size_type, false>{s};
848
+ }
849
+
850
+ // Returns the position of the first value whose key is not less than k using
851
+ // binary search performed using compare-to.
852
+ template <typename K, typename CompareTo>
853
+ SearchResult<size_type, true> binary_search_impl(
854
+ const K &k, size_type s, size_type e, const CompareTo &comp,
855
+ std::true_type /* IsCompareTo */) const {
856
+ if (params_type::template can_have_multiple_equivalent_keys<K>()) {
857
+ MatchKind exact_match = MatchKind::kNe;
858
+ while (s != e) {
859
+ const size_type mid = (s + e) >> 1;
860
+ const absl::weak_ordering c = comp(key(mid), k);
861
+ if (c < 0) {
862
+ s = mid + 1;
863
+ } else {
864
+ e = mid;
865
+ if (c == 0) {
866
+ // Need to return the first value whose key is not less than k,
867
+ // which requires continuing the binary search if there could be
868
+ // multiple equivalent keys.
869
+ exact_match = MatchKind::kEq;
870
+ }
871
+ }
872
+ }
873
+ return {s, exact_match};
874
+ } else { // Can't have multiple equivalent keys.
875
+ while (s != e) {
876
+ const size_type mid = (s + e) >> 1;
877
+ const absl::weak_ordering c = comp(key(mid), k);
878
+ if (c < 0) {
879
+ s = mid + 1;
880
+ } else if (c > 0) {
881
+ e = mid;
882
+ } else {
883
+ return {mid, MatchKind::kEq};
884
+ }
885
+ }
886
+ return {s, MatchKind::kNe};
887
+ }
888
+ }
889
+
890
+ // Returns whether key i is ordered correctly with respect to the other keys
891
+ // in the node. The motivation here is to detect comparators that violate
892
+ // transitivity. Note: we only do comparisons of keys on this node rather than
893
+ // the whole tree so that this is constant time.
894
+ template <typename Compare>
895
+ bool is_ordered_correctly(field_type i, const Compare &comp) const {
896
+ if (std::is_base_of<BtreeTestOnlyCheckedCompareOptOutBase,
897
+ Compare>::value ||
898
+ params_type::kIsKeyCompareStringAdapted) {
899
+ return true;
900
+ }
901
+
902
+ const auto compare = [&](field_type a, field_type b) {
903
+ const absl::weak_ordering cmp =
904
+ compare_internal::do_three_way_comparison(comp, key(a), key(b));
905
+ return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
906
+ };
907
+ int cmp = -1;
908
+ constexpr bool kCanHaveEquivKeys =
909
+ params_type::template can_have_multiple_equivalent_keys<key_type>();
910
+ for (field_type j = start(); j < finish(); ++j) {
911
+ if (j == i) {
912
+ if (cmp > 0) return false;
913
+ continue;
914
+ }
915
+ int new_cmp = compare(j, i);
916
+ if (new_cmp < cmp || (!kCanHaveEquivKeys && new_cmp == 0)) return false;
917
+ cmp = new_cmp;
918
+ }
919
+ return true;
920
+ }
921
+
922
+ // Emplaces a value at position i, shifting all existing values and
923
+ // children at positions >= i to the right by 1.
924
+ template <typename... Args>
925
+ void emplace_value(field_type i, allocator_type *alloc, Args &&...args);
926
+
927
+ // Removes the values at positions [i, i + to_erase), shifting all existing
928
+ // values and children after that range to the left by to_erase. Clears all
929
+ // children between [i, i + to_erase).
930
+ void remove_values(field_type i, field_type to_erase, allocator_type *alloc);
931
+
932
+ // Rebalances a node with its right sibling.
933
+ void rebalance_right_to_left(field_type to_move, btree_node *right,
934
+ allocator_type *alloc);
935
+ void rebalance_left_to_right(field_type to_move, btree_node *right,
936
+ allocator_type *alloc);
937
+
938
+ // Splits a node, moving a portion of the node's values to its right sibling.
939
+ void split(int insert_position, btree_node *dest, allocator_type *alloc);
940
+
941
+ // Merges a node with its right sibling, moving all of the values and the
942
+ // delimiting key in the parent node onto itself, and deleting the src node.
943
+ void merge(btree_node *src, allocator_type *alloc);
944
+
945
+ // Node allocation/deletion routines.
946
+ void init_leaf(field_type position, field_type max_count,
947
+ btree_node *parent) {
948
+ set_generation(0);
949
+ set_parent(parent);
950
+ set_position(position);
951
+ set_start(0);
952
+ set_finish(0);
953
+ set_max_count(max_count);
954
+ absl::container_internal::SanitizerPoisonMemoryRegion(
955
+ start_slot(), max_count * sizeof(slot_type));
956
+ }
957
+ void init_internal(field_type position, btree_node *parent) {
958
+ init_leaf(position, kNodeSlots, parent);
959
+ // Set `max_count` to a sentinel value to indicate that this node is
960
+ // internal.
961
+ set_max_count(kInternalNodeMaxCount);
962
+ absl::container_internal::SanitizerPoisonMemoryRegion(
963
+ &mutable_child(start()), (kNodeSlots + 1) * sizeof(btree_node *));
964
+ }
965
+
966
+ static void deallocate(const size_type size, btree_node *node,
967
+ allocator_type *alloc) {
968
+ absl::container_internal::SanitizerUnpoisonMemoryRegion(node, size);
969
+ absl::container_internal::Deallocate<Alignment()>(alloc, node, size);
970
+ }
971
+
972
+ // Deletes a node and all of its children.
973
+ static void clear_and_delete(btree_node *node, allocator_type *alloc);
974
+
975
+ private:
976
+ template <typename... Args>
977
+ void value_init(const field_type i, allocator_type *alloc, Args &&...args) {
978
+ next_generation();
979
+ absl::container_internal::SanitizerUnpoisonObject(slot(i));
980
+ params_type::construct(alloc, slot(i), std::forward<Args>(args)...);
981
+ }
982
+ void value_destroy(const field_type i, allocator_type *alloc) {
983
+ next_generation();
984
+ params_type::destroy(alloc, slot(i));
985
+ absl::container_internal::SanitizerPoisonObject(slot(i));
986
+ }
987
+ void value_destroy_n(const field_type i, const field_type n,
988
+ allocator_type *alloc) {
989
+ next_generation();
990
+ for (slot_type *s = slot(i), *end = slot(i + n); s != end; ++s) {
991
+ params_type::destroy(alloc, s);
992
+ absl::container_internal::SanitizerPoisonObject(s);
993
+ }
994
+ }
995
+
996
+ static void transfer(slot_type *dest, slot_type *src, allocator_type *alloc) {
997
+ absl::container_internal::SanitizerUnpoisonObject(dest);
998
+ params_type::transfer(alloc, dest, src);
999
+ absl::container_internal::SanitizerPoisonObject(src);
1000
+ }
1001
+
1002
+ // Transfers value from slot `src_i` in `src_node` to slot `dest_i` in `this`.
1003
+ void transfer(const size_type dest_i, const size_type src_i,
1004
+ btree_node *src_node, allocator_type *alloc) {
1005
+ next_generation();
1006
+ transfer(slot(dest_i), src_node->slot(src_i), alloc);
1007
+ }
1008
+
1009
+ // Transfers `n` values starting at value `src_i` in `src_node` into the
1010
+ // values starting at value `dest_i` in `this`.
1011
+ void transfer_n(const size_type n, const size_type dest_i,
1012
+ const size_type src_i, btree_node *src_node,
1013
+ allocator_type *alloc) {
1014
+ next_generation();
1015
+ for (slot_type *src = src_node->slot(src_i), *end = src + n,
1016
+ *dest = slot(dest_i);
1017
+ src != end; ++src, ++dest) {
1018
+ transfer(dest, src, alloc);
1019
+ }
1020
+ }
1021
+
1022
+ // Same as above, except that we start at the end and work our way to the
1023
+ // beginning.
1024
+ void transfer_n_backward(const size_type n, const size_type dest_i,
1025
+ const size_type src_i, btree_node *src_node,
1026
+ allocator_type *alloc) {
1027
+ next_generation();
1028
+ for (slot_type *src = src_node->slot(src_i + n), *end = src - n,
1029
+ *dest = slot(dest_i + n);
1030
+ src != end; --src, --dest) {
1031
+ // If we modified the loop index calculations above to avoid the -1s here,
1032
+ // it would result in UB in the computation of `end` (and possibly `src`
1033
+ // as well, if n == 0), since slot() is effectively an array index and it
1034
+ // is UB to compute the address of any out-of-bounds array element except
1035
+ // for one-past-the-end.
1036
+ transfer(dest - 1, src - 1, alloc);
1037
+ }
1038
+ }
1039
+
1040
+ template <typename P>
1041
+ friend class btree;
1042
+ template <typename N, typename R, typename P>
1043
+ friend class btree_iterator;
1044
+ friend class BtreeNodePeer;
1045
+ friend struct btree_access;
1046
+ };
1047
+
1048
+ template <typename Node>
1049
+ bool AreNodesFromSameContainer(const Node *node_a, const Node *node_b) {
1050
+ // If either node is null, then give up on checking whether they're from the
1051
+ // same container. (If exactly one is null, then we'll trigger the
1052
+ // default-constructed assert in Equals.)
1053
+ if (node_a == nullptr || node_b == nullptr) return true;
1054
+ while (!node_a->is_root()) node_a = node_a->parent();
1055
+ while (!node_b->is_root()) node_b = node_b->parent();
1056
+ return node_a == node_b;
1057
+ }
1058
+
1059
+ class btree_iterator_generation_info_enabled {
1060
+ public:
1061
+ explicit btree_iterator_generation_info_enabled(uint32_t g)
1062
+ : generation_(g) {}
1063
+
1064
+ // Updates the generation. For use internally right before we return an
1065
+ // iterator to the user.
1066
+ template <typename Node>
1067
+ void update_generation(const Node *node) {
1068
+ if (node != nullptr) generation_ = node->generation();
1069
+ }
1070
+ uint32_t generation() const { return generation_; }
1071
+
1072
+ template <typename Node>
1073
+ void assert_valid_generation(const Node *node) const {
1074
+ if (node != nullptr && node->generation() != generation_) {
1075
+ ABSL_INTERNAL_LOG(
1076
+ FATAL,
1077
+ "Attempting to use an invalidated iterator. The corresponding b-tree "
1078
+ "container has been mutated since this iterator was constructed.");
1079
+ }
1080
+ }
1081
+
1082
+ private:
1083
+ // Used to check that the iterator hasn't been invalidated.
1084
+ uint32_t generation_;
1085
+ };
1086
+
1087
+ class btree_iterator_generation_info_disabled {
1088
+ public:
1089
+ explicit btree_iterator_generation_info_disabled(uint32_t) {}
1090
+ static void update_generation(const void *) {}
1091
+ static uint32_t generation() { return 0; }
1092
+ static void assert_valid_generation(const void *) {}
1093
+ };
1094
+
1095
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
1096
+ using btree_iterator_generation_info = btree_iterator_generation_info_enabled;
1097
+ #else
1098
+ using btree_iterator_generation_info = btree_iterator_generation_info_disabled;
1099
+ #endif
1100
+
1101
+ template <typename Node, typename Reference, typename Pointer>
1102
+ class btree_iterator : private btree_iterator_generation_info {
1103
+ using field_type = typename Node::field_type;
1104
+ using key_type = typename Node::key_type;
1105
+ using size_type = typename Node::size_type;
1106
+ using params_type = typename Node::params_type;
1107
+ using is_map_container = typename params_type::is_map_container;
1108
+
1109
+ using node_type = Node;
1110
+ using normal_node = typename std::remove_const<Node>::type;
1111
+ using const_node = const Node;
1112
+ using normal_pointer = typename params_type::pointer;
1113
+ using normal_reference = typename params_type::reference;
1114
+ using const_pointer = typename params_type::const_pointer;
1115
+ using const_reference = typename params_type::const_reference;
1116
+ using slot_type = typename params_type::slot_type;
1117
+
1118
+ // In sets, all iterators are const.
1119
+ using iterator = absl::conditional_t<
1120
+ is_map_container::value,
1121
+ btree_iterator<normal_node, normal_reference, normal_pointer>,
1122
+ btree_iterator<normal_node, const_reference, const_pointer>>;
1123
+ using const_iterator =
1124
+ btree_iterator<const_node, const_reference, const_pointer>;
1125
+
1126
+ public:
1127
+ // These aliases are public for std::iterator_traits.
1128
+ using difference_type = typename Node::difference_type;
1129
+ using value_type = typename params_type::value_type;
1130
+ using pointer = Pointer;
1131
+ using reference = Reference;
1132
+ using iterator_category = std::bidirectional_iterator_tag;
1133
+
1134
+ btree_iterator() : btree_iterator(nullptr, -1) {}
1135
+ explicit btree_iterator(Node *n) : btree_iterator(n, n->start()) {}
1136
+ btree_iterator(Node *n, int p)
1137
+ : btree_iterator_generation_info(n != nullptr ? n->generation()
1138
+ : ~uint32_t{}),
1139
+ node_(n),
1140
+ position_(p) {}
1141
+
1142
+ // NOTE: this SFINAE allows for implicit conversions from iterator to
1143
+ // const_iterator, but it specifically avoids hiding the copy constructor so
1144
+ // that the trivial one will be used when possible.
1145
+ template <typename N, typename R, typename P,
1146
+ absl::enable_if_t<
1147
+ std::is_same<btree_iterator<N, R, P>, iterator>::value &&
1148
+ std::is_same<btree_iterator, const_iterator>::value,
1149
+ int> = 0>
1150
+ btree_iterator(const btree_iterator<N, R, P> other) // NOLINT
1151
+ : btree_iterator_generation_info(other),
1152
+ node_(other.node_),
1153
+ position_(other.position_) {}
1154
+
1155
+ bool operator==(const iterator &other) const {
1156
+ return Equals(other);
1157
+ }
1158
+ bool operator==(const const_iterator &other) const {
1159
+ return Equals(other);
1160
+ }
1161
+ bool operator!=(const iterator &other) const {
1162
+ return !Equals(other);
1163
+ }
1164
+ bool operator!=(const const_iterator &other) const {
1165
+ return !Equals(other);
1166
+ }
1167
+
1168
+ // Returns n such that n calls to ++other yields *this.
1169
+ // Precondition: n exists.
1170
+ difference_type operator-(const_iterator other) const {
1171
+ if (node_ == other.node_) {
1172
+ if (node_->is_leaf()) return position_ - other.position_;
1173
+ if (position_ == other.position_) return 0;
1174
+ }
1175
+ return distance_slow(other);
1176
+ }
1177
+
1178
+ // Accessors for the key/value the iterator is pointing at.
1179
+ reference operator*() const {
1180
+ ABSL_HARDENING_ASSERT(node_ != nullptr);
1181
+ assert_valid_generation(node_);
1182
+ ABSL_HARDENING_ASSERT(position_ >= node_->start());
1183
+ if (position_ >= node_->finish()) {
1184
+ ABSL_HARDENING_ASSERT(!IsEndIterator() && "Dereferencing end() iterator");
1185
+ ABSL_HARDENING_ASSERT(position_ < node_->finish());
1186
+ }
1187
+ return node_->value(static_cast<field_type>(position_));
1188
+ }
1189
+ pointer operator->() const { return &operator*(); }
1190
+
1191
+ btree_iterator &operator++() {
1192
+ increment();
1193
+ return *this;
1194
+ }
1195
+ btree_iterator &operator--() {
1196
+ decrement();
1197
+ return *this;
1198
+ }
1199
+ btree_iterator operator++(int) {
1200
+ btree_iterator tmp = *this;
1201
+ ++*this;
1202
+ return tmp;
1203
+ }
1204
+ btree_iterator operator--(int) {
1205
+ btree_iterator tmp = *this;
1206
+ --*this;
1207
+ return tmp;
1208
+ }
1209
+
1210
+ private:
1211
+ friend iterator;
1212
+ friend const_iterator;
1213
+ template <typename Params>
1214
+ friend class btree;
1215
+ template <typename Tree>
1216
+ friend class btree_container;
1217
+ template <typename Tree>
1218
+ friend class btree_set_container;
1219
+ template <typename Tree>
1220
+ friend class btree_map_container;
1221
+ template <typename Tree>
1222
+ friend class btree_multiset_container;
1223
+ template <typename TreeType, typename CheckerType>
1224
+ friend class base_checker;
1225
+ friend struct btree_access;
1226
+
1227
+ // This SFINAE allows explicit conversions from const_iterator to
1228
+ // iterator, but also avoids hiding the copy constructor.
1229
+ // NOTE: the const_cast is safe because this constructor is only called by
1230
+ // non-const methods and the container owns the nodes.
1231
+ template <typename N, typename R, typename P,
1232
+ absl::enable_if_t<
1233
+ std::is_same<btree_iterator<N, R, P>, const_iterator>::value &&
1234
+ std::is_same<btree_iterator, iterator>::value,
1235
+ int> = 0>
1236
+ explicit btree_iterator(const btree_iterator<N, R, P> other)
1237
+ : btree_iterator_generation_info(other.generation()),
1238
+ node_(const_cast<node_type *>(other.node_)),
1239
+ position_(other.position_) {}
1240
+
1241
+ bool Equals(const const_iterator other) const {
1242
+ ABSL_HARDENING_ASSERT(((node_ == nullptr && other.node_ == nullptr) ||
1243
+ (node_ != nullptr && other.node_ != nullptr)) &&
1244
+ "Comparing default-constructed iterator with "
1245
+ "non-default-constructed iterator.");
1246
+ // Note: we use assert instead of ABSL_HARDENING_ASSERT here because this
1247
+ // changes the complexity of Equals from O(1) to O(log(N) + log(M)) where
1248
+ // N/M are sizes of the containers containing node_/other.node_.
1249
+ assert(AreNodesFromSameContainer(node_, other.node_) &&
1250
+ "Comparing iterators from different containers.");
1251
+ assert_valid_generation(node_);
1252
+ other.assert_valid_generation(other.node_);
1253
+ return node_ == other.node_ && position_ == other.position_;
1254
+ }
1255
+
1256
+ bool IsEndIterator() const {
1257
+ if (position_ != node_->finish()) return false;
1258
+ node_type *node = node_;
1259
+ while (!node->is_root()) {
1260
+ if (node->position() != node->parent()->finish()) return false;
1261
+ node = node->parent();
1262
+ }
1263
+ return true;
1264
+ }
1265
+
1266
+ // Returns n such that n calls to ++other yields *this.
1267
+ // Precondition: n exists && (this->node_ != other.node_ ||
1268
+ // !this->node_->is_leaf() || this->position_ != other.position_).
1269
+ difference_type distance_slow(const_iterator other) const;
1270
+
1271
+ // Increment/decrement the iterator.
1272
+ void increment() {
1273
+ assert_valid_generation(node_);
1274
+ if (node_->is_leaf() && ++position_ < node_->finish()) {
1275
+ return;
1276
+ }
1277
+ increment_slow();
1278
+ }
1279
+ void increment_slow();
1280
+
1281
+ void decrement() {
1282
+ assert_valid_generation(node_);
1283
+ if (node_->is_leaf() && --position_ >= node_->start()) {
1284
+ return;
1285
+ }
1286
+ decrement_slow();
1287
+ }
1288
+ void decrement_slow();
1289
+
1290
+ const key_type &key() const {
1291
+ return node_->key(static_cast<size_type>(position_));
1292
+ }
1293
+ decltype(std::declval<Node *>()->slot(0)) slot() {
1294
+ return node_->slot(static_cast<size_type>(position_));
1295
+ }
1296
+
1297
+ void update_generation() {
1298
+ btree_iterator_generation_info::update_generation(node_);
1299
+ }
1300
+
1301
+ // The node in the tree the iterator is pointing at.
1302
+ Node *node_;
1303
+ // The position within the node of the tree the iterator is pointing at.
1304
+ // NOTE: this is an int rather than a field_type because iterators can point
1305
+ // to invalid positions (such as -1) in certain circumstances.
1306
+ int position_;
1307
+ };
1308
+
1309
+ template <typename Params>
1310
+ class btree {
1311
+ using node_type = btree_node<Params>;
1312
+ using is_key_compare_to = typename Params::is_key_compare_to;
1313
+ using field_type = typename node_type::field_type;
1314
+
1315
+ // We use a static empty node for the root/leftmost/rightmost of empty btrees
1316
+ // in order to avoid branching in begin()/end().
1317
+ struct EmptyNodeType : node_type {
1318
+ using field_type = typename node_type::field_type;
1319
+ node_type *parent;
1320
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
1321
+ uint32_t generation = 0;
1322
+ #endif
1323
+ field_type position = 0;
1324
+ field_type start = 0;
1325
+ field_type finish = 0;
1326
+ // max_count must be != kInternalNodeMaxCount (so that this node is regarded
1327
+ // as a leaf node). max_count() is never called when the tree is empty.
1328
+ field_type max_count = node_type::kInternalNodeMaxCount + 1;
1329
+
1330
+ constexpr EmptyNodeType() : parent(this) {}
1331
+ };
1332
+
1333
+ static node_type *EmptyNode() {
1334
+ alignas(node_type::Alignment()) static constexpr EmptyNodeType empty_node;
1335
+ return const_cast<EmptyNodeType *>(&empty_node);
1336
+ }
1337
+
1338
+ enum : uint32_t {
1339
+ kNodeSlots = node_type::kNodeSlots,
1340
+ kMinNodeValues = kNodeSlots / 2,
1341
+ };
1342
+
1343
+ struct node_stats {
1344
+ using size_type = typename Params::size_type;
1345
+
1346
+ node_stats(size_type l, size_type i) : leaf_nodes(l), internal_nodes(i) {}
1347
+
1348
+ node_stats &operator+=(const node_stats &other) {
1349
+ leaf_nodes += other.leaf_nodes;
1350
+ internal_nodes += other.internal_nodes;
1351
+ return *this;
1352
+ }
1353
+
1354
+ size_type leaf_nodes;
1355
+ size_type internal_nodes;
1356
+ };
1357
+
1358
+ public:
1359
+ using key_type = typename Params::key_type;
1360
+ using value_type = typename Params::value_type;
1361
+ using size_type = typename Params::size_type;
1362
+ using difference_type = typename Params::difference_type;
1363
+ using key_compare = typename Params::key_compare;
1364
+ using original_key_compare = typename Params::original_key_compare;
1365
+ using value_compare = typename Params::value_compare;
1366
+ using allocator_type = typename Params::allocator_type;
1367
+ using reference = typename Params::reference;
1368
+ using const_reference = typename Params::const_reference;
1369
+ using pointer = typename Params::pointer;
1370
+ using const_pointer = typename Params::const_pointer;
1371
+ using iterator =
1372
+ typename btree_iterator<node_type, reference, pointer>::iterator;
1373
+ using const_iterator = typename iterator::const_iterator;
1374
+ using reverse_iterator = std::reverse_iterator<iterator>;
1375
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1376
+ using node_handle_type = node_handle<Params, Params, allocator_type>;
1377
+
1378
+ // Internal types made public for use by btree_container types.
1379
+ using params_type = Params;
1380
+ using slot_type = typename Params::slot_type;
1381
+
1382
+ private:
1383
+ // Copies or moves (depending on the template parameter) the values in
1384
+ // other into this btree in their order in other. This btree must be empty
1385
+ // before this method is called. This method is used in copy construction,
1386
+ // copy assignment, and move assignment.
1387
+ template <typename Btree>
1388
+ void copy_or_move_values_in_order(Btree &other);
1389
+
1390
+ // Validates that various assumptions/requirements are true at compile time.
1391
+ constexpr static bool static_assert_validation();
1392
+
1393
+ public:
1394
+ btree(const key_compare &comp, const allocator_type &alloc)
1395
+ : root_(EmptyNode()), rightmost_(comp, alloc, EmptyNode()), size_(0) {}
1396
+
1397
+ btree(const btree &other) : btree(other, other.allocator()) {}
1398
+ btree(const btree &other, const allocator_type &alloc)
1399
+ : btree(other.key_comp(), alloc) {
1400
+ copy_or_move_values_in_order(other);
1401
+ }
1402
+ btree(btree &&other) noexcept
1403
+ : root_(std::exchange(other.root_, EmptyNode())),
1404
+ rightmost_(std::move(other.rightmost_)),
1405
+ size_(std::exchange(other.size_, 0u)) {
1406
+ other.mutable_rightmost() = EmptyNode();
1407
+ }
1408
+ btree(btree &&other, const allocator_type &alloc)
1409
+ : btree(other.key_comp(), alloc) {
1410
+ if (alloc == other.allocator()) {
1411
+ swap(other);
1412
+ } else {
1413
+ // Move values from `other` one at a time when allocators are different.
1414
+ copy_or_move_values_in_order(other);
1415
+ }
1416
+ }
1417
+
1418
+ ~btree() {
1419
+ // Put static_asserts in destructor to avoid triggering them before the type
1420
+ // is complete.
1421
+ static_assert(static_assert_validation(), "This call must be elided.");
1422
+ clear();
1423
+ }
1424
+
1425
+ // Assign the contents of other to *this.
1426
+ btree &operator=(const btree &other);
1427
+ btree &operator=(btree &&other) noexcept;
1428
+
1429
+ iterator begin() { return iterator(leftmost()); }
1430
+ const_iterator begin() const { return const_iterator(leftmost()); }
1431
+ iterator end() { return iterator(rightmost(), rightmost()->finish()); }
1432
+ const_iterator end() const {
1433
+ return const_iterator(rightmost(), rightmost()->finish());
1434
+ }
1435
+ reverse_iterator rbegin() { return reverse_iterator(end()); }
1436
+ const_reverse_iterator rbegin() const {
1437
+ return const_reverse_iterator(end());
1438
+ }
1439
+ reverse_iterator rend() { return reverse_iterator(begin()); }
1440
+ const_reverse_iterator rend() const {
1441
+ return const_reverse_iterator(begin());
1442
+ }
1443
+
1444
+ // Finds the first element whose key is not less than `key`.
1445
+ template <typename K>
1446
+ iterator lower_bound(const K &key) {
1447
+ return internal_end(internal_lower_bound(key).value);
1448
+ }
1449
+ template <typename K>
1450
+ const_iterator lower_bound(const K &key) const {
1451
+ return internal_end(internal_lower_bound(key).value);
1452
+ }
1453
+
1454
+ // Finds the first element whose key is not less than `key` and also returns
1455
+ // whether that element is equal to `key`.
1456
+ template <typename K>
1457
+ std::pair<iterator, bool> lower_bound_equal(const K &key) const;
1458
+
1459
+ // Finds the first element whose key is greater than `key`.
1460
+ template <typename K>
1461
+ iterator upper_bound(const K &key) {
1462
+ return internal_end(internal_upper_bound(key));
1463
+ }
1464
+ template <typename K>
1465
+ const_iterator upper_bound(const K &key) const {
1466
+ return internal_end(internal_upper_bound(key));
1467
+ }
1468
+
1469
+ // Finds the range of values which compare equal to key. The first member of
1470
+ // the returned pair is equal to lower_bound(key). The second member of the
1471
+ // pair is equal to upper_bound(key).
1472
+ template <typename K>
1473
+ std::pair<iterator, iterator> equal_range(const K &key);
1474
+ template <typename K>
1475
+ std::pair<const_iterator, const_iterator> equal_range(const K &key) const {
1476
+ return const_cast<btree *>(this)->equal_range(key);
1477
+ }
1478
+
1479
+ // Inserts a value into the btree only if it does not already exist. The
1480
+ // boolean return value indicates whether insertion succeeded or failed.
1481
+ // Requirement: if `key` already exists in the btree, does not consume `args`.
1482
+ // Requirement: `key` is never referenced after consuming `args`.
1483
+ template <typename K, typename... Args>
1484
+ std::pair<iterator, bool> insert_unique(const K &key, Args &&...args);
1485
+
1486
+ // Inserts with hint. Checks to see if the value should be placed immediately
1487
+ // before `position` in the tree. If so, then the insertion will take
1488
+ // amortized constant time. If not, the insertion will take amortized
1489
+ // logarithmic time as if a call to insert_unique() were made.
1490
+ // Requirement: if `key` already exists in the btree, does not consume `args`.
1491
+ // Requirement: `key` is never referenced after consuming `args`.
1492
+ template <typename K, typename... Args>
1493
+ std::pair<iterator, bool> insert_hint_unique(iterator position, const K &key,
1494
+ Args &&...args);
1495
+
1496
+ // Insert a range of values into the btree.
1497
+ // Note: the first overload avoids constructing a value_type if the key
1498
+ // already exists in the btree.
1499
+ template <typename InputIterator,
1500
+ typename = decltype(std::declval<const key_compare &>()(
1501
+ params_type::key(*std::declval<InputIterator>()),
1502
+ std::declval<const key_type &>()))>
1503
+ void insert_iterator_unique(InputIterator b, InputIterator e, int);
1504
+ // We need the second overload for cases in which we need to construct a
1505
+ // value_type in order to compare it with the keys already in the btree.
1506
+ template <typename InputIterator>
1507
+ void insert_iterator_unique(InputIterator b, InputIterator e, char);
1508
+
1509
+ // Inserts a value into the btree.
1510
+ template <typename ValueType>
1511
+ iterator insert_multi(const key_type &key, ValueType &&v);
1512
+
1513
+ // Inserts a value into the btree.
1514
+ template <typename ValueType>
1515
+ iterator insert_multi(ValueType &&v) {
1516
+ return insert_multi(params_type::key(v), std::forward<ValueType>(v));
1517
+ }
1518
+
1519
+ // Insert with hint. Check to see if the value should be placed immediately
1520
+ // before position in the tree. If it does, then the insertion will take
1521
+ // amortized constant time. If not, the insertion will take amortized
1522
+ // logarithmic time as if a call to insert_multi(v) were made.
1523
+ template <typename ValueType>
1524
+ iterator insert_hint_multi(iterator position, ValueType &&v);
1525
+
1526
+ // Insert a range of values into the btree.
1527
+ template <typename InputIterator>
1528
+ void insert_iterator_multi(InputIterator b,
1529
+ InputIterator e);
1530
+
1531
+ // Erase the specified iterator from the btree. The iterator must be valid
1532
+ // (i.e. not equal to end()). Return an iterator pointing to the node after
1533
+ // the one that was erased (or end() if none exists).
1534
+ // Requirement: does not read the value at `*iter`.
1535
+ iterator erase(iterator iter);
1536
+
1537
+ // Erases range. Returns the number of keys erased and an iterator pointing
1538
+ // to the element after the last erased element.
1539
+ std::pair<size_type, iterator> erase_range(iterator begin, iterator end);
1540
+
1541
+ // Finds an element with key equivalent to `key` or returns `end()` if `key`
1542
+ // is not present.
1543
+ template <typename K>
1544
+ iterator find(const K &key) {
1545
+ return internal_end(internal_find(key));
1546
+ }
1547
+ template <typename K>
1548
+ const_iterator find(const K &key) const {
1549
+ return internal_end(internal_find(key));
1550
+ }
1551
+
1552
+ // Clear the btree, deleting all of the values it contains.
1553
+ void clear();
1554
+
1555
+ // Swaps the contents of `this` and `other`.
1556
+ void swap(btree &other);
1557
+
1558
+ const key_compare &key_comp() const noexcept {
1559
+ return rightmost_.template get<0>();
1560
+ }
1561
+ template <typename K1, typename K2>
1562
+ bool compare_keys(const K1 &a, const K2 &b) const {
1563
+ return compare_internal::compare_result_as_less_than(key_comp()(a, b));
1564
+ }
1565
+
1566
+ value_compare value_comp() const {
1567
+ return value_compare(original_key_compare(key_comp()));
1568
+ }
1569
+
1570
+ // Verifies the structure of the btree.
1571
+ void verify() const;
1572
+
1573
+ // Size routines.
1574
+ size_type size() const { return size_; }
1575
+ size_type max_size() const { return (std::numeric_limits<size_type>::max)(); }
1576
+ bool empty() const { return size_ == 0; }
1577
+
1578
+ // The height of the btree. An empty tree will have height 0.
1579
+ size_type height() const {
1580
+ size_type h = 0;
1581
+ if (!empty()) {
1582
+ // Count the length of the chain from the leftmost node up to the
1583
+ // root. We actually count from the root back around to the level below
1584
+ // the root, but the calculation is the same because of the circularity
1585
+ // of that traversal.
1586
+ const node_type *n = root();
1587
+ do {
1588
+ ++h;
1589
+ n = n->parent();
1590
+ } while (n != root());
1591
+ }
1592
+ return h;
1593
+ }
1594
+
1595
+ // The number of internal, leaf and total nodes used by the btree.
1596
+ size_type leaf_nodes() const { return internal_stats(root()).leaf_nodes; }
1597
+ size_type internal_nodes() const {
1598
+ return internal_stats(root()).internal_nodes;
1599
+ }
1600
+ size_type nodes() const {
1601
+ node_stats stats = internal_stats(root());
1602
+ return stats.leaf_nodes + stats.internal_nodes;
1603
+ }
1604
+
1605
+ // The total number of bytes used by the btree.
1606
+ // TODO(b/169338300): update to support node_btree_*.
1607
+ size_type bytes_used() const {
1608
+ node_stats stats = internal_stats(root());
1609
+ if (stats.leaf_nodes == 1 && stats.internal_nodes == 0) {
1610
+ return sizeof(*this) + node_type::LeafSize(root()->max_count());
1611
+ } else {
1612
+ return sizeof(*this) + stats.leaf_nodes * node_type::LeafSize() +
1613
+ stats.internal_nodes * node_type::InternalSize();
1614
+ }
1615
+ }
1616
+
1617
+ // The average number of bytes used per value stored in the btree assuming
1618
+ // random insertion order.
1619
+ static double average_bytes_per_value() {
1620
+ // The expected number of values per node with random insertion order is the
1621
+ // average of the maximum and minimum numbers of values per node.
1622
+ const double expected_values_per_node = (kNodeSlots + kMinNodeValues) / 2.0;
1623
+ return node_type::LeafSize() / expected_values_per_node;
1624
+ }
1625
+
1626
+ // The fullness of the btree. Computed as the number of elements in the btree
1627
+ // divided by the maximum number of elements a tree with the current number
1628
+ // of nodes could hold. A value of 1 indicates perfect space
1629
+ // utilization. Smaller values indicate space wastage.
1630
+ // Returns 0 for empty trees.
1631
+ double fullness() const {
1632
+ if (empty()) return 0.0;
1633
+ return static_cast<double>(size()) / (nodes() * kNodeSlots);
1634
+ }
1635
+ // The overhead of the btree structure in bytes per node. Computed as the
1636
+ // total number of bytes used by the btree minus the number of bytes used for
1637
+ // storing elements divided by the number of elements.
1638
+ // Returns 0 for empty trees.
1639
+ double overhead() const {
1640
+ if (empty()) return 0.0;
1641
+ return (bytes_used() - size() * sizeof(value_type)) /
1642
+ static_cast<double>(size());
1643
+ }
1644
+
1645
+ // The allocator used by the btree.
1646
+ allocator_type get_allocator() const { return allocator(); }
1647
+
1648
+ private:
1649
+ friend struct btree_access;
1650
+
1651
+ // Internal accessor routines.
1652
+ node_type *root() { return root_; }
1653
+ const node_type *root() const { return root_; }
1654
+ node_type *&mutable_root() noexcept { return root_; }
1655
+ node_type *rightmost() { return rightmost_.template get<2>(); }
1656
+ const node_type *rightmost() const { return rightmost_.template get<2>(); }
1657
+ node_type *&mutable_rightmost() noexcept {
1658
+ return rightmost_.template get<2>();
1659
+ }
1660
+ key_compare *mutable_key_comp() noexcept {
1661
+ return &rightmost_.template get<0>();
1662
+ }
1663
+
1664
+ // The leftmost node is stored as the parent of the root node.
1665
+ node_type *leftmost() { return root()->parent(); }
1666
+ const node_type *leftmost() const { return root()->parent(); }
1667
+
1668
+ // Allocator routines.
1669
+ allocator_type *mutable_allocator() noexcept {
1670
+ return &rightmost_.template get<1>();
1671
+ }
1672
+ const allocator_type &allocator() const noexcept {
1673
+ return rightmost_.template get<1>();
1674
+ }
1675
+
1676
+ // Allocates a correctly aligned node of at least size bytes using the
1677
+ // allocator.
1678
+ node_type *allocate(size_type size) {
1679
+ return reinterpret_cast<node_type *>(
1680
+ absl::container_internal::Allocate<node_type::Alignment()>(
1681
+ mutable_allocator(), size));
1682
+ }
1683
+
1684
+ // Node creation/deletion routines.
1685
+ node_type *new_internal_node(field_type position, node_type *parent) {
1686
+ node_type *n = allocate(node_type::InternalSize());
1687
+ n->init_internal(position, parent);
1688
+ return n;
1689
+ }
1690
+ node_type *new_leaf_node(field_type position, node_type *parent) {
1691
+ node_type *n = allocate(node_type::LeafSize());
1692
+ n->init_leaf(position, kNodeSlots, parent);
1693
+ return n;
1694
+ }
1695
+ node_type *new_leaf_root_node(field_type max_count) {
1696
+ node_type *n = allocate(node_type::LeafSize(max_count));
1697
+ n->init_leaf(/*position=*/0, max_count, /*parent=*/n);
1698
+ return n;
1699
+ }
1700
+
1701
+ // Deletion helper routines.
1702
+ iterator rebalance_after_delete(iterator iter);
1703
+
1704
+ // Rebalances or splits the node iter points to.
1705
+ void rebalance_or_split(iterator *iter);
1706
+
1707
+ // Merges the values of left, right and the delimiting key on their parent
1708
+ // onto left, removing the delimiting key and deleting right.
1709
+ void merge_nodes(node_type *left, node_type *right);
1710
+
1711
+ // Tries to merge node with its left or right sibling, and failing that,
1712
+ // rebalance with its left or right sibling. Returns true if a merge
1713
+ // occurred, at which point it is no longer valid to access node. Returns
1714
+ // false if no merging took place.
1715
+ bool try_merge_or_rebalance(iterator *iter);
1716
+
1717
+ // Tries to shrink the height of the tree by 1.
1718
+ void try_shrink();
1719
+
1720
+ iterator internal_end(iterator iter) {
1721
+ return iter.node_ != nullptr ? iter : end();
1722
+ }
1723
+ const_iterator internal_end(const_iterator iter) const {
1724
+ return iter.node_ != nullptr ? iter : end();
1725
+ }
1726
+
1727
+ // Emplaces a value into the btree immediately before iter. Requires that
1728
+ // key(v) <= iter.key() and (--iter).key() <= key(v).
1729
+ template <typename... Args>
1730
+ iterator internal_emplace(iterator iter, Args &&...args);
1731
+
1732
+ // Returns an iterator pointing to the first value >= the value "iter" is
1733
+ // pointing at. Note that "iter" might be pointing to an invalid location such
1734
+ // as iter.position_ == iter.node_->finish(). This routine simply moves iter
1735
+ // up in the tree to a valid location. Requires: iter.node_ is non-null.
1736
+ template <typename IterType>
1737
+ static IterType internal_last(IterType iter);
1738
+
1739
+ // Returns an iterator pointing to the leaf position at which key would
1740
+ // reside in the tree, unless there is an exact match - in which case, the
1741
+ // result may not be on a leaf. When there's a three-way comparator, we can
1742
+ // return whether there was an exact match. This allows the caller to avoid a
1743
+ // subsequent comparison to determine if an exact match was made, which is
1744
+ // important for keys with expensive comparison, such as strings.
1745
+ template <typename K>
1746
+ SearchResult<iterator, is_key_compare_to::value> internal_locate(
1747
+ const K &key) const;
1748
+
1749
+ // Internal routine which implements lower_bound().
1750
+ template <typename K>
1751
+ SearchResult<iterator, is_key_compare_to::value> internal_lower_bound(
1752
+ const K &key) const;
1753
+
1754
+ // Internal routine which implements upper_bound().
1755
+ template <typename K>
1756
+ iterator internal_upper_bound(const K &key) const;
1757
+
1758
+ // Internal routine which implements find().
1759
+ template <typename K>
1760
+ iterator internal_find(const K &key) const;
1761
+
1762
+ // Verifies the tree structure of node.
1763
+ size_type internal_verify(const node_type *node, const key_type *lo,
1764
+ const key_type *hi) const;
1765
+
1766
+ node_stats internal_stats(const node_type *node) const {
1767
+ // The root can be a static empty node.
1768
+ if (node == nullptr || (node == root() && empty())) {
1769
+ return node_stats(0, 0);
1770
+ }
1771
+ if (node->is_leaf()) {
1772
+ return node_stats(1, 0);
1773
+ }
1774
+ node_stats res(0, 1);
1775
+ for (int i = node->start(); i <= node->finish(); ++i) {
1776
+ res += internal_stats(node->child(i));
1777
+ }
1778
+ return res;
1779
+ }
1780
+
1781
+ node_type *root_;
1782
+
1783
+ // A pointer to the rightmost node. Note that the leftmost node is stored as
1784
+ // the root's parent. We use compressed tuple in order to save space because
1785
+ // key_compare and allocator_type are usually empty.
1786
+ absl::container_internal::CompressedTuple<key_compare, allocator_type,
1787
+ node_type *>
1788
+ rightmost_;
1789
+
1790
+ // Number of values.
1791
+ size_type size_;
1792
+ };
1793
+
1794
+ ////
1795
+ // btree_node methods
1796
+ template <typename P>
1797
+ template <typename... Args>
1798
+ inline void btree_node<P>::emplace_value(const field_type i,
1799
+ allocator_type *alloc,
1800
+ Args &&...args) {
1801
+ assert(i >= start());
1802
+ assert(i <= finish());
1803
+ // Shift old values to create space for new value and then construct it in
1804
+ // place.
1805
+ if (i < finish()) {
1806
+ transfer_n_backward(finish() - i, /*dest_i=*/i + 1, /*src_i=*/i, this,
1807
+ alloc);
1808
+ }
1809
+ value_init(static_cast<field_type>(i), alloc, std::forward<Args>(args)...);
1810
+ set_finish(finish() + 1);
1811
+
1812
+ if (is_internal() && finish() > i + 1) {
1813
+ for (field_type j = finish(); j > i + 1; --j) {
1814
+ set_child(j, child(j - 1));
1815
+ }
1816
+ clear_child(i + 1);
1817
+ }
1818
+ }
1819
+
1820
+ template <typename P>
1821
+ inline void btree_node<P>::remove_values(const field_type i,
1822
+ const field_type to_erase,
1823
+ allocator_type *alloc) {
1824
+ // Transfer values after the removed range into their new places.
1825
+ value_destroy_n(i, to_erase, alloc);
1826
+ const field_type orig_finish = finish();
1827
+ const field_type src_i = i + to_erase;
1828
+ transfer_n(orig_finish - src_i, i, src_i, this, alloc);
1829
+
1830
+ if (is_internal()) {
1831
+ // Delete all children between begin and end.
1832
+ for (field_type j = 0; j < to_erase; ++j) {
1833
+ clear_and_delete(child(i + j + 1), alloc);
1834
+ }
1835
+ // Rotate children after end into new positions.
1836
+ for (field_type j = i + to_erase + 1; j <= orig_finish; ++j) {
1837
+ set_child(j - to_erase, child(j));
1838
+ clear_child(j);
1839
+ }
1840
+ }
1841
+ set_finish(orig_finish - to_erase);
1842
+ }
1843
+
1844
+ template <typename P>
1845
+ void btree_node<P>::rebalance_right_to_left(field_type to_move,
1846
+ btree_node *right,
1847
+ allocator_type *alloc) {
1848
+ assert(parent() == right->parent());
1849
+ assert(position() + 1 == right->position());
1850
+ assert(right->count() >= count());
1851
+ assert(to_move >= 1);
1852
+ assert(to_move <= right->count());
1853
+
1854
+ // 1) Move the delimiting value in the parent to the left node.
1855
+ transfer(finish(), position(), parent(), alloc);
1856
+
1857
+ // 2) Move the (to_move - 1) values from the right node to the left node.
1858
+ transfer_n(to_move - 1, finish() + 1, right->start(), right, alloc);
1859
+
1860
+ // 3) Move the new delimiting value to the parent from the right node.
1861
+ parent()->transfer(position(), right->start() + to_move - 1, right, alloc);
1862
+
1863
+ // 4) Shift the values in the right node to their correct positions.
1864
+ right->transfer_n(right->count() - to_move, right->start(),
1865
+ right->start() + to_move, right, alloc);
1866
+
1867
+ if (is_internal()) {
1868
+ // Move the child pointers from the right to the left node.
1869
+ for (field_type i = 0; i < to_move; ++i) {
1870
+ init_child(finish() + i + 1, right->child(i));
1871
+ }
1872
+ for (field_type i = right->start(); i <= right->finish() - to_move; ++i) {
1873
+ assert(i + to_move <= right->max_count());
1874
+ right->init_child(i, right->child(i + to_move));
1875
+ right->clear_child(i + to_move);
1876
+ }
1877
+ }
1878
+
1879
+ // Fixup `finish` on the left and right nodes.
1880
+ set_finish(finish() + to_move);
1881
+ right->set_finish(right->finish() - to_move);
1882
+ }
1883
+
1884
+ template <typename P>
1885
+ void btree_node<P>::rebalance_left_to_right(field_type to_move,
1886
+ btree_node *right,
1887
+ allocator_type *alloc) {
1888
+ assert(parent() == right->parent());
1889
+ assert(position() + 1 == right->position());
1890
+ assert(count() >= right->count());
1891
+ assert(to_move >= 1);
1892
+ assert(to_move <= count());
1893
+
1894
+ // Values in the right node are shifted to the right to make room for the
1895
+ // new to_move values. Then, the delimiting value in the parent and the
1896
+ // other (to_move - 1) values in the left node are moved into the right node.
1897
+ // Lastly, a new delimiting value is moved from the left node into the
1898
+ // parent, and the remaining empty left node entries are destroyed.
1899
+
1900
+ // 1) Shift existing values in the right node to their correct positions.
1901
+ right->transfer_n_backward(right->count(), right->start() + to_move,
1902
+ right->start(), right, alloc);
1903
+
1904
+ // 2) Move the delimiting value in the parent to the right node.
1905
+ right->transfer(right->start() + to_move - 1, position(), parent(), alloc);
1906
+
1907
+ // 3) Move the (to_move - 1) values from the left node to the right node.
1908
+ right->transfer_n(to_move - 1, right->start(), finish() - (to_move - 1), this,
1909
+ alloc);
1910
+
1911
+ // 4) Move the new delimiting value to the parent from the left node.
1912
+ parent()->transfer(position(), finish() - to_move, this, alloc);
1913
+
1914
+ if (is_internal()) {
1915
+ // Move the child pointers from the left to the right node.
1916
+ for (field_type i = right->finish() + 1; i > right->start(); --i) {
1917
+ right->init_child(i - 1 + to_move, right->child(i - 1));
1918
+ right->clear_child(i - 1);
1919
+ }
1920
+ for (field_type i = 1; i <= to_move; ++i) {
1921
+ right->init_child(i - 1, child(finish() - to_move + i));
1922
+ clear_child(finish() - to_move + i);
1923
+ }
1924
+ }
1925
+
1926
+ // Fixup the counts on the left and right nodes.
1927
+ set_finish(finish() - to_move);
1928
+ right->set_finish(right->finish() + to_move);
1929
+ }
1930
+
1931
+ template <typename P>
1932
+ void btree_node<P>::split(const int insert_position, btree_node *dest,
1933
+ allocator_type *alloc) {
1934
+ assert(dest->count() == 0);
1935
+ assert(max_count() == kNodeSlots);
1936
+ assert(position() + 1 == dest->position());
1937
+ assert(parent() == dest->parent());
1938
+
1939
+ // We bias the split based on the position being inserted. If we're
1940
+ // inserting at the beginning of the left node then bias the split to put
1941
+ // more values on the right node. If we're inserting at the end of the
1942
+ // right node then bias the split to put more values on the left node.
1943
+ if (insert_position == start()) {
1944
+ dest->set_finish(dest->start() + finish() - 1);
1945
+ } else if (insert_position == kNodeSlots) {
1946
+ dest->set_finish(dest->start());
1947
+ } else {
1948
+ dest->set_finish(dest->start() + count() / 2);
1949
+ }
1950
+ set_finish(finish() - dest->count());
1951
+ assert(count() >= 1);
1952
+
1953
+ // Move values from the left sibling to the right sibling.
1954
+ dest->transfer_n(dest->count(), dest->start(), finish(), this, alloc);
1955
+
1956
+ // The split key is the largest value in the left sibling.
1957
+ --mutable_finish();
1958
+ parent()->emplace_value(position(), alloc, finish_slot());
1959
+ value_destroy(finish(), alloc);
1960
+ parent()->set_child_noupdate_position(position() + 1, dest);
1961
+
1962
+ if (is_internal()) {
1963
+ for (field_type i = dest->start(), j = finish() + 1; i <= dest->finish();
1964
+ ++i, ++j) {
1965
+ assert(child(j) != nullptr);
1966
+ dest->init_child(i, child(j));
1967
+ clear_child(j);
1968
+ }
1969
+ }
1970
+ }
1971
+
1972
+ template <typename P>
1973
+ void btree_node<P>::merge(btree_node *src, allocator_type *alloc) {
1974
+ assert(parent() == src->parent());
1975
+ assert(position() + 1 == src->position());
1976
+
1977
+ // Move the delimiting value to the left node.
1978
+ value_init(finish(), alloc, parent()->slot(position()));
1979
+
1980
+ // Move the values from the right to the left node.
1981
+ transfer_n(src->count(), finish() + 1, src->start(), src, alloc);
1982
+
1983
+ if (is_internal()) {
1984
+ // Move the child pointers from the right to the left node.
1985
+ for (field_type i = src->start(), j = finish() + 1; i <= src->finish();
1986
+ ++i, ++j) {
1987
+ init_child(j, src->child(i));
1988
+ src->clear_child(i);
1989
+ }
1990
+ }
1991
+
1992
+ // Fixup `finish` on the src and dest nodes.
1993
+ set_finish(start() + 1 + count() + src->count());
1994
+ src->set_finish(src->start());
1995
+
1996
+ // Remove the value on the parent node and delete the src node.
1997
+ parent()->remove_values(position(), /*to_erase=*/1, alloc);
1998
+ }
1999
+
2000
+ template <typename P>
2001
+ void btree_node<P>::clear_and_delete(btree_node *node, allocator_type *alloc) {
2002
+ if (node->is_leaf()) {
2003
+ node->value_destroy_n(node->start(), node->count(), alloc);
2004
+ deallocate(LeafSize(node->max_count()), node, alloc);
2005
+ return;
2006
+ }
2007
+ if (node->count() == 0) {
2008
+ deallocate(InternalSize(), node, alloc);
2009
+ return;
2010
+ }
2011
+
2012
+ // The parent of the root of the subtree we are deleting.
2013
+ btree_node *delete_root_parent = node->parent();
2014
+
2015
+ // Navigate to the leftmost leaf under node, and then delete upwards.
2016
+ while (node->is_internal()) node = node->start_child();
2017
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
2018
+ // When generations are enabled, we delete the leftmost leaf last in case it's
2019
+ // the parent of the root and we need to check whether it's a leaf before we
2020
+ // can update the root's generation.
2021
+ // TODO(ezb): if we change btree_node::is_root to check a bool inside the node
2022
+ // instead of checking whether the parent is a leaf, we can remove this logic.
2023
+ btree_node *leftmost_leaf = node;
2024
+ #endif
2025
+ // Use `size_type` because `pos` needs to be able to hold `kNodeSlots+1`,
2026
+ // which isn't guaranteed to be a valid `field_type`.
2027
+ size_type pos = node->position();
2028
+ btree_node *parent = node->parent();
2029
+ for (;;) {
2030
+ // In each iteration of the next loop, we delete one leaf node and go right.
2031
+ assert(pos <= parent->finish());
2032
+ do {
2033
+ node = parent->child(static_cast<field_type>(pos));
2034
+ if (node->is_internal()) {
2035
+ // Navigate to the leftmost leaf under node.
2036
+ while (node->is_internal()) node = node->start_child();
2037
+ pos = node->position();
2038
+ parent = node->parent();
2039
+ }
2040
+ node->value_destroy_n(node->start(), node->count(), alloc);
2041
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
2042
+ if (leftmost_leaf != node)
2043
+ #endif
2044
+ deallocate(LeafSize(node->max_count()), node, alloc);
2045
+ ++pos;
2046
+ } while (pos <= parent->finish());
2047
+
2048
+ // Once we've deleted all children of parent, delete parent and go up/right.
2049
+ assert(pos > parent->finish());
2050
+ do {
2051
+ node = parent;
2052
+ pos = node->position();
2053
+ parent = node->parent();
2054
+ node->value_destroy_n(node->start(), node->count(), alloc);
2055
+ deallocate(InternalSize(), node, alloc);
2056
+ if (parent == delete_root_parent) {
2057
+ #ifdef ABSL_BTREE_ENABLE_GENERATIONS
2058
+ deallocate(LeafSize(leftmost_leaf->max_count()), leftmost_leaf, alloc);
2059
+ #endif
2060
+ return;
2061
+ }
2062
+ ++pos;
2063
+ } while (pos > parent->finish());
2064
+ }
2065
+ }
2066
+
2067
+ ////
2068
+ // btree_iterator methods
2069
+
2070
+ // Note: the implementation here is based on btree_node::clear_and_delete.
2071
+ template <typename N, typename R, typename P>
2072
+ auto btree_iterator<N, R, P>::distance_slow(const_iterator other) const
2073
+ -> difference_type {
2074
+ const_iterator begin = other;
2075
+ const_iterator end = *this;
2076
+ assert(begin.node_ != end.node_ || !begin.node_->is_leaf() ||
2077
+ begin.position_ != end.position_);
2078
+
2079
+ const node_type *node = begin.node_;
2080
+ // We need to compensate for double counting if begin.node_ is a leaf node.
2081
+ difference_type count = node->is_leaf() ? -begin.position_ : 0;
2082
+
2083
+ // First navigate to the leftmost leaf node past begin.
2084
+ if (node->is_internal()) {
2085
+ ++count;
2086
+ node = node->child(begin.position_ + 1);
2087
+ }
2088
+ while (node->is_internal()) node = node->start_child();
2089
+
2090
+ // Use `size_type` because `pos` needs to be able to hold `kNodeSlots+1`,
2091
+ // which isn't guaranteed to be a valid `field_type`.
2092
+ size_type pos = node->position();
2093
+ const node_type *parent = node->parent();
2094
+ for (;;) {
2095
+ // In each iteration of the next loop, we count one leaf node and go right.
2096
+ assert(pos <= parent->finish());
2097
+ do {
2098
+ node = parent->child(static_cast<field_type>(pos));
2099
+ if (node->is_internal()) {
2100
+ // Navigate to the leftmost leaf under node.
2101
+ while (node->is_internal()) node = node->start_child();
2102
+ pos = node->position();
2103
+ parent = node->parent();
2104
+ }
2105
+ if (node == end.node_) return count + end.position_;
2106
+ if (parent == end.node_ && pos == static_cast<size_type>(end.position_))
2107
+ return count + node->count();
2108
+ // +1 is for the next internal node value.
2109
+ count += node->count() + 1;
2110
+ ++pos;
2111
+ } while (pos <= parent->finish());
2112
+
2113
+ // Once we've counted all children of parent, go up/right.
2114
+ assert(pos > parent->finish());
2115
+ do {
2116
+ node = parent;
2117
+ pos = node->position();
2118
+ parent = node->parent();
2119
+ // -1 because we counted the value at end and shouldn't.
2120
+ if (parent == end.node_ && pos == static_cast<size_type>(end.position_))
2121
+ return count - 1;
2122
+ ++pos;
2123
+ } while (pos > parent->finish());
2124
+ }
2125
+ }
2126
+
2127
+ template <typename N, typename R, typename P>
2128
+ void btree_iterator<N, R, P>::increment_slow() {
2129
+ if (node_->is_leaf()) {
2130
+ assert(position_ >= node_->finish());
2131
+ btree_iterator save(*this);
2132
+ while (position_ == node_->finish() && !node_->is_root()) {
2133
+ assert(node_->parent()->child(node_->position()) == node_);
2134
+ position_ = node_->position();
2135
+ node_ = node_->parent();
2136
+ }
2137
+ // TODO(ezb): assert we aren't incrementing end() instead of handling.
2138
+ if (position_ == node_->finish()) {
2139
+ *this = save;
2140
+ }
2141
+ } else {
2142
+ assert(position_ < node_->finish());
2143
+ node_ = node_->child(static_cast<field_type>(position_ + 1));
2144
+ while (node_->is_internal()) {
2145
+ node_ = node_->start_child();
2146
+ }
2147
+ position_ = node_->start();
2148
+ }
2149
+ }
2150
+
2151
+ template <typename N, typename R, typename P>
2152
+ void btree_iterator<N, R, P>::decrement_slow() {
2153
+ if (node_->is_leaf()) {
2154
+ assert(position_ <= -1);
2155
+ btree_iterator save(*this);
2156
+ while (position_ < node_->start() && !node_->is_root()) {
2157
+ assert(node_->parent()->child(node_->position()) == node_);
2158
+ position_ = node_->position() - 1;
2159
+ node_ = node_->parent();
2160
+ }
2161
+ // TODO(ezb): assert we aren't decrementing begin() instead of handling.
2162
+ if (position_ < node_->start()) {
2163
+ *this = save;
2164
+ }
2165
+ } else {
2166
+ assert(position_ >= node_->start());
2167
+ node_ = node_->child(static_cast<field_type>(position_));
2168
+ while (node_->is_internal()) {
2169
+ node_ = node_->child(node_->finish());
2170
+ }
2171
+ position_ = node_->finish() - 1;
2172
+ }
2173
+ }
2174
+
2175
+ ////
2176
+ // btree methods
2177
+ template <typename P>
2178
+ template <typename Btree>
2179
+ void btree<P>::copy_or_move_values_in_order(Btree &other) {
2180
+ static_assert(std::is_same<btree, Btree>::value ||
2181
+ std::is_same<const btree, Btree>::value,
2182
+ "Btree type must be same or const.");
2183
+ assert(empty());
2184
+
2185
+ // We can avoid key comparisons because we know the order of the
2186
+ // values is the same order we'll store them in.
2187
+ auto iter = other.begin();
2188
+ if (iter == other.end()) return;
2189
+ insert_multi(iter.slot());
2190
+ ++iter;
2191
+ for (; iter != other.end(); ++iter) {
2192
+ // If the btree is not empty, we can just insert the new value at the end
2193
+ // of the tree.
2194
+ internal_emplace(end(), iter.slot());
2195
+ }
2196
+ }
2197
+
2198
+ template <typename P>
2199
+ constexpr bool btree<P>::static_assert_validation() {
2200
+ static_assert(std::is_nothrow_copy_constructible<key_compare>::value,
2201
+ "Key comparison must be nothrow copy constructible");
2202
+ static_assert(std::is_nothrow_copy_constructible<allocator_type>::value,
2203
+ "Allocator must be nothrow copy constructible");
2204
+ static_assert(std::is_trivially_copyable<iterator>::value,
2205
+ "iterator not trivially copyable.");
2206
+
2207
+ // Note: We assert that kTargetValues, which is computed from
2208
+ // Params::kTargetNodeSize, must fit the node_type::field_type.
2209
+ static_assert(
2210
+ kNodeSlots < (1 << (8 * sizeof(typename node_type::field_type))),
2211
+ "target node size too large");
2212
+
2213
+ // Verify that key_compare returns an absl::{weak,strong}_ordering or bool.
2214
+ static_assert(
2215
+ compare_has_valid_result_type<key_compare, key_type>(),
2216
+ "key comparison function must return absl::{weak,strong}_ordering or "
2217
+ "bool.");
2218
+
2219
+ // Test the assumption made in setting kNodeSlotSpace.
2220
+ static_assert(node_type::MinimumOverhead() >= sizeof(void *) + 4,
2221
+ "node space assumption incorrect");
2222
+
2223
+ return true;
2224
+ }
2225
+
2226
+ template <typename P>
2227
+ template <typename K>
2228
+ auto btree<P>::lower_bound_equal(const K &key) const
2229
+ -> std::pair<iterator, bool> {
2230
+ const SearchResult<iterator, is_key_compare_to::value> res =
2231
+ internal_lower_bound(key);
2232
+ const iterator lower = iterator(internal_end(res.value));
2233
+ const bool equal = res.HasMatch()
2234
+ ? res.IsEq()
2235
+ : lower != end() && !compare_keys(key, lower.key());
2236
+ return {lower, equal};
2237
+ }
2238
+
2239
+ template <typename P>
2240
+ template <typename K>
2241
+ auto btree<P>::equal_range(const K &key) -> std::pair<iterator, iterator> {
2242
+ const std::pair<iterator, bool> lower_and_equal = lower_bound_equal(key);
2243
+ const iterator lower = lower_and_equal.first;
2244
+ if (!lower_and_equal.second) {
2245
+ return {lower, lower};
2246
+ }
2247
+
2248
+ const iterator next = std::next(lower);
2249
+ if (!params_type::template can_have_multiple_equivalent_keys<K>()) {
2250
+ // The next iterator after lower must point to a key greater than `key`.
2251
+ // Note: if this assert fails, then it may indicate that the comparator does
2252
+ // not meet the equivalence requirements for Compare
2253
+ // (see https://en.cppreference.com/w/cpp/named_req/Compare).
2254
+ assert(next == end() || compare_keys(key, next.key()));
2255
+ return {lower, next};
2256
+ }
2257
+ // Try once more to avoid the call to upper_bound() if there's only one
2258
+ // equivalent key. This should prevent all calls to upper_bound() in cases of
2259
+ // unique-containers with heterogeneous comparators in which all comparison
2260
+ // operators have the same equivalence classes.
2261
+ if (next == end() || compare_keys(key, next.key())) return {lower, next};
2262
+
2263
+ // In this case, we need to call upper_bound() to avoid worst case O(N)
2264
+ // behavior if we were to iterate over equal keys.
2265
+ return {lower, upper_bound(key)};
2266
+ }
2267
+
2268
+ template <typename P>
2269
+ template <typename K, typename... Args>
2270
+ auto btree<P>::insert_unique(const K &key, Args &&...args)
2271
+ -> std::pair<iterator, bool> {
2272
+ if (empty()) {
2273
+ mutable_root() = mutable_rightmost() = new_leaf_root_node(1);
2274
+ }
2275
+
2276
+ SearchResult<iterator, is_key_compare_to::value> res = internal_locate(key);
2277
+ iterator iter = res.value;
2278
+
2279
+ if (res.HasMatch()) {
2280
+ if (res.IsEq()) {
2281
+ // The key already exists in the tree, do nothing.
2282
+ return {iter, false};
2283
+ }
2284
+ } else {
2285
+ iterator last = internal_last(iter);
2286
+ if (last.node_ && !compare_keys(key, last.key())) {
2287
+ // The key already exists in the tree, do nothing.
2288
+ return {last, false};
2289
+ }
2290
+ }
2291
+ return {internal_emplace(iter, std::forward<Args>(args)...), true};
2292
+ }
2293
+
2294
+ template <typename P>
2295
+ template <typename K, typename... Args>
2296
+ inline auto btree<P>::insert_hint_unique(iterator position, const K &key,
2297
+ Args &&...args)
2298
+ -> std::pair<iterator, bool> {
2299
+ if (!empty()) {
2300
+ if (position == end() || compare_keys(key, position.key())) {
2301
+ if (position == begin() || compare_keys(std::prev(position).key(), key)) {
2302
+ // prev.key() < key < position.key()
2303
+ return {internal_emplace(position, std::forward<Args>(args)...), true};
2304
+ }
2305
+ } else if (compare_keys(position.key(), key)) {
2306
+ ++position;
2307
+ if (position == end() || compare_keys(key, position.key())) {
2308
+ // {original `position`}.key() < key < {current `position`}.key()
2309
+ return {internal_emplace(position, std::forward<Args>(args)...), true};
2310
+ }
2311
+ } else {
2312
+ // position.key() == key
2313
+ return {position, false};
2314
+ }
2315
+ }
2316
+ return insert_unique(key, std::forward<Args>(args)...);
2317
+ }
2318
+
2319
+ template <typename P>
2320
+ template <typename InputIterator, typename>
2321
+ void btree<P>::insert_iterator_unique(InputIterator b, InputIterator e, int) {
2322
+ for (; b != e; ++b) {
2323
+ insert_hint_unique(end(), params_type::key(*b), *b);
2324
+ }
2325
+ }
2326
+
2327
+ template <typename P>
2328
+ template <typename InputIterator>
2329
+ void btree<P>::insert_iterator_unique(InputIterator b, InputIterator e, char) {
2330
+ for (; b != e; ++b) {
2331
+ // Use a node handle to manage a temp slot.
2332
+ auto node_handle =
2333
+ CommonAccess::Construct<node_handle_type>(get_allocator(), *b);
2334
+ slot_type *slot = CommonAccess::GetSlot(node_handle);
2335
+ insert_hint_unique(end(), params_type::key(slot), slot);
2336
+ }
2337
+ }
2338
+
2339
+ template <typename P>
2340
+ template <typename ValueType>
2341
+ auto btree<P>::insert_multi(const key_type &key, ValueType &&v) -> iterator {
2342
+ if (empty()) {
2343
+ mutable_root() = mutable_rightmost() = new_leaf_root_node(1);
2344
+ }
2345
+
2346
+ iterator iter = internal_upper_bound(key);
2347
+ if (iter.node_ == nullptr) {
2348
+ iter = end();
2349
+ }
2350
+ return internal_emplace(iter, std::forward<ValueType>(v));
2351
+ }
2352
+
2353
+ template <typename P>
2354
+ template <typename ValueType>
2355
+ auto btree<P>::insert_hint_multi(iterator position, ValueType &&v) -> iterator {
2356
+ if (!empty()) {
2357
+ const key_type &key = params_type::key(v);
2358
+ if (position == end() || !compare_keys(position.key(), key)) {
2359
+ if (position == begin() ||
2360
+ !compare_keys(key, std::prev(position).key())) {
2361
+ // prev.key() <= key <= position.key()
2362
+ return internal_emplace(position, std::forward<ValueType>(v));
2363
+ }
2364
+ } else {
2365
+ ++position;
2366
+ if (position == end() || !compare_keys(position.key(), key)) {
2367
+ // {original `position`}.key() < key < {current `position`}.key()
2368
+ return internal_emplace(position, std::forward<ValueType>(v));
2369
+ }
2370
+ }
2371
+ }
2372
+ return insert_multi(std::forward<ValueType>(v));
2373
+ }
2374
+
2375
+ template <typename P>
2376
+ template <typename InputIterator>
2377
+ void btree<P>::insert_iterator_multi(InputIterator b, InputIterator e) {
2378
+ for (; b != e; ++b) {
2379
+ insert_hint_multi(end(), *b);
2380
+ }
2381
+ }
2382
+
2383
+ template <typename P>
2384
+ auto btree<P>::operator=(const btree &other) -> btree & {
2385
+ if (this != &other) {
2386
+ clear();
2387
+
2388
+ *mutable_key_comp() = other.key_comp();
2389
+ if (absl::allocator_traits<
2390
+ allocator_type>::propagate_on_container_copy_assignment::value) {
2391
+ *mutable_allocator() = other.allocator();
2392
+ }
2393
+
2394
+ copy_or_move_values_in_order(other);
2395
+ }
2396
+ return *this;
2397
+ }
2398
+
2399
+ template <typename P>
2400
+ auto btree<P>::operator=(btree &&other) noexcept -> btree & {
2401
+ if (this != &other) {
2402
+ clear();
2403
+
2404
+ using std::swap;
2405
+ if (absl::allocator_traits<
2406
+ allocator_type>::propagate_on_container_move_assignment::value) {
2407
+ swap(root_, other.root_);
2408
+ // Note: `rightmost_` also contains the allocator and the key comparator.
2409
+ swap(rightmost_, other.rightmost_);
2410
+ swap(size_, other.size_);
2411
+ } else {
2412
+ if (allocator() == other.allocator()) {
2413
+ swap(mutable_root(), other.mutable_root());
2414
+ swap(*mutable_key_comp(), *other.mutable_key_comp());
2415
+ swap(mutable_rightmost(), other.mutable_rightmost());
2416
+ swap(size_, other.size_);
2417
+ } else {
2418
+ // We aren't allowed to propagate the allocator and the allocator is
2419
+ // different so we can't take over its memory. We must move each element
2420
+ // individually. We need both `other` and `this` to have `other`s key
2421
+ // comparator while moving the values so we can't swap the key
2422
+ // comparators.
2423
+ *mutable_key_comp() = other.key_comp();
2424
+ copy_or_move_values_in_order(other);
2425
+ }
2426
+ }
2427
+ }
2428
+ return *this;
2429
+ }
2430
+
2431
+ template <typename P>
2432
+ auto btree<P>::erase(iterator iter) -> iterator {
2433
+ iter.node_->value_destroy(static_cast<field_type>(iter.position_),
2434
+ mutable_allocator());
2435
+ iter.update_generation();
2436
+
2437
+ const bool internal_delete = iter.node_->is_internal();
2438
+ if (internal_delete) {
2439
+ // Deletion of a value on an internal node. First, transfer the largest
2440
+ // value from our left child here, then erase/rebalance from that position.
2441
+ // We can get to the largest value from our left child by decrementing iter.
2442
+ iterator internal_iter(iter);
2443
+ --iter;
2444
+ assert(iter.node_->is_leaf());
2445
+ internal_iter.node_->transfer(
2446
+ static_cast<size_type>(internal_iter.position_),
2447
+ static_cast<size_type>(iter.position_), iter.node_,
2448
+ mutable_allocator());
2449
+ } else {
2450
+ // Shift values after erased position in leaf. In the internal case, we
2451
+ // don't need to do this because the leaf position is the end of the node.
2452
+ const field_type transfer_from =
2453
+ static_cast<field_type>(iter.position_ + 1);
2454
+ const field_type num_to_transfer = iter.node_->finish() - transfer_from;
2455
+ iter.node_->transfer_n(num_to_transfer,
2456
+ static_cast<size_type>(iter.position_),
2457
+ transfer_from, iter.node_, mutable_allocator());
2458
+ }
2459
+ // Update node finish and container size.
2460
+ iter.node_->set_finish(iter.node_->finish() - 1);
2461
+ --size_;
2462
+
2463
+ // We want to return the next value after the one we just erased. If we
2464
+ // erased from an internal node (internal_delete == true), then the next
2465
+ // value is ++(++iter). If we erased from a leaf node (internal_delete ==
2466
+ // false) then the next value is ++iter. Note that ++iter may point to an
2467
+ // internal node and the value in the internal node may move to a leaf node
2468
+ // (iter.node_) when rebalancing is performed at the leaf level.
2469
+
2470
+ iterator res = rebalance_after_delete(iter);
2471
+
2472
+ // If we erased from an internal node, advance the iterator.
2473
+ if (internal_delete) {
2474
+ ++res;
2475
+ }
2476
+ return res;
2477
+ }
2478
+
2479
+ template <typename P>
2480
+ auto btree<P>::rebalance_after_delete(iterator iter) -> iterator {
2481
+ // Merge/rebalance as we walk back up the tree.
2482
+ iterator res(iter);
2483
+ bool first_iteration = true;
2484
+ for (;;) {
2485
+ if (iter.node_ == root()) {
2486
+ try_shrink();
2487
+ if (empty()) {
2488
+ return end();
2489
+ }
2490
+ break;
2491
+ }
2492
+ if (iter.node_->count() >= kMinNodeValues) {
2493
+ break;
2494
+ }
2495
+ bool merged = try_merge_or_rebalance(&iter);
2496
+ // On the first iteration, we should update `res` with `iter` because `res`
2497
+ // may have been invalidated.
2498
+ if (first_iteration) {
2499
+ res = iter;
2500
+ first_iteration = false;
2501
+ }
2502
+ if (!merged) {
2503
+ break;
2504
+ }
2505
+ iter.position_ = iter.node_->position();
2506
+ iter.node_ = iter.node_->parent();
2507
+ }
2508
+ res.update_generation();
2509
+
2510
+ // Adjust our return value. If we're pointing at the end of a node, advance
2511
+ // the iterator.
2512
+ if (res.position_ == res.node_->finish()) {
2513
+ res.position_ = res.node_->finish() - 1;
2514
+ ++res;
2515
+ }
2516
+
2517
+ return res;
2518
+ }
2519
+
2520
+ // Note: we tried implementing this more efficiently by erasing all of the
2521
+ // elements in [begin, end) at once and then doing rebalancing once at the end
2522
+ // (rather than interleaving deletion and rebalancing), but that adds a lot of
2523
+ // complexity, which seems to outweigh the performance win.
2524
+ template <typename P>
2525
+ auto btree<P>::erase_range(iterator begin, iterator end)
2526
+ -> std::pair<size_type, iterator> {
2527
+ size_type count = static_cast<size_type>(end - begin);
2528
+ assert(count >= 0);
2529
+
2530
+ if (count == 0) {
2531
+ return {0, begin};
2532
+ }
2533
+
2534
+ if (static_cast<size_type>(count) == size_) {
2535
+ clear();
2536
+ return {count, this->end()};
2537
+ }
2538
+
2539
+ if (begin.node_ == end.node_) {
2540
+ assert(end.position_ > begin.position_);
2541
+ begin.node_->remove_values(
2542
+ static_cast<field_type>(begin.position_),
2543
+ static_cast<field_type>(end.position_ - begin.position_),
2544
+ mutable_allocator());
2545
+ size_ -= count;
2546
+ return {count, rebalance_after_delete(begin)};
2547
+ }
2548
+
2549
+ const size_type target_size = size_ - count;
2550
+ while (size_ > target_size) {
2551
+ if (begin.node_->is_leaf()) {
2552
+ const size_type remaining_to_erase = size_ - target_size;
2553
+ const size_type remaining_in_node =
2554
+ static_cast<size_type>(begin.node_->finish() - begin.position_);
2555
+ const field_type to_erase = static_cast<field_type>(
2556
+ (std::min)(remaining_to_erase, remaining_in_node));
2557
+ begin.node_->remove_values(static_cast<field_type>(begin.position_),
2558
+ to_erase, mutable_allocator());
2559
+ size_ -= to_erase;
2560
+ begin = rebalance_after_delete(begin);
2561
+ } else {
2562
+ begin = erase(begin);
2563
+ }
2564
+ }
2565
+ begin.update_generation();
2566
+ return {count, begin};
2567
+ }
2568
+
2569
+ template <typename P>
2570
+ void btree<P>::clear() {
2571
+ if (!empty()) {
2572
+ node_type::clear_and_delete(root(), mutable_allocator());
2573
+ }
2574
+ mutable_root() = mutable_rightmost() = EmptyNode();
2575
+ size_ = 0;
2576
+ }
2577
+
2578
+ template <typename P>
2579
+ void btree<P>::swap(btree &other) {
2580
+ using std::swap;
2581
+ if (absl::allocator_traits<
2582
+ allocator_type>::propagate_on_container_swap::value) {
2583
+ // Note: `rightmost_` also contains the allocator and the key comparator.
2584
+ swap(rightmost_, other.rightmost_);
2585
+ } else {
2586
+ // It's undefined behavior if the allocators are unequal here.
2587
+ assert(allocator() == other.allocator());
2588
+ swap(mutable_rightmost(), other.mutable_rightmost());
2589
+ swap(*mutable_key_comp(), *other.mutable_key_comp());
2590
+ }
2591
+ swap(mutable_root(), other.mutable_root());
2592
+ swap(size_, other.size_);
2593
+ }
2594
+
2595
+ template <typename P>
2596
+ void btree<P>::verify() const {
2597
+ assert(root() != nullptr);
2598
+ assert(leftmost() != nullptr);
2599
+ assert(rightmost() != nullptr);
2600
+ assert(empty() || size() == internal_verify(root(), nullptr, nullptr));
2601
+ assert(leftmost() == (++const_iterator(root(), -1)).node_);
2602
+ assert(rightmost() == (--const_iterator(root(), root()->finish())).node_);
2603
+ assert(leftmost()->is_leaf());
2604
+ assert(rightmost()->is_leaf());
2605
+ }
2606
+
2607
+ template <typename P>
2608
+ void btree<P>::rebalance_or_split(iterator *iter) {
2609
+ node_type *&node = iter->node_;
2610
+ int &insert_position = iter->position_;
2611
+ assert(node->count() == node->max_count());
2612
+ assert(kNodeSlots == node->max_count());
2613
+
2614
+ // First try to make room on the node by rebalancing.
2615
+ node_type *parent = node->parent();
2616
+ if (node != root()) {
2617
+ if (node->position() > parent->start()) {
2618
+ // Try rebalancing with our left sibling.
2619
+ node_type *left = parent->child(node->position() - 1);
2620
+ assert(left->max_count() == kNodeSlots);
2621
+ if (left->count() < kNodeSlots) {
2622
+ // We bias rebalancing based on the position being inserted. If we're
2623
+ // inserting at the end of the right node then we bias rebalancing to
2624
+ // fill up the left node.
2625
+ field_type to_move =
2626
+ (kNodeSlots - left->count()) /
2627
+ (1 + (static_cast<field_type>(insert_position) < kNodeSlots));
2628
+ to_move = (std::max)(field_type{1}, to_move);
2629
+
2630
+ if (static_cast<field_type>(insert_position) - to_move >=
2631
+ node->start() ||
2632
+ left->count() + to_move < kNodeSlots) {
2633
+ left->rebalance_right_to_left(to_move, node, mutable_allocator());
2634
+
2635
+ assert(node->max_count() - node->count() == to_move);
2636
+ insert_position = static_cast<int>(
2637
+ static_cast<field_type>(insert_position) - to_move);
2638
+ if (insert_position < node->start()) {
2639
+ insert_position = insert_position + left->count() + 1;
2640
+ node = left;
2641
+ }
2642
+
2643
+ assert(node->count() < node->max_count());
2644
+ return;
2645
+ }
2646
+ }
2647
+ }
2648
+
2649
+ if (node->position() < parent->finish()) {
2650
+ // Try rebalancing with our right sibling.
2651
+ node_type *right = parent->child(node->position() + 1);
2652
+ assert(right->max_count() == kNodeSlots);
2653
+ if (right->count() < kNodeSlots) {
2654
+ // We bias rebalancing based on the position being inserted. If we're
2655
+ // inserting at the beginning of the left node then we bias rebalancing
2656
+ // to fill up the right node.
2657
+ field_type to_move = (kNodeSlots - right->count()) /
2658
+ (1 + (insert_position > node->start()));
2659
+ to_move = (std::max)(field_type{1}, to_move);
2660
+
2661
+ if (static_cast<field_type>(insert_position) <=
2662
+ node->finish() - to_move ||
2663
+ right->count() + to_move < kNodeSlots) {
2664
+ node->rebalance_left_to_right(to_move, right, mutable_allocator());
2665
+
2666
+ if (insert_position > node->finish()) {
2667
+ insert_position = insert_position - node->count() - 1;
2668
+ node = right;
2669
+ }
2670
+
2671
+ assert(node->count() < node->max_count());
2672
+ return;
2673
+ }
2674
+ }
2675
+ }
2676
+
2677
+ // Rebalancing failed, make sure there is room on the parent node for a new
2678
+ // value.
2679
+ assert(parent->max_count() == kNodeSlots);
2680
+ if (parent->count() == kNodeSlots) {
2681
+ iterator parent_iter(parent, node->position());
2682
+ rebalance_or_split(&parent_iter);
2683
+ parent = node->parent();
2684
+ }
2685
+ } else {
2686
+ // Rebalancing not possible because this is the root node.
2687
+ // Create a new root node and set the current root node as the child of the
2688
+ // new root.
2689
+ parent = new_internal_node(/*position=*/0, parent);
2690
+ parent->set_generation(root()->generation());
2691
+ parent->init_child(parent->start(), node);
2692
+ mutable_root() = parent;
2693
+ // If the former root was a leaf node, then it's now the rightmost node.
2694
+ assert(parent->start_child()->is_internal() ||
2695
+ parent->start_child() == rightmost());
2696
+ }
2697
+
2698
+ // Split the node.
2699
+ node_type *split_node;
2700
+ if (node->is_leaf()) {
2701
+ split_node = new_leaf_node(node->position() + 1, parent);
2702
+ node->split(insert_position, split_node, mutable_allocator());
2703
+ if (rightmost() == node) mutable_rightmost() = split_node;
2704
+ } else {
2705
+ split_node = new_internal_node(node->position() + 1, parent);
2706
+ node->split(insert_position, split_node, mutable_allocator());
2707
+ }
2708
+
2709
+ if (insert_position > node->finish()) {
2710
+ insert_position = insert_position - node->count() - 1;
2711
+ node = split_node;
2712
+ }
2713
+ }
2714
+
2715
+ template <typename P>
2716
+ void btree<P>::merge_nodes(node_type *left, node_type *right) {
2717
+ left->merge(right, mutable_allocator());
2718
+ if (rightmost() == right) mutable_rightmost() = left;
2719
+ }
2720
+
2721
+ template <typename P>
2722
+ bool btree<P>::try_merge_or_rebalance(iterator *iter) {
2723
+ node_type *parent = iter->node_->parent();
2724
+ if (iter->node_->position() > parent->start()) {
2725
+ // Try merging with our left sibling.
2726
+ node_type *left = parent->child(iter->node_->position() - 1);
2727
+ assert(left->max_count() == kNodeSlots);
2728
+ if (1U + left->count() + iter->node_->count() <= kNodeSlots) {
2729
+ iter->position_ += 1 + left->count();
2730
+ merge_nodes(left, iter->node_);
2731
+ iter->node_ = left;
2732
+ return true;
2733
+ }
2734
+ }
2735
+ if (iter->node_->position() < parent->finish()) {
2736
+ // Try merging with our right sibling.
2737
+ node_type *right = parent->child(iter->node_->position() + 1);
2738
+ assert(right->max_count() == kNodeSlots);
2739
+ if (1U + iter->node_->count() + right->count() <= kNodeSlots) {
2740
+ merge_nodes(iter->node_, right);
2741
+ return true;
2742
+ }
2743
+ // Try rebalancing with our right sibling. We don't perform rebalancing if
2744
+ // we deleted the first element from iter->node_ and the node is not
2745
+ // empty. This is a small optimization for the common pattern of deleting
2746
+ // from the front of the tree.
2747
+ if (right->count() > kMinNodeValues &&
2748
+ (iter->node_->count() == 0 || iter->position_ > iter->node_->start())) {
2749
+ field_type to_move = (right->count() - iter->node_->count()) / 2;
2750
+ to_move =
2751
+ (std::min)(to_move, static_cast<field_type>(right->count() - 1));
2752
+ iter->node_->rebalance_right_to_left(to_move, right, mutable_allocator());
2753
+ return false;
2754
+ }
2755
+ }
2756
+ if (iter->node_->position() > parent->start()) {
2757
+ // Try rebalancing with our left sibling. We don't perform rebalancing if
2758
+ // we deleted the last element from iter->node_ and the node is not
2759
+ // empty. This is a small optimization for the common pattern of deleting
2760
+ // from the back of the tree.
2761
+ node_type *left = parent->child(iter->node_->position() - 1);
2762
+ if (left->count() > kMinNodeValues &&
2763
+ (iter->node_->count() == 0 ||
2764
+ iter->position_ < iter->node_->finish())) {
2765
+ field_type to_move = (left->count() - iter->node_->count()) / 2;
2766
+ to_move = (std::min)(to_move, static_cast<field_type>(left->count() - 1));
2767
+ left->rebalance_left_to_right(to_move, iter->node_, mutable_allocator());
2768
+ iter->position_ += to_move;
2769
+ return false;
2770
+ }
2771
+ }
2772
+ return false;
2773
+ }
2774
+
2775
+ template <typename P>
2776
+ void btree<P>::try_shrink() {
2777
+ node_type *orig_root = root();
2778
+ if (orig_root->count() > 0) {
2779
+ return;
2780
+ }
2781
+ // Deleted the last item on the root node, shrink the height of the tree.
2782
+ if (orig_root->is_leaf()) {
2783
+ assert(size() == 0);
2784
+ mutable_root() = mutable_rightmost() = EmptyNode();
2785
+ } else {
2786
+ node_type *child = orig_root->start_child();
2787
+ child->make_root();
2788
+ mutable_root() = child;
2789
+ }
2790
+ node_type::clear_and_delete(orig_root, mutable_allocator());
2791
+ }
2792
+
2793
+ template <typename P>
2794
+ template <typename IterType>
2795
+ inline IterType btree<P>::internal_last(IterType iter) {
2796
+ assert(iter.node_ != nullptr);
2797
+ while (iter.position_ == iter.node_->finish()) {
2798
+ iter.position_ = iter.node_->position();
2799
+ iter.node_ = iter.node_->parent();
2800
+ if (iter.node_->is_leaf()) {
2801
+ iter.node_ = nullptr;
2802
+ break;
2803
+ }
2804
+ }
2805
+ iter.update_generation();
2806
+ return iter;
2807
+ }
2808
+
2809
+ template <typename P>
2810
+ template <typename... Args>
2811
+ inline auto btree<P>::internal_emplace(iterator iter, Args &&...args)
2812
+ -> iterator {
2813
+ if (iter.node_->is_internal()) {
2814
+ // We can't insert on an internal node. Instead, we'll insert after the
2815
+ // previous value which is guaranteed to be on a leaf node.
2816
+ --iter;
2817
+ ++iter.position_;
2818
+ }
2819
+ const field_type max_count = iter.node_->max_count();
2820
+ allocator_type *alloc = mutable_allocator();
2821
+
2822
+ const auto transfer_and_delete = [&](node_type *old_node,
2823
+ node_type *new_node) {
2824
+ new_node->transfer_n(old_node->count(), new_node->start(),
2825
+ old_node->start(), old_node, alloc);
2826
+ new_node->set_finish(old_node->finish());
2827
+ old_node->set_finish(old_node->start());
2828
+ new_node->set_generation(old_node->generation());
2829
+ node_type::clear_and_delete(old_node, alloc);
2830
+ };
2831
+ const auto replace_leaf_root_node = [&](field_type new_node_size) {
2832
+ assert(iter.node_ == root());
2833
+ node_type *old_root = iter.node_;
2834
+ node_type *new_root = iter.node_ = new_leaf_root_node(new_node_size);
2835
+ transfer_and_delete(old_root, new_root);
2836
+ mutable_root() = mutable_rightmost() = new_root;
2837
+ };
2838
+
2839
+ bool replaced_node = false;
2840
+ if (iter.node_->count() == max_count) {
2841
+ // Make room in the leaf for the new item.
2842
+ if (max_count < kNodeSlots) {
2843
+ // Insertion into the root where the root is smaller than the full node
2844
+ // size. Simply grow the size of the root node.
2845
+ replace_leaf_root_node(static_cast<field_type>(
2846
+ (std::min)(static_cast<int>(kNodeSlots), 2 * max_count)));
2847
+ replaced_node = true;
2848
+ } else {
2849
+ rebalance_or_split(&iter);
2850
+ }
2851
+ }
2852
+ (void)replaced_node;
2853
+ #if defined(ABSL_HAVE_ADDRESS_SANITIZER) || \
2854
+ defined(ABSL_HAVE_HWADDRESS_SANITIZER)
2855
+ if (!replaced_node) {
2856
+ assert(iter.node_->is_leaf());
2857
+ if (iter.node_->is_root()) {
2858
+ replace_leaf_root_node(max_count);
2859
+ } else {
2860
+ node_type *old_node = iter.node_;
2861
+ const bool was_rightmost = rightmost() == old_node;
2862
+ const bool was_leftmost = leftmost() == old_node;
2863
+ node_type *parent = old_node->parent();
2864
+ const field_type position = old_node->position();
2865
+ node_type *new_node = iter.node_ = new_leaf_node(position, parent);
2866
+ parent->set_child_noupdate_position(position, new_node);
2867
+ transfer_and_delete(old_node, new_node);
2868
+ if (was_rightmost) mutable_rightmost() = new_node;
2869
+ // The leftmost node is stored as the parent of the root node.
2870
+ if (was_leftmost) root()->set_parent(new_node);
2871
+ }
2872
+ }
2873
+ #endif
2874
+ iter.node_->emplace_value(static_cast<field_type>(iter.position_), alloc,
2875
+ std::forward<Args>(args)...);
2876
+ assert(
2877
+ iter.node_->is_ordered_correctly(static_cast<field_type>(iter.position_),
2878
+ original_key_compare(key_comp())) &&
2879
+ "If this assert fails, then either (1) the comparator may violate "
2880
+ "transitivity, i.e. comp(a,b) && comp(b,c) -> comp(a,c) (see "
2881
+ "https://en.cppreference.com/w/cpp/named_req/Compare), or (2) a "
2882
+ "key may have been mutated after it was inserted into the tree.");
2883
+ ++size_;
2884
+ iter.update_generation();
2885
+ return iter;
2886
+ }
2887
+
2888
+ template <typename P>
2889
+ template <typename K>
2890
+ inline auto btree<P>::internal_locate(const K &key) const
2891
+ -> SearchResult<iterator, is_key_compare_to::value> {
2892
+ iterator iter(const_cast<node_type *>(root()));
2893
+ for (;;) {
2894
+ SearchResult<size_type, is_key_compare_to::value> res =
2895
+ iter.node_->lower_bound(key, key_comp());
2896
+ iter.position_ = static_cast<int>(res.value);
2897
+ if (res.IsEq()) {
2898
+ return {iter, MatchKind::kEq};
2899
+ }
2900
+ // Note: in the non-key-compare-to case, we don't need to walk all the way
2901
+ // down the tree if the keys are equal, but determining equality would
2902
+ // require doing an extra comparison on each node on the way down, and we
2903
+ // will need to go all the way to the leaf node in the expected case.
2904
+ if (iter.node_->is_leaf()) {
2905
+ break;
2906
+ }
2907
+ iter.node_ = iter.node_->child(static_cast<field_type>(iter.position_));
2908
+ }
2909
+ // Note: in the non-key-compare-to case, the key may actually be equivalent
2910
+ // here (and the MatchKind::kNe is ignored).
2911
+ return {iter, MatchKind::kNe};
2912
+ }
2913
+
2914
+ template <typename P>
2915
+ template <typename K>
2916
+ auto btree<P>::internal_lower_bound(const K &key) const
2917
+ -> SearchResult<iterator, is_key_compare_to::value> {
2918
+ if (!params_type::template can_have_multiple_equivalent_keys<K>()) {
2919
+ SearchResult<iterator, is_key_compare_to::value> ret = internal_locate(key);
2920
+ ret.value = internal_last(ret.value);
2921
+ return ret;
2922
+ }
2923
+ iterator iter(const_cast<node_type *>(root()));
2924
+ SearchResult<size_type, is_key_compare_to::value> res;
2925
+ bool seen_eq = false;
2926
+ for (;;) {
2927
+ res = iter.node_->lower_bound(key, key_comp());
2928
+ iter.position_ = static_cast<int>(res.value);
2929
+ if (iter.node_->is_leaf()) {
2930
+ break;
2931
+ }
2932
+ seen_eq = seen_eq || res.IsEq();
2933
+ iter.node_ = iter.node_->child(static_cast<field_type>(iter.position_));
2934
+ }
2935
+ if (res.IsEq()) return {iter, MatchKind::kEq};
2936
+ return {internal_last(iter), seen_eq ? MatchKind::kEq : MatchKind::kNe};
2937
+ }
2938
+
2939
+ template <typename P>
2940
+ template <typename K>
2941
+ auto btree<P>::internal_upper_bound(const K &key) const -> iterator {
2942
+ iterator iter(const_cast<node_type *>(root()));
2943
+ for (;;) {
2944
+ iter.position_ = static_cast<int>(iter.node_->upper_bound(key, key_comp()));
2945
+ if (iter.node_->is_leaf()) {
2946
+ break;
2947
+ }
2948
+ iter.node_ = iter.node_->child(static_cast<field_type>(iter.position_));
2949
+ }
2950
+ return internal_last(iter);
2951
+ }
2952
+
2953
+ template <typename P>
2954
+ template <typename K>
2955
+ auto btree<P>::internal_find(const K &key) const -> iterator {
2956
+ SearchResult<iterator, is_key_compare_to::value> res = internal_locate(key);
2957
+ if (res.HasMatch()) {
2958
+ if (res.IsEq()) {
2959
+ return res.value;
2960
+ }
2961
+ } else {
2962
+ const iterator iter = internal_last(res.value);
2963
+ if (iter.node_ != nullptr && !compare_keys(key, iter.key())) {
2964
+ return iter;
2965
+ }
2966
+ }
2967
+ return {nullptr, 0};
2968
+ }
2969
+
2970
+ template <typename P>
2971
+ typename btree<P>::size_type btree<P>::internal_verify(
2972
+ const node_type *node, const key_type *lo, const key_type *hi) const {
2973
+ assert(node->count() > 0);
2974
+ assert(node->count() <= node->max_count());
2975
+ if (lo) {
2976
+ assert(!compare_keys(node->key(node->start()), *lo));
2977
+ }
2978
+ if (hi) {
2979
+ assert(!compare_keys(*hi, node->key(node->finish() - 1)));
2980
+ }
2981
+ for (int i = node->start() + 1; i < node->finish(); ++i) {
2982
+ assert(!compare_keys(node->key(i), node->key(i - 1)));
2983
+ }
2984
+ size_type count = node->count();
2985
+ if (node->is_internal()) {
2986
+ for (field_type i = node->start(); i <= node->finish(); ++i) {
2987
+ assert(node->child(i) != nullptr);
2988
+ assert(node->child(i)->parent() == node);
2989
+ assert(node->child(i)->position() == i);
2990
+ count += internal_verify(node->child(i),
2991
+ i == node->start() ? lo : &node->key(i - 1),
2992
+ i == node->finish() ? hi : &node->key(i));
2993
+ }
2994
+ }
2995
+ return count;
2996
+ }
2997
+
2998
+ struct btree_access {
2999
+ template <typename BtreeContainer, typename Pred>
3000
+ static auto erase_if(BtreeContainer &container, Pred pred) ->
3001
+ typename BtreeContainer::size_type {
3002
+ const auto initial_size = container.size();
3003
+ auto &tree = container.tree_;
3004
+ auto *alloc = tree.mutable_allocator();
3005
+ for (auto it = container.begin(); it != container.end();) {
3006
+ if (!pred(*it)) {
3007
+ ++it;
3008
+ continue;
3009
+ }
3010
+ auto *node = it.node_;
3011
+ if (node->is_internal()) {
3012
+ // Handle internal nodes normally.
3013
+ it = container.erase(it);
3014
+ continue;
3015
+ }
3016
+ // If this is a leaf node, then we do all the erases from this node
3017
+ // at once before doing rebalancing.
3018
+
3019
+ // The current position to transfer slots to.
3020
+ int to_pos = it.position_;
3021
+ node->value_destroy(it.position_, alloc);
3022
+ while (++it.position_ < node->finish()) {
3023
+ it.update_generation();
3024
+ if (pred(*it)) {
3025
+ node->value_destroy(it.position_, alloc);
3026
+ } else {
3027
+ node->transfer(node->slot(to_pos++), node->slot(it.position_), alloc);
3028
+ }
3029
+ }
3030
+ const int num_deleted = node->finish() - to_pos;
3031
+ tree.size_ -= num_deleted;
3032
+ node->set_finish(to_pos);
3033
+ it.position_ = to_pos;
3034
+ it = tree.rebalance_after_delete(it);
3035
+ }
3036
+ return initial_size - container.size();
3037
+ }
3038
+ };
3039
+
3040
+ #undef ABSL_BTREE_ENABLE_GENERATIONS
3041
+
3042
+ } // namespace container_internal
3043
+ ABSL_NAMESPACE_END
3044
+ } // namespace absl
3045
+
3046
+ #endif // ABSL_CONTAINER_INTERNAL_BTREE_H_