Skip to content

Commit 7599e36

Browse files
derekmaurocopybara-github
authored andcommitted
Add absl::chunked_queue
This change introduces absl::chunked_queue, a sequence container optimized for use as a FIFO (First-In, First-Out) queue. It is similar in purpose to std::deque but with different performance trade-offs and features. absl::chunked_queue stores elements in a series of exponentially-growing chunks of memory. absl::chunked_queue is often a better choice than std::deque in the following situations: * Large queues: For very large numbers of elements, the exponential growth strategy of absl::chunked_queue can lead to fewer, larger memory allocations compared to std::deque, which can be a performance advantage. * Strict FIFO processing: When you only need to add elements to the back (push_back) and remove them from the front (pop_front). std::deque should be preferred in the following cases: * Operations at both ends: std::deque is designed for efficient insertions and deletions at both the front and the back. absl::chunked_queue is optimized for push_back and pop_front and does not offer a pop_back method. * Random access: std::deque provides amortized O(1) random access to elements via operator[]. absl::chunked_queue does not support random access. PiperOrigin-RevId: 850999629 Change-Id: Ie71737c10b6125b9e498109267cac87a4ca2f9e8
1 parent 60b607b commit 7599e36

File tree

7 files changed

+2162
-0
lines changed

7 files changed

+2162
-0
lines changed

CMake/AbseilDll.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ set(ABSL_INTERNAL_DLL_FILES
6969
"cleanup/internal/cleanup.h"
7070
"container/btree_map.h"
7171
"container/btree_set.h"
72+
"container/chunked_queue.h"
7273
"container/hash_container_defaults.h"
7374
"container/fixed_array.h"
7475
"container/flat_hash_map.h"
7576
"container/flat_hash_set.h"
7677
"container/inlined_vector.h"
7778
"container/internal/btree.h"
7879
"container/internal/btree_container.h"
80+
"container/internal/chunked_queue.h"
7981
"container/internal/common.h"
8082
"container/internal/common_policy_traits.h"
8183
"container/internal/compressed_tuple.h"

absl/container/BUILD.bazel

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,3 +1349,46 @@ cc_binary(
13491349
"@google_benchmark//:benchmark_main",
13501350
],
13511351
)
1352+
1353+
cc_library(
1354+
name = "chunked_queue",
1355+
srcs = ["internal/chunked_queue.h"],
1356+
hdrs = ["chunked_queue.h"],
1357+
deps = [
1358+
":layout",
1359+
"//absl/base:config",
1360+
"//absl/base:core_headers",
1361+
"//absl/base:iterator_traits_internal",
1362+
],
1363+
)
1364+
1365+
cc_test(
1366+
name = "chunked_queue_test",
1367+
size = "small",
1368+
srcs = ["chunked_queue_test.cc"],
1369+
deps = [
1370+
":chunked_queue",
1371+
":test_allocator",
1372+
"//absl/base:core_headers",
1373+
"//absl/strings",
1374+
"@googletest//:gtest",
1375+
"@googletest//:gtest_main",
1376+
],
1377+
)
1378+
1379+
cc_binary(
1380+
name = "chunked_queue_benchmark",
1381+
testonly = True,
1382+
srcs = ["chunked_queue_benchmark.cc"],
1383+
copts = ABSL_TEST_COPTS,
1384+
linkopts = ABSL_DEFAULT_LINKOPTS,
1385+
tags = ["benchmark"],
1386+
visibility = ["//visibility:private"],
1387+
deps = [
1388+
":chunked_queue",
1389+
"//absl/random",
1390+
"//absl/status",
1391+
"//absl/strings:cord",
1392+
"@google_benchmark//:benchmark_main",
1393+
],
1394+
)

absl/container/CMakeLists.txt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,3 +1202,38 @@ absl_cc_test(
12021202
absl::unordered_set_modifiers_test
12031203
GTest::gmock_main
12041204
)
1205+
1206+
absl_cc_library(
1207+
NAME
1208+
chunked_queue
1209+
HDRS
1210+
"chunked_queue.h"
1211+
"internal/chunked_queue.h"
1212+
COPTS
1213+
${ABSL_DEFAULT_COPTS}
1214+
LINKOPTS
1215+
${ABSL_DEFAULT_LINKOPTS}
1216+
DEPS
1217+
absl::config
1218+
absl::core_headers
1219+
absl::iterator_traits_internal
1220+
absl::layout
1221+
)
1222+
1223+
absl_cc_test(
1224+
NAME
1225+
chunked_queue_test
1226+
SRCS
1227+
"chunked_queue_test.cc"
1228+
COPTS
1229+
${ABSL_TEST_COPTS}
1230+
LINKOPTS
1231+
${ABSL_DEFAULT_LINKOPTS}
1232+
DEPS
1233+
absl::chunked_queue
1234+
absl::config
1235+
absl::core_headers
1236+
absl::strings
1237+
absl::test_allocator
1238+
GTest::gmock_main
1239+
)

0 commit comments

Comments
 (0)