datasketches 0.5.2 → 0.5.3

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 (115) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/ext/datasketches/theta_wrapper.cpp +1 -1
  4. data/lib/datasketches/version.rb +1 -1
  5. data/vendor/datasketches-cpp/CMakeLists.txt +5 -3
  6. data/vendor/datasketches-cpp/CODE_OF_CONDUCT.md +1 -1
  7. data/vendor/datasketches-cpp/LICENSE +14 -0
  8. data/vendor/datasketches-cpp/README.md +67 -73
  9. data/vendor/datasketches-cpp/benchmarks/CMakeLists.txt +52 -0
  10. data/vendor/datasketches-cpp/benchmarks/benchmark_count_min_sketch.cpp +153 -0
  11. data/vendor/datasketches-cpp/benchmarks/benchmark_count_min_sketch_serialization.cpp +161 -0
  12. data/vendor/datasketches-cpp/common/CMakeLists.txt +1 -0
  13. data/vendor/datasketches-cpp/common/include/binomial_bounds.hpp +2 -2
  14. data/vendor/datasketches-cpp/common/include/fdlibm_log.hpp +101 -0
  15. data/vendor/datasketches-cpp/common/include/serde.hpp +6 -0
  16. data/vendor/datasketches-cpp/common/test/CMakeLists.txt +44 -2
  17. data/vendor/datasketches-cpp/common/test/binomial_bounds_test.cpp +279 -0
  18. data/vendor/datasketches-cpp/common/test/deserialize_hardening_test.cpp +188 -0
  19. data/vendor/datasketches-cpp/count/include/count_min.hpp +17 -4
  20. data/vendor/datasketches-cpp/count/include/count_min_impl.hpp +65 -83
  21. data/vendor/datasketches-cpp/count/test/count_min_test.cpp +63 -7
  22. data/vendor/datasketches-cpp/cpc/include/compression_data.hpp +2 -0
  23. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +16 -7
  24. data/vendor/datasketches-cpp/cpc/include/cpc_sketch.hpp +1 -0
  25. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +54 -36
  26. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +27 -27
  27. data/vendor/datasketches-cpp/cpc/include/cpc_util.hpp +7 -7
  28. data/vendor/datasketches-cpp/cpc/include/icon_estimator.hpp +5 -5
  29. data/vendor/datasketches-cpp/cpc/include/u32_table_impl.hpp +16 -16
  30. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +35 -0
  31. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +28 -3
  32. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +41 -25
  33. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map.hpp +3 -1
  34. data/vendor/datasketches-cpp/fi/include/reverse_purge_hash_map_impl.hpp +10 -5
  35. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_serialize_for_java.cpp +24 -0
  36. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +116 -0
  37. data/vendor/datasketches-cpp/filters/include/bloom_filter.hpp +1 -1
  38. data/vendor/datasketches-cpp/filters/include/bloom_filter_impl.hpp +32 -12
  39. data/vendor/datasketches-cpp/filters/test/bloom_filter_test.cpp +28 -1
  40. data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +1 -2
  41. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +19 -5
  42. data/vendor/datasketches-cpp/hll/include/CubicInterpolation-internal.hpp +4 -4
  43. data/vendor/datasketches-cpp/hll/include/HarmonicNumbers-internal.hpp +2 -1
  44. data/vendor/datasketches-cpp/hll/include/Hll4Array-internal.hpp +4 -4
  45. data/vendor/datasketches-cpp/hll/include/Hll4Array.hpp +1 -1
  46. data/vendor/datasketches-cpp/hll/include/Hll6Array-internal.hpp +3 -3
  47. data/vendor/datasketches-cpp/hll/include/Hll6Array.hpp +1 -1
  48. data/vendor/datasketches-cpp/hll/include/Hll8Array-internal.hpp +6 -3
  49. data/vendor/datasketches-cpp/hll/include/Hll8Array.hpp +1 -1
  50. data/vendor/datasketches-cpp/hll/include/HllArray-internal.hpp +35 -29
  51. data/vendor/datasketches-cpp/hll/include/HllArray.hpp +1 -1
  52. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +3 -5
  53. data/vendor/datasketches-cpp/hll/include/HllSketchImpl-internal.hpp +5 -11
  54. data/vendor/datasketches-cpp/hll/include/HllSketchImpl.hpp +2 -4
  55. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +11 -10
  56. data/vendor/datasketches-cpp/hll/include/HllUnion-internal.hpp +17 -8
  57. data/vendor/datasketches-cpp/hll/include/HllUtil.hpp +12 -3
  58. data/vendor/datasketches-cpp/hll/include/coupon_iterator-internal.hpp +2 -2
  59. data/vendor/datasketches-cpp/hll/include/coupon_iterator.hpp +3 -0
  60. data/vendor/datasketches-cpp/hll/include/hll.hpp +11 -4
  61. data/vendor/datasketches-cpp/hll/include/hll.private.hpp +19 -0
  62. data/vendor/datasketches-cpp/hll/test/CMakeLists.txt +2 -0
  63. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +64 -0
  64. data/vendor/datasketches-cpp/hll/test/HllFullSizeTest.cpp +137 -0
  65. data/vendor/datasketches-cpp/hll/test/HllKxqRebuildTest.cpp +150 -0
  66. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +3 -3
  67. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +71 -1
  68. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +10 -10
  69. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +10 -1
  70. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +33 -24
  71. data/vendor/datasketches-cpp/kll/test/kll_sketch_deserialize_from_java_test.cpp +24 -0
  72. data/vendor/datasketches-cpp/kll/test/kll_sketch_serialize_for_java.cpp +10 -0
  73. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +11 -2
  74. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +24 -15
  75. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +9 -0
  76. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +24 -15
  77. data/vendor/datasketches-cpp/req/test/req_sketch_deserialize_from_java_test.cpp +46 -0
  78. data/vendor/datasketches-cpp/req/test/req_sketch_serialize_for_java.cpp +20 -0
  79. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +70 -0
  80. data/vendor/datasketches-cpp/sampling/include/ebpps_sample_impl.hpp +17 -8
  81. data/vendor/datasketches-cpp/sampling/include/ebpps_sketch.hpp +13 -0
  82. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +10 -1
  83. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +6 -7
  84. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +5 -1
  85. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +2 -1
  86. data/vendor/datasketches-cpp/sampling/test/ebpps_allocation_test.cpp +1 -1
  87. data/vendor/datasketches-cpp/sampling/test/ebpps_sketch_test.cpp +2 -2
  88. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +1 -1
  89. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +10 -4
  90. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +12 -0
  91. data/vendor/datasketches-cpp/tdigest/include/tdigest.hpp +38 -2
  92. data/vendor/datasketches-cpp/tdigest/include/tdigest_impl.hpp +168 -9
  93. data/vendor/datasketches-cpp/tdigest/test/CMakeLists.txt +1 -0
  94. data/vendor/datasketches-cpp/tdigest/test/tdigest_iterator_test.cpp +274 -0
  95. data/vendor/datasketches-cpp/tdigest/test/tdigest_test.cpp +275 -0
  96. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser.hpp +2 -0
  97. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +24 -3
  98. data/vendor/datasketches-cpp/theta/include/theta_constants.hpp +4 -2
  99. data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +32 -0
  100. data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +4 -2
  101. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +22 -4
  102. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +60 -38
  103. data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +2 -6
  104. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +2 -2
  105. data/vendor/datasketches-cpp/theta/test/bit_packing_test.cpp +50 -0
  106. data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +22 -0
  107. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +315 -0
  108. data/vendor/datasketches-cpp/tools/rat-check.sh +68 -0
  109. data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch.hpp +35 -4
  110. data/vendor/datasketches-cpp/tuple/include/array_tuple_sketch_impl.hpp +2 -2
  111. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +41 -0
  112. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +5 -4
  113. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +59 -0
  114. data/vendor/datasketches-cpp/version.cfg.in +1 -1
  115. metadata +12 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eadeb269a420be62fa48fbdc950bd5583cdfd1d74776b3e627be852f2551af89
4
- data.tar.gz: 422aee84c37c94267c9e6222145eb0bad0f0530e6917faba42a8ef17f1079b69
3
+ metadata.gz: 6a91d4d694972af601b74f32fdec1d52fb48d6bf9ee0c16332219d3755afd4c6
4
+ data.tar.gz: 5ca86cc02447be6af32c4eb1368fb93641cca227781a4e7827f2b1d3d43532bc
5
5
  SHA512:
6
- metadata.gz: de095d22fac5e124d9927178961aaf0c375e43020ffe23f448ae16f57b48725aea254076755c518588036ebfe66197ff31170e4ac08365b2d1608cc440a144af
7
- data.tar.gz: 7f6dda2ab6190c1aa6527951406db4c57d58d2d8205bd5a13c61d50c2d0ed8c903a69d4dc2ccb805ba47d2b04c1cacc691dacef07f5c0228d83d5572e6fe805e
6
+ metadata.gz: aaafc9cff65cd3827524ee7ae9d32076471adaaf8c17924121c1ca8f303cc76beafbf3fbaae4dea31895f31265b1a522795b3e6905a8275ba1eb3ae329032153
7
+ data.tar.gz: 07ffe0606651871f0b10f4b31d383ef78db3c1fe2ae83021686e3ed835bb6f7437554ffe342f68f703bae799dae3176f391a0d3e642b42a620f160c079d5579d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.5.3 (2026-10-07)
2
+
3
+ - Updated DataSketches to 5.3.0
4
+
1
5
  ## 0.5.2 (2026-04-06)
2
6
 
3
7
  - Improved installation time
@@ -57,7 +57,7 @@ void init_theta(Rice::Module& m) {
57
57
  return builder.build();
58
58
  },
59
59
  Rice::Arg("lg_k")=datasketches::theta_constants::DEFAULT_LG_K, Rice::Arg("p")=1.0, Rice::Arg("seed")=DEFAULT_SEED)
60
- .define_method("compact", &update_theta_sketch::compact, Rice::Arg("ordered")=true)
60
+ .define_method("compact", &update_theta_sketch::compact, Rice::Arg("ordered")=true, Rice::Arg("trim")=false)
61
61
  .define_method(
62
62
  "update",
63
63
  [](update_theta_sketch& self, Rice::Object datum) {
@@ -1,3 +1,3 @@
1
1
  module DataSketches
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
@@ -59,7 +59,7 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_VERSION VERS
59
59
  add_compile_options(-Wimplicit-fallthrough=3)
60
60
  endif()
61
61
 
62
- # Code generation options, to ensure shaerd libraries work and are portable
62
+ # Code generation options, to ensure shared libraries work and are portable
63
63
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
64
64
  set(CMAKE_C_EXTENSIONS OFF)
65
65
  set(CMAKE_CXX_EXTENSIONS OFF)
@@ -74,6 +74,8 @@ if (BUILD_TESTS)
74
74
  enable_testing()
75
75
  endif()
76
76
 
77
+ option(BUILD_BENCHMARKS "Build benchmarks" OFF)
78
+
77
79
  option(COVERAGE "Enable code coverage reporting (g++/clang only)" OFF)
78
80
  if(COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
79
81
  set(CMAKE_BUILD_TYPE "Debug" FORCE)
@@ -121,8 +123,8 @@ add_subdirectory(density)
121
123
  add_subdirectory(tdigest)
122
124
  add_subdirectory(filters)
123
125
 
124
- if (WITH_PYTHON)
125
- add_subdirectory(python)
126
+ if (BUILD_BENCHMARKS)
127
+ add_subdirectory(benchmarks)
126
128
  endif()
127
129
 
128
130
  target_link_libraries(datasketches INTERFACE hll cpc kll fi theta sampling req quantiles count)
@@ -1,3 +1,3 @@
1
1
  # Code of Conduct
2
2
 
3
- We adhere to the Apache Softare Foundation's [Code of Conduct](https://www.apache.org/foundation/policies/conduct).
3
+ We adhere to the Apache Software Foundation's [Code of Conduct](https://www.apache.org/foundation/policies/conduct).
@@ -296,3 +296,17 @@ APPENDIX B: Additional licenses relevant to this product.
296
296
  Code Locations:
297
297
  * common/include/ceiling_power_of_2.hpp
298
298
  that is adapted from the above.
299
+
300
+ =============================================================
301
+ FDLIBM
302
+ =============================================================
303
+ Original source code:
304
+ Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
305
+ Developed at SunSoft, a Sun Microsystems, Inc. business.
306
+
307
+ Permission to use, copy, modify, and distribute this software is freely
308
+ granted, provided that this notice is preserved.
309
+
310
+ Code Locations:
311
+ common/include/fdlibm_log.hpp
312
+ that is adapted from __ieee754_log in FDLIBM 5.3.
@@ -1,106 +1,100 @@
1
1
  # Apache DataSketches Core C++ Library Component
2
- This is the core C++ component of the Apache DataSketches library. It contains all of the key sketching algorithms that are in the Java component and can be accessed directly from user applications.
3
2
 
4
- This component is also a dependency of other components of the library that create adaptors for target systems, such as PostgreSQL.
3
+ This is the core C++ component of the Apache DataSketches library. It contains all the key sketching algorithms from the Java implementation and can be accessed directly by user applications.
5
4
 
6
- Note that we have a parallel core component for [Java]((https://github.com/apache/datasketches-java) and [Python]((https://github.com/apache/datasketches-python) implementations of the same sketch algorithms.
5
+ This component is also a dependency of other library components that create adaptors for target systems, such as [PostgreSQL](https://github.com/apache/datasketches-postgresql).
6
+
7
+ Note that we have parallel core library components for Java, Python, GO, and Rust implementations of many of the same sketch algorithms:
8
+
9
+ - [datasketches-java](https://github.com/apache/datasketches-java)
10
+ - [datasketches-python](https://github.com/apache/datasketches-python)
11
+ - [datasketches-go](https://github.com/apache/datasketches-go)
12
+ - [datasketches-rust](https://github.com/apache/datasketches-rust)
7
13
 
8
14
  Please visit the main [Apache DataSketches website](https://datasketches.apache.org) for more information.
9
15
 
10
- If you are interested in making contributions to this site please see our [Community](https://datasketches.apache.org/docs/Community/) page for how to contact us.
16
+ If you are interested in making contributions to this site, please see our [Community](https://datasketches.apache.org/docs/Community/) page for how to contact us.
11
17
 
12
18
  ---
13
19
 
14
20
  This code requires C++11.
15
21
 
16
- This library is header-only. The build process provided is only for building unit tests.
22
+ This library is header-only. The provided build process is only for unit tests.
17
23
 
18
- Building the unit tests requires cmake 3.12.0 or higher.
24
+ Building the unit tests requires CMake 3.12.0 or higher.
19
25
 
20
- Installing the latest cmake on OSX: brew install cmake
26
+ Installing the latest CMake on OSX: `brew install cmake`.
21
27
 
22
- Building and running unit tests using cmake for OSX and Linux:
28
+ Building and running unit tests using CMake for OSX and Linux:
23
29
 
24
- ```
25
- $ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release
26
- $ cmake --build build/Release -t all test
30
+ ```shell
31
+ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release
32
+ cmake --build build/Release -t all test
27
33
  ```
28
34
 
29
- Building and running unit tests using cmake for Windows from the command line:
35
+ Building and running unit tests using CMake for Windows from the command line:
30
36
 
31
- ```
32
- $ cd build
33
- $ cmake ..
34
- $ cd ..
35
- $ cmake --build build --config Release
36
- $ cmake --build build --config Release --target RUN_TESTS
37
+ ```shell
38
+ cd build
39
+ cmake ..
40
+ cd ..
41
+ cmake --build build --config Release
42
+ cmake --build build --config Release --target RUN_TESTS
37
43
  ```
38
44
 
39
- To install a local distribution (OSX and Linux), use the following command. The
40
- CMAKE_INSTALL_PREFIX variable controls the destination. If not specified, it
41
- defaults to installing in /usr (/usr/include, /usr/lib, etc). In the command below,
42
- the installation will be in /tmp/install/DataSketches (/tmp/install/DataSketches/include,
43
- /tmp/install/DataSketches/lib, etc)
45
+ To install a local distribution (OSX and Linux), use the following command. The `CMAKE_INSTALL_PREFIX` variable controls the destination. If not specified, it defaults to installing in /usr (/usr/include, /usr/lib, etc). In the command below, the installation will be in /tmp/install/DataSketches (/tmp/install/DataSketches/include, /tmp/install/DataSketches/lib, etc).
44
46
 
45
- ```
46
- $ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install/DataSketches
47
- $ cmake --build build/Release -t install
47
+ ```shell
48
+ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install/DataSketches
49
+ cmake --build build/Release -t install
48
50
  ```
49
51
 
50
- To generate an installable package using cmake's built in cpack packaging tool,
51
- use the following command. The type of packaging is controlled by the CPACK_GENERATOR
52
- variable (semi-colon separated list). Cmake usually supports packaging types such as RPM,
53
- DEB, STGZ, TGZ, TZ, ZIP, etc.
52
+ To generate an installable package using CMake's built-in cpack packaging tool, use the following command. The type of packaging is controlled by the `CPACK_GENERATOR` variable (semi-colon separated list). CMake usually supports packaging formats such as RPM, DEB, STGZ, TGZ, TZ, and ZIP.
54
53
 
55
- ```
56
- $ cmake3 -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR="RPM;STGZ;TGZ"
57
- $ cmake3 --build build/Release -t package
54
+ ```shell
55
+ cmake -S . -B build/Release -DCMAKE_BUILD_TYPE=Release -DCPACK_GENERATOR="RPM;STGZ;TGZ"
56
+ cmake --build build/Release -t package
58
57
  ```
59
58
 
60
59
  The DataSketches project can be included in other projects' CMakeLists.txt files in one of two ways.
61
- If DataSketches has been installed on the host (using an RPM, DEB, "make install" into /usr/local, or some
62
- way, then CMake's `find_package` command can be used like this:
63
60
 
64
- ```
65
- find_package(DataSketches 3.2 REQUIRED)
66
- target_link_library(my_dependent_target PUBLIC ${DATASKETCHES_LIB})
61
+ If DataSketches has been installed on the host (using an RPM, DEB, "make install" into /usr/local, or some way, then CMake's `find_package` command can be used like this:
62
+
63
+ ```cmake
64
+ find_package(DataSketches 3.2 REQUIRED)
65
+ target_link_library(my_dependent_target PUBLIC ${DATASKETCHES_LIB})
67
66
  ```
68
67
 
69
68
  When used with find_package, DataSketches exports several variables, including
70
69
 
71
- - `DATASKETCHES_VERSION`: The version number of the datasketches package that was imported.
72
- - `DATASKETCHES_INCLUDE_DIR`: The directory that should be added to access DataSketches include files.
73
- Because cmake automatically includes the interface directories for included target libraries when
74
- using `target_link_library`, under normal circumstances there will be no need to include this directly.
75
- - `DATASKETCHES_LIB`: The name of the DataSketches target to include as a dependency. Projects pulling
76
- in DataSketches should reference this with `target_link_library` in order to set up all the correct dependencies
77
- and include paths.
78
-
79
- If you don't have DataSketches installed locally, dependent projects can pull it directly
80
- from GitHub using CMake's `ExternalProject` module. The code would look something like this:
81
-
82
- ```
83
- cmake_policy(SET CMP0097 NEW)
84
- include(ExternalProject)
85
- ExternalProject_Add(datasketches
86
- GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
87
- GIT_TAG 3.2.0
88
- GIT_SHALLOW true
89
- GIT_SUBMODULES ""
90
- INSTALL_DIR /tmp/datasketches-prefix
91
- CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches-prefix
92
-
93
- # Override the install command to add DESTDIR
94
- # This is necessary to work around an oddity in the RPM (but not other) package
95
- # generation, as CMake otherwise picks up the Datasketch files when building
96
- # an RPM for a dependent package. (RPM scans the directory for files in addition to installing
97
- # those files referenced in an "install" rule in the cmake file)
98
- INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build . --target install
99
- )
100
- ExternalProject_Get_property(datasketches INSTALL_DIR)
101
- set(datasketches_INSTALL_DIR ${INSTALL_DIR})
102
- message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
103
- target_include_directories(my_dependent_target
104
- PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
105
- add_dependencies(my_dependent_target datasketches)
70
+ - `DATASKETCHES_VERSION`: The version number of the datasketches package that was imported.
71
+ - `DATASKETCHES_INCLUDE_DIR`: The directory that should be added to access DataSketches include files. Because CMake automatically includes the interface directories for included target libraries when using `target_link_library`, under normal circumstances, there will be no need to include this directly
72
+ - `DATASKETCHES_LIB`: The name of the DataSketches target to include as a dependency. Projects pulling in DataSketches should reference this with `target_link_library` in order to set up all the correct dependencies and include paths.
73
+
74
+ If you don't have DataSketches installed locally, dependent projects can pull it directly from GitHub using CMake's `ExternalProject` module. The code would look something like this:
75
+
76
+ ```cmake
77
+ cmake_policy(SET CMP0097 NEW)
78
+ include(ExternalProject)
79
+ ExternalProject_Add(datasketches
80
+ GIT_REPOSITORY https://github.com/apache/datasketches-cpp.git
81
+ GIT_TAG 3.2.0
82
+ GIT_SHALLOW true
83
+ GIT_SUBMODULES ""
84
+ INSTALL_DIR /tmp/datasketches-prefix
85
+ CMAKE_ARGS -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=/tmp/datasketches-prefix
86
+
87
+ # Override the install command to add DESTDIR
88
+ # This is necessary to work around an oddity in the RPM (but not other) package
89
+ # generation, as CMake otherwise picks up the Datasketch files when building
90
+ # an RPM for a dependent package. (RPM scans the directory for files in addition to installing
91
+ # those files referenced in an "install" rule in the cmake file)
92
+ INSTALL_COMMAND env DESTDIR= ${CMAKE_COMMAND} --build . --target install
93
+ )
94
+ ExternalProject_Get_property(datasketches INSTALL_DIR)
95
+ set(datasketches_INSTALL_DIR ${INSTALL_DIR})
96
+ message("Source dir of datasketches = ${datasketches_INSTALL_DIR}")
97
+ target_include_directories(my_dependent_target
98
+ PRIVATE ${datasketches_INSTALL_DIR}/include/DataSketches)
99
+ add_dependencies(my_dependent_target datasketches)
106
100
  ```
@@ -0,0 +1,52 @@
1
+ # Licensed to the Apache Software Foundation (ASF) under one
2
+ # or more contributor license agreements. See the NOTICE file
3
+ # distributed with this work for additional information
4
+ # regarding copyright ownership. The ASF licenses this file
5
+ # to you under the Apache License, Version 2.0 (the
6
+ # "License"); you may not use this file except in compliance
7
+ # with the License. You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing,
12
+ # software distributed under the License is distributed on an
13
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ # KIND, either express or implied. See the License for the
15
+ # specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ if (NOT TARGET benchmark::benchmark_main)
19
+ include(FetchContent)
20
+
21
+ set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable google-benchmark tests" FORCE)
22
+ set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "Disable google-benchmark gtest tests" FORCE)
23
+ set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable google-benchmark install rules" FORCE)
24
+ set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "Disable google-benchmark documentation install" FORCE)
25
+ set(BENCHMARK_ENABLE_WERROR OFF CACHE BOOL "Disable google-benchmark warnings as errors" FORCE)
26
+
27
+ FetchContent_Declare(
28
+ googlebenchmark
29
+ GIT_REPOSITORY https://github.com/google/benchmark.git
30
+ GIT_TAG v1.7.1
31
+ )
32
+
33
+ FetchContent_MakeAvailable(googlebenchmark)
34
+ endif()
35
+
36
+ add_executable(count_min_sketch_benchmark)
37
+
38
+ target_link_libraries(count_min_sketch_benchmark
39
+ PRIVATE
40
+ count
41
+ benchmark::benchmark_main
42
+ )
43
+
44
+ set_target_properties(count_min_sketch_benchmark PROPERTIES
45
+ CXX_STANDARD_REQUIRED YES
46
+ )
47
+
48
+ target_sources(count_min_sketch_benchmark
49
+ PRIVATE
50
+ benchmark_count_min_sketch.cpp
51
+ benchmark_count_min_sketch_serialization.cpp
52
+ )
@@ -0,0 +1,153 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ #include <benchmark/benchmark.h>
21
+ #include <count_min.hpp>
22
+
23
+ #include <cstddef>
24
+ #include <cstdint>
25
+ #include <string>
26
+ #include <vector>
27
+
28
+ namespace
29
+ {
30
+
31
+ using Sketch = datasketches::count_min_sketch<uint64_t>;
32
+
33
+ // Roughly 99.9% confidence and 0.1% relative error:
34
+ // suggest_num_hashes(0.999) == 7 and suggest_num_buckets(0.001) == 2719.
35
+ constexpr uint8_t NUM_HASHES = 7;
36
+ constexpr uint32_t NUM_BUCKETS = 2719;
37
+
38
+ std::vector<uint64_t> makeUInt64Keys(size_t size)
39
+ {
40
+ std::vector<uint64_t> keys;
41
+ keys.reserve(size);
42
+ for (size_t i = 0; i < size; ++i)
43
+ keys.push_back(static_cast<uint64_t>(i * 0x9e3779b97f4a7c15ULL));
44
+ return keys;
45
+ }
46
+
47
+ std::vector<std::string> makeStringKeys(size_t size)
48
+ {
49
+ std::vector<std::string> keys;
50
+ keys.reserve(size);
51
+ for (size_t i = 0; i < size; ++i)
52
+ keys.push_back("countmin-key-" + std::to_string(i * 2654435761ULL));
53
+ return keys;
54
+ }
55
+
56
+ int64_t totalStringBytes(const std::vector<std::string> & keys)
57
+ {
58
+ int64_t bytes = 0;
59
+ for (const auto & key : keys)
60
+ bytes += static_cast<int64_t>(key.size());
61
+ return bytes;
62
+ }
63
+
64
+ void BM_CountMinUpdateUInt64(benchmark::State & state)
65
+ {
66
+ const auto keys = makeUInt64Keys(static_cast<size_t>(state.range(0)));
67
+ for (auto _ : state)
68
+ {
69
+ state.PauseTiming();
70
+ Sketch sketch(NUM_HASHES, NUM_BUCKETS);
71
+ state.ResumeTiming();
72
+
73
+ for (const auto key : keys)
74
+ sketch.update(&key, sizeof(key), 1);
75
+
76
+ benchmark::ClobberMemory();
77
+ benchmark::DoNotOptimize(sketch.get_total_weight());
78
+ }
79
+
80
+ state.SetItemsProcessed(state.iterations() * static_cast<int64_t>(keys.size()));
81
+ state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(keys.size() * sizeof(uint64_t)));
82
+ }
83
+
84
+ void BM_CountMinUpdateStringBytes(benchmark::State & state)
85
+ {
86
+ const auto keys = makeStringKeys(static_cast<size_t>(state.range(0)));
87
+ const auto bytes_per_iteration = totalStringBytes(keys);
88
+
89
+ for (auto _ : state)
90
+ {
91
+ state.PauseTiming();
92
+ Sketch sketch(NUM_HASHES, NUM_BUCKETS);
93
+ state.ResumeTiming();
94
+
95
+ for (const auto & key : keys)
96
+ sketch.update(key.data(), key.size(), 1);
97
+
98
+ benchmark::ClobberMemory();
99
+ benchmark::DoNotOptimize(sketch.get_total_weight());
100
+ }
101
+
102
+ state.SetItemsProcessed(state.iterations() * static_cast<int64_t>(keys.size()));
103
+ state.SetBytesProcessed(state.iterations() * bytes_per_iteration);
104
+ }
105
+
106
+ void BM_CountMinEstimateUInt64(benchmark::State & state)
107
+ {
108
+ const auto keys = makeUInt64Keys(static_cast<size_t>(state.range(0)));
109
+ Sketch sketch(NUM_HASHES, NUM_BUCKETS);
110
+ for (const auto key : keys)
111
+ sketch.update(&key, sizeof(key), 1);
112
+
113
+ uint64_t sum = 0;
114
+ for (auto _ : state)
115
+ {
116
+ for (const auto key : keys)
117
+ sum += sketch.get_estimate(&key, sizeof(key));
118
+
119
+ benchmark::DoNotOptimize(sum);
120
+ }
121
+
122
+ state.SetItemsProcessed(state.iterations() * static_cast<int64_t>(keys.size()));
123
+ state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(keys.size() * sizeof(uint64_t)));
124
+ }
125
+
126
+ void BM_CountMinEstimateStringBytes(benchmark::State & state)
127
+ {
128
+ const auto keys = makeStringKeys(static_cast<size_t>(state.range(0)));
129
+ const auto bytes_per_iteration = totalStringBytes(keys);
130
+
131
+ Sketch sketch(NUM_HASHES, NUM_BUCKETS);
132
+ for (const auto & key : keys)
133
+ sketch.update(key.data(), key.size(), 1);
134
+
135
+ uint64_t sum = 0;
136
+ for (auto _ : state)
137
+ {
138
+ for (const auto & key : keys)
139
+ sum += sketch.get_estimate(key.data(), key.size());
140
+
141
+ benchmark::DoNotOptimize(sum);
142
+ }
143
+
144
+ state.SetItemsProcessed(state.iterations() * static_cast<int64_t>(keys.size()));
145
+ state.SetBytesProcessed(state.iterations() * bytes_per_iteration);
146
+ }
147
+
148
+ }
149
+
150
+ BENCHMARK(BM_CountMinUpdateUInt64)->RangeMultiplier(8)->Range(1024, 65536);
151
+ BENCHMARK(BM_CountMinUpdateStringBytes)->RangeMultiplier(8)->Range(1024, 65536);
152
+ BENCHMARK(BM_CountMinEstimateUInt64)->RangeMultiplier(8)->Range(1024, 65536);
153
+ BENCHMARK(BM_CountMinEstimateStringBytes)->RangeMultiplier(8)->Range(1024, 65536);
@@ -0,0 +1,161 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+
20
+ #include <benchmark/benchmark.h>
21
+ #include <count_min.hpp>
22
+
23
+ #include <algorithm>
24
+ #include <cstddef>
25
+ #include <cstdint>
26
+ #include <cstring>
27
+ #include <ostream>
28
+ #include <streambuf>
29
+ #include <vector>
30
+
31
+ namespace
32
+ {
33
+
34
+ using Sketch = datasketches::count_min_sketch<uint64_t>;
35
+
36
+ // Roughly 99.9% confidence. Serialization cost then scales with the bucket count.
37
+ constexpr uint8_t NUM_HASHES = 7;
38
+
39
+ Sketch makeSketch(uint32_t num_buckets)
40
+ {
41
+ Sketch sketch(NUM_HASHES, num_buckets);
42
+ for (uint64_t i = 0; i < NUM_HASHES; ++i)
43
+ sketch.update(i, i + 1);
44
+ return sketch;
45
+ }
46
+
47
+ class fixed_buffer_streambuf final: public std::streambuf
48
+ {
49
+ public:
50
+ explicit fixed_buffer_streambuf(std::vector<uint8_t>& buffer): buffer_(buffer), position_(0) {}
51
+
52
+ void reset()
53
+ {
54
+ position_ = 0;
55
+ }
56
+
57
+ size_t bytes_written() const
58
+ {
59
+ return position_;
60
+ }
61
+
62
+ protected:
63
+ std::streamsize xsputn(const char* data, std::streamsize size) override
64
+ {
65
+ const size_t requested = static_cast<size_t>(size);
66
+ const size_t available = buffer_.size() - position_;
67
+ const size_t bytes_to_write = std::min(requested, available);
68
+ if (bytes_to_write > 0) {
69
+ std::memcpy(buffer_.data() + position_, data, bytes_to_write);
70
+ position_ += bytes_to_write;
71
+ }
72
+ return static_cast<std::streamsize>(bytes_to_write);
73
+ }
74
+
75
+ int_type overflow(int_type ch) override
76
+ {
77
+ if (traits_type::eq_int_type(ch, traits_type::eof()))
78
+ return traits_type::not_eof(ch);
79
+ if (position_ == buffer_.size())
80
+ return traits_type::eof();
81
+ buffer_[position_++] = static_cast<uint8_t>(traits_type::to_char_type(ch));
82
+ return ch;
83
+ }
84
+
85
+ private:
86
+ std::vector<uint8_t>& buffer_;
87
+ size_t position_;
88
+ };
89
+
90
+ void BM_CountMinGetSerializedSizeBytes(benchmark::State& state)
91
+ {
92
+ const auto sketch = makeSketch(static_cast<uint32_t>(state.range(0)));
93
+
94
+ for (auto _ : state) {
95
+ const auto size = sketch.get_serialized_size_bytes();
96
+ benchmark::DoNotOptimize(size);
97
+ }
98
+
99
+ state.SetItemsProcessed(state.iterations());
100
+ }
101
+
102
+ void BM_CountMinSerializeVector(benchmark::State& state)
103
+ {
104
+ const auto sketch = makeSketch(static_cast<uint32_t>(state.range(0)));
105
+ const auto serialized_size = sketch.get_serialized_size_bytes();
106
+
107
+ for (auto _ : state) {
108
+ auto bytes = sketch.serialize();
109
+ benchmark::DoNotOptimize(bytes.data());
110
+ benchmark::DoNotOptimize(bytes.size());
111
+ benchmark::ClobberMemory();
112
+ }
113
+
114
+ state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(serialized_size));
115
+ }
116
+
117
+ void BM_CountMinSerializeOStream(benchmark::State& state)
118
+ {
119
+ const auto sketch = makeSketch(static_cast<uint32_t>(state.range(0)));
120
+ const auto serialized_size = sketch.get_serialized_size_bytes();
121
+ std::vector<uint8_t> bytes(serialized_size);
122
+ fixed_buffer_streambuf stream_buffer(bytes);
123
+ std::ostream os(&stream_buffer);
124
+
125
+ for (auto _ : state) {
126
+ stream_buffer.reset();
127
+ os.clear();
128
+ sketch.serialize(os);
129
+ benchmark::DoNotOptimize(stream_buffer.bytes_written());
130
+ benchmark::ClobberMemory();
131
+ }
132
+
133
+ state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(serialized_size));
134
+ }
135
+
136
+ void BM_CountMinSerializeToSink(benchmark::State& state)
137
+ {
138
+ const auto sketch = makeSketch(static_cast<uint32_t>(state.range(0)));
139
+ const auto serialized_size = sketch.get_serialized_size_bytes();
140
+ std::vector<uint8_t> bytes(serialized_size);
141
+
142
+ for (auto _ : state) {
143
+ uint8_t* ptr = bytes.data();
144
+ const auto bytes_written = sketch.serialize_to([&ptr](const void* data, size_t size) {
145
+ std::memcpy(ptr, data, size);
146
+ ptr += size;
147
+ });
148
+ benchmark::DoNotOptimize(ptr);
149
+ benchmark::DoNotOptimize(bytes_written);
150
+ benchmark::ClobberMemory();
151
+ }
152
+
153
+ state.SetBytesProcessed(state.iterations() * static_cast<int64_t>(serialized_size));
154
+ }
155
+
156
+ }
157
+
158
+ BENCHMARK(BM_CountMinGetSerializedSizeBytes)->RangeMultiplier(8)->Range(1024, 65536);
159
+ BENCHMARK(BM_CountMinSerializeVector)->RangeMultiplier(8)->Range(1024, 65536);
160
+ BENCHMARK(BM_CountMinSerializeOStream)->RangeMultiplier(8)->Range(1024, 65536);
161
+ BENCHMARK(BM_CountMinSerializeToSink)->RangeMultiplier(8)->Range(1024, 65536);
@@ -40,6 +40,7 @@ install(FILES
40
40
  include/conditional_back_inserter.hpp
41
41
  include/conditional_forward.hpp
42
42
  include/count_zeros.hpp
43
+ include/fdlibm_log.hpp
43
44
  include/inv_pow2_table.hpp
44
45
  include/kolmogorov_smirnov_impl.hpp
45
46
  include/kolmogorov_smirnov.hpp
@@ -441,8 +441,8 @@ private:
441
441
  }
442
442
 
443
443
  static void check_theta(double theta) {
444
- if (theta < 0 || theta > 1) {
445
- throw std::invalid_argument("theta must be in [0, 1]");
444
+ if (theta <= 0 || theta > 1) {
445
+ throw std::invalid_argument("theta must be in (0, 1]");
446
446
  }
447
447
  }
448
448