From 27af4c3edce727fefb1167a1b294607beb96adc7 Mon Sep 17 00:00:00 2001 From: bogzbonny Date: Thu, 15 May 2025 16:02:48 -0700 Subject: [PATCH 1/3] cargo update --- Cargo.lock | 330 ++++++++++++++++++++++++----------------------------- 1 file changed, 151 insertions(+), 179 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 698dfc6..11c80ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,67 +1,68 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] -name = "adler" -version = "1.0.2" +name = "adler2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" [[package]] name = "anstyle-parse" -version = "0.2.2" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" dependencies = [ - "windows-sys 0.48.0", + "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" dependencies = [ "anstyle", - "windows-sys 0.48.0", + "once_cell", + "windows-sys", ] [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] name = "az" @@ -71,15 +72,9 @@ checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" [[package]] name = "base64" -version = "0.21.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" - -[[package]] -name = "bitflags" -version = "2.4.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "byteorder" @@ -95,18 +90,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.3.24" +version = "4.5.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487" +checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.3.24" +version = "4.5.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e" +checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" dependencies = [ "anstream", "anstyle", @@ -116,59 +111,45 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-channel" -version = "0.5.8" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" dependencies = [ - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "errno" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "flate2" -version = "1.0.28" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" dependencies = [ "crc32fast", "miniz_oxide", @@ -176,9 +157,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", @@ -187,12 +168,12 @@ dependencies = [ [[package]] name = "gmp-mpfr-sys" -version = "1.6.1" +version = "1.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19c5c67d8c29fe87e3266e691dd60948e6e4df4496c53355ef3551142945721b" +checksum = "c66d61197a68f6323b9afa616cf83d55d69191e1bf364d4eb7d35ae18defe776" dependencies = [ "libc", - "windows-sys 0.42.0", + "windows-sys", ] [[package]] @@ -211,12 +192,6 @@ dependencies = [ "rug", ] -[[package]] -name = "hermit-abi" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" - [[package]] name = "ieee754" version = "0.2.6" @@ -224,33 +199,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9007da9cacbd3e6343da136e98b0d2df013f553d35bdec8b518f07bea768e19c" [[package]] -name = "is-terminal" -version = "0.4.9" +name = "is_terminal_polyfill" +version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" -dependencies = [ - "hermit-abi", - "rustix", - "windows-sys 0.48.0", -] +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] -name = "linux-raw-sys" -version = "0.4.11" +name = "libm" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "minimal-lexical" @@ -260,11 +230,11 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a" dependencies = [ - "adler", + "adler2", ] [[package]] @@ -279,18 +249,45 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] [[package]] name = "rand" @@ -324,39 +321,44 @@ dependencies = [ [[package]] name = "rug" -version = "1.22.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a118f8296241f6952511e8f9ab5b8a759c0d9ed902159b0aeed82d902e84ca6" +checksum = "4207e8d668e5b8eb574bda8322088ccd0d7782d3d03c7e8d562e82ed82bdcbc3" dependencies = [ "az", "gmp-mpfr-sys", "libc", + "libm", ] [[package]] -name = "rustix" -version = "0.38.21" +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.48.0", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "strsim" -version = "0.10.0" +name = "unicode-ident" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "wasi" @@ -366,123 +368,93 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] -name = "windows_i686_msvc" -version = "0.42.2" +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.48.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" +name = "windows_x86_64_msvc" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" +name = "zerocopy" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" +name = "zerocopy-derive" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] From 6576559c8e5c1652d42fe72537bc83b750184ae9 Mon Sep 17 00:00:00 2001 From: bogzbonny Date: Thu, 15 May 2025 16:18:30 -0700 Subject: [PATCH 2/3] clippy fixes --- benches/interval_log.rs | 4 +- benches/record.rs | 28 ++--- benches/serialization.rs | 24 ++--- examples/cli.rs | 4 +- src/errors/mod.rs | 4 +- src/lib.rs | 40 +++---- src/serialization/benchmarks.rs | 12 +-- src/serialization/deserializer.rs | 4 +- src/serialization/interval_log/mod.rs | 28 ++--- src/serialization/interval_log/tests.rs | 6 +- src/serialization/mod.rs | 8 +- src/serialization/rand_varint.rs | 6 +- src/serialization/tests.rs | 53 +++++---- src/serialization/v2_serializer.rs | 6 +- src/tests/index_calculation.rs | 18 ++-- src/tests/init.rs | 30 +++--- src/tests/subtract.rs | 68 ++++++------ src/tests/tests.rs | 2 +- src/tests/value_calculation.rs | 42 ++++---- tests/auto_resize.rs | 2 +- tests/data_access.rs | 16 +-- tests/histogram.rs | 138 ++++++++++++------------ tests/interval_log.rs | 14 +-- tests/iterators.rs | 36 +++---- tests/quantile.rs | 28 ++--- tests/serialization.rs | 15 ++- 26 files changed, 316 insertions(+), 320 deletions(-) diff --git a/benches/interval_log.rs b/benches/interval_log.rs index 51a9fb0..9bd910a 100644 --- a/benches/interval_log.rs +++ b/benches/interval_log.rs @@ -22,7 +22,7 @@ fn write_interval_log_1k_hist_10k_value(b: &mut Bencher) { let mut rng = rand::rngs::SmallRng::from_entropy(); for _ in 0..1000 { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for v in RandomVarintEncodedLengthIter::new(&mut rng).take(10_000) { h.record(v).unwrap(); @@ -56,7 +56,7 @@ fn parse_interval_log_1k_hist_10k_value(b: &mut Bencher) { let mut rng = rand::rngs::SmallRng::from_entropy(); for _ in 0..1000 { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for v in RandomVarintEncodedLengthIter::new(&mut rng).take(10_000) { h.record(v).unwrap(); diff --git a/benches/record.rs b/benches/record.rs index 9110842..b6c0dec 100644 --- a/benches/record.rs +++ b/benches/record.rs @@ -13,7 +13,7 @@ mod rand_varint; #[bench] fn record_precalc_random_values_with_1_count_u64(b: &mut Bencher) { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut indices = Vec::::new(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -34,7 +34,7 @@ fn record_precalc_random_values_with_1_count_u64(b: &mut Bencher) { #[bench] fn record_precalc_random_values_with_max_count_u64(b: &mut Bencher) { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut indices = Vec::::new(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -42,7 +42,7 @@ fn record_precalc_random_values_with_max_count_u64(b: &mut Bencher) { for v in RandomVarintEncodedLengthIter::new(&mut rng).take(1_000_000) { indices.push(v); - h.record_n(v, u64::max_value()).unwrap(); + h.record_n(v, u64::MAX).unwrap(); } b.iter(|| { @@ -55,7 +55,7 @@ fn record_precalc_random_values_with_max_count_u64(b: &mut Bencher) { #[bench] fn record_correct_precalc_random_values_with_1_count_u64(b: &mut Bencher) { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut indices = Vec::::new(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -73,7 +73,7 @@ fn record_correct_precalc_random_values_with_1_count_u64(b: &mut Bencher) { #[bench] fn record_random_values_with_1_count_u64(b: &mut Bencher) { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut rng = rand::rngs::SmallRng::from_entropy(); // This should be *slower* than the benchmarks above where we pre-calculate the values @@ -89,35 +89,35 @@ fn record_random_values_with_1_count_u64(b: &mut Bencher) { #[bench] fn add_precalc_random_value_1_count_same_dimensions_u64(b: &mut Bencher) { do_add_benchmark(b, 1, || { - Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap() + Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap() }) } #[bench] fn add_precalc_random_value_max_count_same_dimensions_u64(b: &mut Bencher) { - do_add_benchmark(b, u64::max_value(), || { - Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap() + do_add_benchmark(b, u64::MAX, || { + Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap() }) } #[bench] fn add_precalc_random_value_1_count_different_precision_u64(b: &mut Bencher) { do_add_benchmark(b, 1, || { - Histogram::::new_with_bounds(1, u64::max_value(), 2).unwrap() + Histogram::::new_with_bounds(1, u64::MAX, 2).unwrap() }) } #[bench] fn add_precalc_random_value_max_count_different_precision_u64(b: &mut Bencher) { - do_add_benchmark(b, u64::max_value(), || { - Histogram::::new_with_bounds(1, u64::max_value(), 2).unwrap() + do_add_benchmark(b, u64::MAX, || { + Histogram::::new_with_bounds(1, u64::MAX, 2).unwrap() }) } #[bench] fn subtract_precalc_random_value_1_count_same_dimensions_u64(b: &mut Bencher) { do_subtract_benchmark(b, 1, || { - Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap() + Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap() }) } @@ -131,7 +131,7 @@ fn do_subtract_benchmark Histogram>( count_at_each_addend_value: u64, addend_factory: F, ) { - let mut accum = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut accum = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut subtrahends = Vec::new(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -160,7 +160,7 @@ fn do_add_benchmark Histogram>( count_at_each_addend_value: u64, addend_factory: F, ) { - let mut accum = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut accum = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut addends = Vec::new(); let mut rng = rand::rngs::SmallRng::from_entropy(); diff --git a/benches/serialization.rs b/benches/serialization.rs index b430c14..250d9dd 100644 --- a/benches/serialization.rs +++ b/benches/serialization.rs @@ -40,25 +40,25 @@ fn serialize_small_sparse_v2(b: &mut Bencher) { #[bench] fn serialize_medium_dense_v2(b: &mut Bencher) { // 56320 counts - do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 3, 1.5) + do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 3, 1.5) } #[bench] fn serialize_medium_sparse_v2(b: &mut Bencher) { // 56320 counts - do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 3, 0.1) + do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 3, 0.1) } #[bench] fn serialize_large_dense_v2(b: &mut Bencher) { // 6291456 buckets - do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 5, 1.5) + do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 5, 1.5) } #[bench] fn serialize_large_sparse_v2(b: &mut Bencher) { // 6291456 buckets - do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 5, 0.1) + do_serialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 5, 0.1) } #[bench] @@ -68,7 +68,7 @@ fn serialize_large_dense_v2_deflate(b: &mut Bencher) { b, &mut V2DeflateSerializer::new(), 1, - u64::max_value(), + u64::MAX, 5, 1.5, ) @@ -81,7 +81,7 @@ fn serialize_large_sparse_v2_deflate(b: &mut Bencher) { b, &mut V2DeflateSerializer::new(), 1, - u64::max_value(), + u64::MAX, 5, 0.1, ) @@ -114,25 +114,25 @@ fn deserialize_small_sparse_v2(b: &mut Bencher) { #[bench] fn deserialize_medium_dense_v2(b: &mut Bencher) { // 56320 counts - do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 3, 1.5) + do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 3, 1.5) } #[bench] fn deserialize_medium_sparse_v2(b: &mut Bencher) { // 56320 counts - do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 3, 0.1) + do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 3, 0.1) } #[bench] fn deserialize_large_dense_v2(b: &mut Bencher) { // 6291456 buckets - do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 5, 1.5) + do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 5, 1.5) } #[bench] fn deserialize_large_sparse_v2(b: &mut Bencher) { // 6291456 buckets - do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::max_value(), 5, 0.1) + do_deserialize_bench(b, &mut V2Serializer::new(), 1, u64::MAX, 5, 0.1) } #[bench] @@ -142,7 +142,7 @@ fn deserialize_large_dense_v2_deflate(b: &mut Bencher) { b, &mut V2DeflateSerializer::new(), 1, - u64::max_value(), + u64::MAX, 5, 1.5, ) @@ -155,7 +155,7 @@ fn deserialize_large_sparse_v2_deflate(b: &mut Bencher) { b, &mut V2DeflateSerializer::new(), 1, - u64::max_value(), + u64::MAX, 5, 0.1, ) diff --git a/examples/cli.rs b/examples/cli.rs index 160de53..b06cb77 100644 --- a/examples/cli.rs +++ b/examples/cli.rs @@ -12,7 +12,7 @@ use hdrhistogram::serialization::{ use hdrhistogram::{Histogram, RecordError}; fn main() { - let default_max = format!("{}", u64::max_value()); + let default_max = format!("{}", u64::MAX); let matches = Command::new("hdrhistogram cli") .subcommand( Command::new("serialize") @@ -228,7 +228,7 @@ fn quantiles( // Normally I frown on excessive use of From as it's too "magic", but in the limited confines of // subcommands, the convenience seems worth it. #[derive(Debug)] -enum CliError { +pub enum CliError { Io(io::Error), HistogramSerialize(V2SerializeError), HistogramSerializeCompressed(V2DeflateSerializeError), diff --git a/src/errors/mod.rs b/src/errors/mod.rs index 29fc1eb..d11abc9 100644 --- a/src/errors/mod.rs +++ b/src/errors/mod.rs @@ -7,7 +7,7 @@ use std::fmt; pub enum CreationError { /// Lowest discernible value must be >= 1. LowIsZero, - /// Lowest discernible value must be <= `u64::max_value() / 2` because the highest value is + /// Lowest discernible value must be <= \x60u64::MAX / 2\x60 because the highest value is /// a `u64` and the lowest value must be no bigger than half the highest. LowExceedsMax, /// Highest trackable value must be >= 2 * lowest discernible value for some internal @@ -78,7 +78,7 @@ impl fmt::Display for CreationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { CreationError::LowIsZero => write!(f, "Lowest discernible value must be >= 1"), - CreationError::LowExceedsMax => write!(f, "Lowest discernible value must be <= `u64::max_value() / 2`"), + CreationError::LowExceedsMax => write!(f, "Lowest discernible value must be <= \x60u64::MAX / 2\x60"), CreationError::HighLessThanTwiceLow => write!(f, "Highest trackable value must be >= 2 * lowest discernible value for some internal calculations"), CreationError::SigFigExceedsMax => write!(f, "Number of significant digits must be in the range `[0, 5]`"), CreationError::CannotRepresentSigFigBeyondLow => write!(f, "Cannot represent sigfig worth of values beyond the lowest discernible value"), diff --git a/src/lib.rs b/src/lib.rs index e3a4e4b..abc150b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -212,7 +212,7 @@ use std::ops::{Add, AddAssign, Sub, SubAssign}; use iterators::HistogramIterator; /// Min value of a new histogram. -/// Equivalent to `u64::max_value()`, but const functions aren't allowed (yet). +/// Equivalent to \x60u64::MAX\x60, but const functions aren't allowed (yet). /// See const ORIGINAL_MIN: u64 = (-1_i64 >> 63) as u64; /// Max value of a new histogram. @@ -605,7 +605,7 @@ impl Histogram { let old_max_lowest_equiv = self.lowest_equivalent(self.max()); // If total_count is at the max value, it may have saturated, so we must restat - let mut needs_restat = self.total_count == u64::max_value(); + let mut needs_restat = self.total_count == u64::MAX; for i in 0..subtrahend.distinct_values() { let other_count = subtrahend @@ -689,7 +689,7 @@ impl Histogram { /// Construct an auto-resizing `Histogram` with a lowest discernible value of 1 and an /// auto-adjusting highest trackable value. Can auto-resize up to track values up to - /// `(i64::max_value() / 2)`. + /// \x60(i64::MAX / 2)\x60. /// /// See [`new_with_bounds`] for info on `sigfig`. /// @@ -724,7 +724,7 @@ impl Histogram { /// use 1. /// /// `high` is the highest value to be tracked by the histogram, and must be a - /// positive integer that is `>= (2 * low)`. If you're not sure, use `u64::max_value()`. + /// positive integer that is \x60>= (2 * low)\x60. If you're not sure, use \x60u64::MAX\x60. /// /// `sigfig` Specifies the number of significant figures to maintain. This is the number of /// significant decimal digits to which the histogram will maintain value resolution and @@ -738,7 +738,7 @@ impl Histogram { if low < 1 { return Err(CreationError::LowIsZero); } - if low > u64::max_value() / 2 { + if low > u64::MAX / 2 { // avoid overflow in 2 * low return Err(CreationError::LowExceedsMax); } @@ -1273,7 +1273,7 @@ impl Histogram { } /// Get the lowest recorded non-zero value level in the histogram. - /// If the histogram has no recorded values, the value returned is `u64::max_value()`. + /// If the histogram has no recorded values, the value returned is \x60u64::MAX\x60. pub fn min_nz(&self) -> u64 { if self.min_non_zero_value == ORIGINAL_MIN { ORIGINAL_MIN @@ -1335,7 +1335,7 @@ impl Histogram { /// /// Two values are considered "equivalent" if `self.equivalent` would return true. /// - /// If the total count of the histogram has exceeded `u64::max_value()`, this will return + /// If the total count of the histogram has exceeded \x60u64::MAX\x60, this will return /// inaccurate results. pub fn value_at_quantile(&self, quantile: f64) -> u64 { // Cap at 1.0 @@ -1386,7 +1386,7 @@ impl Histogram { /// If the value is larger than the maximum representable value, it will be clamped to the /// max representable value. /// - /// If the total count of the histogram has reached `u64::max_value()`, this will return + /// If the total count of the histogram has reached \x60u64::MAX\x60, this will return /// inaccurate results. pub fn quantile_below(&self, value: u64) -> f64 { if self.total_count == 0 { @@ -1431,7 +1431,7 @@ impl Histogram { /// If either value is larger than the maximum representable value, it will be clamped to the /// max representable value. /// - /// The count will saturate at u64::max_value(). + /// The count will saturate at u64::MAX. pub fn count_between(&self, low: u64, high: u64) -> u64 { let low_index = self.index_for_or_last(low); let high_index = self.index_for_or_last(high); @@ -1471,10 +1471,10 @@ impl Histogram { /// resolution. Equivalent here means that value samples recorded for any two equivalent values /// are counted in a common total count. /// - /// Note that the return value is capped at `u64::max_value()`. + /// Note that the return value is capped at \x60u64::MAX\x60. pub fn highest_equivalent(&self, value: u64) -> u64 { - if value == u64::max_value() { - u64::max_value() + if value == u64::MAX { + u64::MAX } else { self.next_non_equivalent(value) - 1 } @@ -1484,7 +1484,7 @@ impl Histogram { /// given value. Equivalent here means that value samples recorded for any two equivalent /// values are counted in a common total count. /// - /// Note that the return value is capped at `u64::max_value()`. + /// Note that the return value is capped at \x60u64::MAX\x60. pub fn median_equivalent(&self, value: u64) -> u64 { // adding half of the range to the bottom of the range shouldn't overflow self.lowest_equivalent(value) @@ -1496,7 +1496,7 @@ impl Histogram { /// resolution. Equivalent means that value samples recorded for any two equivalent values are /// counted in a common total count. /// - /// Note that the return value is capped at `u64::max_value()`. + /// Note that the return value is capped at \x60u64::MAX\x60. pub fn next_non_equivalent(&self, value: u64) -> u64 { self.lowest_equivalent(value) .saturating_add(self.equivalent_range(value)) @@ -1522,13 +1522,13 @@ impl Histogram { /// Computes the matching histogram value for the given histogram bin. /// - /// `index` must be no larger than `u32::max_value()`; no possible histogram uses that much + /// \x60index\x60 must be no larger than \x60u32::MAX\x60; no possible histogram uses that much /// storage anyway. So, any index that comes from a valid histogram location will be safe. /// /// If the index is for a position beyond what this histogram is configured for, the correct /// corresponding value will be returned, but of course it won't have a corresponding count. /// - /// If the index maps to a value beyond `u64::max_value()`, the result will be garbage. + /// If the index maps to a value beyond \x60u64::MAX\x60, the result will be garbage. fn value_for(&self, index: usize) -> u64 { // Dividing by sub bucket half count will yield 1 in top half of first bucket, 2 in // in the top half (i.e., the only half that's used) of the 2nd bucket, etc, so subtract 1 @@ -1595,7 +1595,7 @@ impl Histogram { /// Compute the value corresponding to the provided bucket and sub bucket indices. /// The indices given must map to an actual u64; providing contrived indices that would map to - /// a value larger than u64::max_value() will yield garbage. + /// a value larger than u64::MAX will yield garbage. #[inline] fn value_from_loc(&self, bucket_index: u8, sub_bucket_index: u32) -> u64 { // Sum won't overflow; bucket_index and unit_magnitude are both <= 64. @@ -1615,7 +1615,7 @@ impl Histogram { // always have at least 1 bucket let mut buckets_needed = 1; while smallest_untrackable_value <= value { - if smallest_untrackable_value > u64::max_value() / 2 { + if smallest_untrackable_value > u64::MAX / 2 { // next shift will overflow, meaning that bucket could represent values up to ones // greater than i64::max_value, so it's the last bucket return buckets_needed + 1; @@ -1645,7 +1645,7 @@ impl Histogram { /// Returns an error if the new size cannot be represented as a `usize`. fn resize(&mut self, high: u64) -> Result<(), UsizeTypeTooSmall> { // will not overflow because lowest_discernible_value must be at least as small as - // u64::max_value() / 2 to have passed initial validation + // u64::MAX / 2 to have passed initial validation assert!( high >= 2 * self.lowest_discernible_value, "highest trackable value must be >= (2 * lowest discernible value)" @@ -1705,7 +1705,7 @@ impl Histogram { fn reset_min(&mut self, min: u64) { let internal_value = min & !self.unit_magnitude_mask; // Min unit-equivalent value - self.min_non_zero_value = if min == u64::max_value() { + self.min_non_zero_value = if min == u64::MAX { min } else { internal_value diff --git a/src/serialization/benchmarks.rs b/src/serialization/benchmarks.rs index 559ba93..badfd7f 100644 --- a/src/serialization/benchmarks.rs +++ b/src/serialization/benchmarks.rs @@ -8,7 +8,7 @@ use test::Bencher; #[bench] fn varint_write_rand(b: &mut Bencher) { - do_varint_write_rand(b, Uniform::new(0, u64::max_value())) + do_varint_write_rand(b, Uniform::new(0, u64::MAX)) } #[bench] @@ -18,12 +18,12 @@ fn varint_write_rand_1_byte(b: &mut Bencher) { #[bench] fn varint_write_rand_9_bytes(b: &mut Bencher) { - do_varint_write_rand(b, Uniform::new(1 << 56, u64::max_value())) + do_varint_write_rand(b, Uniform::new(1 << 56, u64::MAX)) } #[bench] fn varint_read_rand(b: &mut Bencher) { - do_varint_read_rand(b, Uniform::new(0, u64::max_value())) + do_varint_read_rand(b, Uniform::new(0, u64::MAX)) } #[bench] @@ -33,12 +33,12 @@ fn varint_read_rand_1_byte(b: &mut Bencher) { #[bench] fn varint_read_rand_9_byte(b: &mut Bencher) { - do_varint_read_rand(b, Uniform::new(1 << 56, u64::max_value())) + do_varint_read_rand(b, Uniform::new(1 << 56, u64::MAX)) } #[bench] fn varint_read_slice_rand(b: &mut Bencher) { - do_varint_read_slice_rand(b, Uniform::new(0, u64::max_value())) + do_varint_read_slice_rand(b, Uniform::new(0, u64::MAX)) } #[bench] @@ -48,7 +48,7 @@ fn varint_read_slice_rand_1_byte(b: &mut Bencher) { #[bench] fn varint_read_slice_rand_9_byte(b: &mut Bencher) { - do_varint_read_slice_rand(b, Uniform::new(1 << 56, u64::max_value())) + do_varint_read_slice_rand(b, Uniform::new(1 << 56, u64::MAX)) } fn do_varint_write_rand(b: &mut Bencher, range: Uniform) { diff --git a/src/serialization/deserializer.rs b/src/serialization/deserializer.rs index dfe6f93..1c75138 100644 --- a/src/serialization/deserializer.rs +++ b/src/serialization/deserializer.rs @@ -164,8 +164,8 @@ impl Deserializer { self.payload_buf.resize(payload_len, 0); } - let mut payload_slice = &mut self.payload_buf[0..payload_len]; - reader.read_exact(&mut payload_slice)?; + let payload_slice = &mut self.payload_buf[0..payload_len]; + reader.read_exact(payload_slice)?; let mut payload_index: usize = 0; let mut restat_state = RestatState::new(); diff --git a/src/serialization/interval_log/mod.rs b/src/serialization/interval_log/mod.rs index 65fe2bb..5601eb2 100644 --- a/src/serialization/interval_log/mod.rs +++ b/src/serialization/interval_log/mod.rs @@ -91,20 +91,20 @@ //! ends up setting its internal version of StartTime. //! //! - Neither StartTime nor BaseTime are present: interval timestamps are interpreted as seconds -//! since the epoch. The first interval's timestamp is stored to the StartTime field. +//! since the epoch. The first interval's timestamp is stored to the StartTime field. //! - StartTime is present: StartTime is a number of seconds since epoch, and interval timestamps -//! may be interpreted as deltas to be added to StartTime or as "absolute" Unix time depending on a -//! heuristic. In other words, the heuristic chooses between setting the effective BaseTime to 0 or -//! to StartTime. Specifically, the heuristic interprets interval timestamps as deltas if they are -//! more than a year's worth of seconds smaller than StartTime and as absolute timestamps otherwise. +//! may be interpreted as deltas to be added to StartTime or as "absolute" Unix time depending on a +//! heuristic. In other words, the heuristic chooses between setting the effective BaseTime to 0 or +//! to StartTime. Specifically, the heuristic interprets interval timestamps as deltas if they are +//! more than a year's worth of seconds smaller than StartTime and as absolute timestamps otherwise. //! - BaseTime is present: BaseTime is a number of seconds since epoch, and interval timestamps are -//! interpreted as deltas. The first interval's (delta) timestamp is stored to the StartTime field. -//! This is likely a bug, since StartTime should be an absolute timestamp, and appears to cause -//! erroneous behavior when filtering by offset timestamps. +//! interpreted as deltas. The first interval's (delta) timestamp is stored to the StartTime field. +//! This is likely a bug, since StartTime should be an absolute timestamp, and appears to cause +//! erroneous behavior when filtering by offset timestamps. //! - BaseTime and StartTime are present: The BaseTime is used like it is when it's the only one -//! present: it's a number of seconds since epoch that serves as the starting point for the -//! per-interval deltas to get a wall-clock time for each interval. No heuristics are applied to -//! guess whether or not the intervals are absolute or deltas. +//! present: it's a number of seconds since epoch that serves as the starting point for the +//! per-interval deltas to get a wall-clock time for each interval. No heuristics are applied to +//! guess whether or not the intervals are absolute or deltas. //! //! The Java implementation also supports re-setting the StartTime and BaseTime if those entries //! exist more than once in the log. Suppose that you had an hour's worth of per-minute intervals, @@ -182,7 +182,7 @@ //! let mut serializer = serialization::V2Serializer::new(); //! //! let mut h = hdrhistogram::Histogram::::new_with_bounds( -//! 1, u64::max_value(), 3).unwrap(); +//! 1, u64::MAX, 3).unwrap(); //! h.record(12345).unwrap(); //! //! // limit scope of mutable borrow of `buf` @@ -316,7 +316,7 @@ impl IntervalLogWriterBuilder { }; for c in &self.comments { - internal_writer.write_comment(&c)?; + internal_writer.write_comment(c)?; } if let Some(st) = self.start_time { @@ -526,7 +526,7 @@ impl<'a> Tag<'a> { } } -impl<'a> ops::Deref for Tag<'a> { +impl ops::Deref for Tag<'_> { type Target = str; fn deref(&self) -> &Self::Target { diff --git a/src/serialization/interval_log/tests.rs b/src/serialization/interval_log/tests.rs index 169fb4d..84291c8 100644 --- a/src/serialization/interval_log/tests.rs +++ b/src/serialization/interval_log/tests.rs @@ -133,7 +133,7 @@ fn write_interval_histo_no_tag() { let mut buf = Vec::new(); let mut serializer = V2Serializer::new(); - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1000).unwrap(); { @@ -164,7 +164,7 @@ fn write_interval_histo_with_tag() { let mut buf = Vec::new(); let mut serializer = V2Serializer::new(); - let h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); { let mut log_writer = IntervalLogWriterBuilder::new() @@ -258,7 +258,7 @@ fn duration_fp_roundtrip_accuracy() { // pick seconds let secs = rng.gen_range(0..2_000_000_000); // pick nsecs that only has ms accuracy - let nsecs = rng.gen_range(0..1000) * 1000_000; + let nsecs = rng.gen_range(0..1000) * 1_000_000; let dur = time::Duration::new(secs, nsecs); let fp_secs = duration_as_fp_seconds(dur); diff --git a/src/serialization/mod.rs b/src/serialization/mod.rs index a4304bc..4be61e8 100644 --- a/src/serialization/mod.rs +++ b/src/serialization/mod.rs @@ -20,13 +20,13 @@ //! # Performance concerns //! //! Serialization is quite fast; serializing a histogram in V2 format that represents 1 to -//! `u64::max_value()` with 3 digits of precision with tens of thousands of recorded counts takes +//! \x60u64::MAX\x60 with 3 digits of precision with tens of thousands of recorded counts takes //! about 40 microseconds on an E5-1650v3 Xeon. Deserialization is about 3x slower, but that will //! improve as there are still some optimizations to perform. //! //! For the V2 format, the space used for a histogram will depend mainly on precision since higher //! precision will reduce the extent to which different values are grouped into the same bucket. -//! Having a large value range (e.g. 1 to `u64::max_value()`) will not directly impact the size if +//! Having a large value range (e.g. 1 to \x60u64::MAX\x60) will not directly impact the size if //! there are many zero counts as zeros are compressed away. //! //! V2 + DEFLATE is significantly slower to serialize (around 10x) but only a little bit slower to @@ -143,7 +143,7 @@ //! //! // Make some histograms //! for _ in 0..num_histograms { -//! let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); +//! let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); //! h.record_n(42, 7).unwrap(); //! histograms.push(h); //! } @@ -161,7 +161,7 @@ //! let mut cursor = Cursor::new(&buf); //! //! let mut accumulator = -//! Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); +//! Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); //! //! for _ in 0..num_histograms { //! let h: Histogram = deserializer.deserialize(&mut cursor).unwrap(); diff --git a/src/serialization/rand_varint.rs b/src/serialization/rand_varint.rs index 5dfeac5..f73b40a 100644 --- a/src/serialization/rand_varint.rs +++ b/src/serialization/rand_varint.rs @@ -7,7 +7,7 @@ use rand::Rng; /// Smallest number in our varint encoding that takes the given number of bytes pub fn smallest_number_in_n_byte_varint(byte_length: usize) -> u64 { - assert!(byte_length <= 9 && byte_length >= 1); + assert!((1..=9).contains(&byte_length)); match byte_length { 1 => 0, @@ -18,10 +18,10 @@ pub fn smallest_number_in_n_byte_varint(byte_length: usize) -> u64 { /// Largest number in our varint encoding that takes the given number of bytes pub fn largest_number_in_n_byte_varint(byte_length: usize) -> u64 { - assert!(byte_length <= 9 && byte_length >= 1); + assert!((1..=9).contains(&byte_length)); match byte_length { - 9 => u64::max_value(), + 9 => u64::MAX, _ => largest_number_in_7_bit_chunk(byte_length - 1), } } diff --git a/src/serialization/tests.rs b/src/serialization/tests.rs index 40e6a96..d3c3d8b 100644 --- a/src/serialization/tests.rs +++ b/src/serialization/tests.rs @@ -84,7 +84,7 @@ fn serialize_roundtrip_all_zeros() { assert_eq!(orig.highest_equivalent(orig.max_value), deser.max_value); // never saw a value, so min never gets set - assert_eq!(u64::max_value(), deser.min_non_zero_value); + assert_eq!(u64::MAX, deser.min_non_zero_value); assert_eq!(orig.total_count, deser.total_count); assert_eq!(orig.counts, deser.counts); @@ -140,47 +140,47 @@ fn serialize_roundtrip_1_count_for_every_value_2_buckets() { #[test] fn serialize_roundtrip_random_v2_u64() { - do_serialize_roundtrip_random(V2Serializer::new(), i64::max_value() as u64); + do_serialize_roundtrip_random(V2Serializer::new(), i64::MAX as u64); } #[test] fn serialize_roundtrip_random_v2_u32() { - do_serialize_roundtrip_random(V2Serializer::new(), u32::max_value()); + do_serialize_roundtrip_random(V2Serializer::new(), u32::MAX); } #[test] fn serialize_roundtrip_random_v2_u16() { - do_serialize_roundtrip_random(V2Serializer::new(), u16::max_value()); + do_serialize_roundtrip_random(V2Serializer::new(), u16::MAX); } #[test] fn serialize_roundtrip_random_v2_u8() { - do_serialize_roundtrip_random(V2Serializer::new(), u8::max_value()); + do_serialize_roundtrip_random(V2Serializer::new(), u8::MAX); } #[test] fn serialize_roundtrip_random_v2_deflate_u64() { - do_serialize_roundtrip_random(V2DeflateSerializer::new(), i64::max_value() as u64); + do_serialize_roundtrip_random(V2DeflateSerializer::new(), i64::MAX as u64); } #[test] fn serialize_roundtrip_random_v2_deflate_u32() { - do_serialize_roundtrip_random(V2DeflateSerializer::new(), u32::max_value()); + do_serialize_roundtrip_random(V2DeflateSerializer::new(), u32::MAX); } #[test] fn serialize_roundtrip_random_v2_deflate_u16() { - do_serialize_roundtrip_random(V2DeflateSerializer::new(), u16::max_value()); + do_serialize_roundtrip_random(V2DeflateSerializer::new(), u16::MAX); } #[test] fn serialize_roundtrip_random_v2_deflate_u8() { - do_serialize_roundtrip_random(V2DeflateSerializer::new(), u8::max_value()); + do_serialize_roundtrip_random(V2DeflateSerializer::new(), u8::MAX); } #[test] fn encode_counts_all_zeros() { - let h = histo64(1, u64::max_value(), 3); + let h = histo64(1, u64::MAX, 3); let counts_len = h.counts.len(); let mut vec = vec![0; counts_array_max_encoded_size(counts_len).unwrap()]; @@ -277,7 +277,7 @@ fn encode_counts_count_too_big() { let mut vec = vec![0; counts_array_max_encoded_size(h.counts.len()).unwrap()]; // first position - h.record_n(0, i64::max_value() as u64 + 1).unwrap(); + h.record_n(0, i64::MAX as u64 + 1).unwrap(); assert_eq!( V2SerializeError::CountNotSerializable.to_string(), encode_counts(&h, &mut vec[..]).unwrap_err().to_string() @@ -312,7 +312,7 @@ fn varint_write_9_bit_value() { #[test] fn varint_write_u64_max() { let mut buf = [0; 9]; - let length = varint_write(u64::max_value(), &mut buf[..]); + let length = varint_write(u64::MAX, &mut buf[..]); assert_eq!(9, length); assert_eq!(vec![0xFF; 9].as_slice(), &buf[..]); } @@ -320,7 +320,7 @@ fn varint_write_u64_max() { #[test] fn varint_read_u64_max() { let input = &mut Cursor::new(vec![0xFF; 9]); - assert_eq!(u64::max_value(), varint_read(input).unwrap()); + assert_eq!(u64::MAX, varint_read(input).unwrap()); } #[test] @@ -451,22 +451,22 @@ fn zig_zag_decode_2() { #[test] fn zig_zag_encode_i64_max() { - assert_eq!(u64::max_value() - 1, zig_zag_encode(i64::max_value())); + assert_eq!(u64::MAX - 1, zig_zag_encode(i64::MAX)); } #[test] fn zig_zag_encode_i64_min() { - assert_eq!(u64::max_value(), zig_zag_encode(i64::min_value())); + assert_eq!(u64::MAX, zig_zag_encode(i64::MIN)); } #[test] fn zig_zag_decode_u64_max_to_i64_min() { - assert_eq!(i64::min_value(), zig_zag_decode(u64::max_value())) + assert_eq!(i64::MIN, zig_zag_decode(u64::MAX)) } #[test] fn zig_zag_decode_u64_max_penultimate_to_i64_max() { - assert_eq!(i64::max_value(), zig_zag_decode(u64::max_value() - 1)) + assert_eq!(i64::MAX, zig_zag_decode(u64::MAX - 1)) } #[test] @@ -483,7 +483,7 @@ fn zig_zag_roundtrip_random() { } fn do_varint_write_read_roundtrip_rand(byte_length: usize) { - assert!(byte_length <= 9 && byte_length >= 1); + assert!((1..=9).contains(&byte_length)); let smallest_in_range = smallest_number_in_n_byte_varint(byte_length); let largest_in_range = largest_number_in_n_byte_varint(byte_length); @@ -496,8 +496,8 @@ fn do_varint_write_read_roundtrip_rand(byte_length: usize) { .chain(once(smallest_in_range)) .chain(once(largest_in_range)) { - for i in 0..(buf.len()) { - buf[i] = 0; + for item in &mut buf { + *item = 0; } let bytes_written = varint_write(i, &mut buf); assert_eq!(byte_length, bytes_written); @@ -509,7 +509,7 @@ fn do_varint_write_read_roundtrip_rand(byte_length: usize) { } fn do_varint_write_read_slice_roundtrip_rand(byte_length: usize) { - assert!(byte_length <= 9 && byte_length >= 1); + assert!((1..=9).contains(&byte_length)); let smallest_in_range = smallest_number_in_n_byte_varint(byte_length); let largest_in_range = largest_number_in_n_byte_varint(byte_length); @@ -523,15 +523,12 @@ fn do_varint_write_read_slice_roundtrip_rand(byte_length: usize) { .chain(once(smallest_in_range)) .chain(once(largest_in_range)) { - for i in 0..(buf.len()) { - buf[i] = 0; + for item in &mut buf { + *item = 0; } let bytes_written = varint_write(i, &mut buf); assert_eq!(byte_length, bytes_written); - assert_eq!( - (i, bytes_written), - varint_read_slice(&mut &buf[..bytes_written]) - ); + assert_eq!((i, bytes_written), varint_read_slice(&buf[..bytes_written])); // make sure the other bytes are all still 0 assert_eq!(vec![0; 9 - bytes_written], &buf[bytes_written..]); @@ -551,7 +548,7 @@ where let range = Uniform::::new(T::one(), max_count); for _ in 0..100 { vec.clear(); - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for value in RandomVarintEncodedLengthIter::new(&mut varint_rng).take(1000) { let count = range.sample(&mut count_rng); diff --git a/src/serialization/v2_serializer.rs b/src/serialization/v2_serializer.rs index 1607154..838a538 100644 --- a/src/serialization/v2_serializer.rs +++ b/src/serialization/v2_serializer.rs @@ -7,7 +7,7 @@ use std::{error, fmt}; /// Errors that occur during serialization. #[derive(Debug)] pub enum V2SerializeError { - /// A count above i64::max_value() cannot be zig-zag encoded, and therefore cannot be + /// A count above i64::MAX cannot be zig-zag encoded, and therefore cannot be /// serialized. CountNotSerializable, /// Internal calculations cannot be represented in `usize`. Use smaller histograms or beefier @@ -28,7 +28,7 @@ impl fmt::Display for V2SerializeError { match self { V2SerializeError::CountNotSerializable => write!( f, - "A count above i64::max_value() cannot be zig-zag encoded" + "A count above i64::MAX cannot be zig-zag encoded" ), V2SerializeError::UsizeTypeTooSmall => { write!(f, "Internal calculations cannot be represented in `usize`") @@ -171,7 +171,7 @@ pub fn encode_counts( -zero_count } else { // TODO while writing tests that serialize random counts, this was annoying. - // Don't want to silently cap them at i64::max_value() for users that, say, aren't + // Don't want to silently cap them at i64::MAX for users that, say, aren't // serializing. Don't want to silently eat counts beyond i63 max when serializing. // Perhaps we should provide some sort of pluggability here -- choose whether you want // to truncate counts to i63 max, or report errors if you need maximum fidelity? diff --git a/src/tests/index_calculation.rs b/src/tests/index_calculation.rs index ef52045..ce3f2fc 100644 --- a/src/tests/index_calculation.rs +++ b/src/tests/index_calculation.rs @@ -27,7 +27,7 @@ fn unit_magnitude_0_index_calculations() { // counting by 4s, starting at halfway through the bucket assert_eq!(1024 + 3, h.sub_bucket_for((2048 << 1) + 3 * 4, 2)); - // past last bucket -- not near u64::max_value(), so should still calculate ok. + // past last bucket -- not near u64::MAX, so should still calculate ok. assert_eq!(23, h.bucket_for((2048_u64 << 22) + 3 * (1 << 23))); assert_eq!( 1024 + 3, @@ -76,7 +76,7 @@ fn unit_magnitude_4_index_calculations() { h.sub_bucket_for((unit << 12) + 3 * (unit << 2), 2) ); - // past last bucket -- not near u64::max_value(), so should still calculate ok. + // past last bucket -- not near u64::MAX, so should still calculate ok. assert_eq!(11, h.bucket_for((unit << 21) + 3 * (unit << 11))); assert_eq!( 1024 + 3, @@ -87,7 +87,7 @@ fn unit_magnitude_4_index_calculations() { #[test] fn unit_magnitude_52_sub_bucket_magnitude_11_index_calculations() { // maximum unit magnitude for this precision - let h = histo64(1_u64 << 52, u64::max_value(), 3); + let h = histo64(1_u64 << 52, u64::MAX, 3); assert_eq!(2048, h.sub_bucket_count); assert_eq!(52, h.unit_magnitude); // sub_bucket_count = 2^11. With unit magnitude shift, it's 2^63. 1 more bucket to (almost) @@ -123,8 +123,8 @@ fn unit_magnitude_52_sub_bucket_magnitude_11_index_calculations() { ); // upper half of second bucket, last slot - assert_eq!(1, h.bucket_for(u64::max_value())); - assert_eq!(1024 + 1023, h.sub_bucket_for(u64::max_value(), 1)); + assert_eq!(1, h.bucket_for(u64::MAX)); + assert_eq!(1024 + 1023, h.sub_bucket_for(u64::MAX, 1)); } #[test] @@ -148,8 +148,8 @@ fn unit_magnitude_55_sub_bucket_magnitude_8_ok() { assert_eq!(0, h.sub_bucket_for(3, 0)); // upper half of second bucket, last slot - assert_eq!(1, h.bucket_for(u64::max_value())); - assert_eq!(128 + 127, h.sub_bucket_for(u64::max_value(), 1)); + assert_eq!(1, h.bucket_for(u64::MAX)); + assert_eq!(128 + 127, h.sub_bucket_for(u64::MAX, 1)); } #[test] @@ -165,8 +165,8 @@ fn unit_magnitude_62_sub_bucket_magnitude_1_ok() { assert_eq!(0, h.sub_bucket_for(3, 0)); // upper half of second bucket, last slot - assert_eq!(1, h.bucket_for(u64::max_value())); - assert_eq!(1, h.sub_bucket_for(u64::max_value(), 1)); + assert_eq!(1, h.bucket_for(u64::MAX)); + assert_eq!(1, h.sub_bucket_for(u64::MAX, 1)); } #[test] diff --git a/src/tests/init.rs b/src/tests/init.rs index 96d805f..096b4b5 100644 --- a/src/tests/init.rs +++ b/src/tests/init.rs @@ -24,9 +24,9 @@ fn init_fields_smallest_possible_array() { #[test] fn init_fields_max_value_max_precision_largest_possible_array() { - let h = histo64(1, u64::max_value(), 5); + let h = histo64(1, u64::MAX, 5); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1, h.lowest_discernible_value); assert_eq!(5, h.significant_value_digits); @@ -50,9 +50,9 @@ fn init_fields_max_value_max_precision_largest_possible_array() { #[test] fn init_fields_max_value_medium_precision() { - let h = histo64(1, u64::max_value(), 3); + let h = histo64(1, u64::MAX, 3); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1, h.lowest_discernible_value); assert_eq!(3, h.significant_value_digits); @@ -100,9 +100,9 @@ fn init_fields_1_bucket_medium_precision() { #[test] fn init_fields_max_value_0_precision_most_buckets() { - let h = histo64(1, u64::max_value(), 0); + let h = histo64(1, u64::MAX, 0); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1, h.lowest_discernible_value); assert_eq!(0, h.significant_value_digits); @@ -124,9 +124,9 @@ fn init_fields_max_value_0_precision_most_buckets() { #[test] fn init_fields_max_value_0_precision_increased_min_value() { - let h = histo64(1000, u64::max_value(), 0); + let h = histo64(1000, u64::MAX, 0); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1000, h.lowest_discernible_value); assert_eq!(0, h.significant_value_digits); @@ -150,9 +150,9 @@ fn init_fields_max_value_0_precision_increased_min_value() { #[test] fn init_fields_max_value_max_precision_increased_min_value() { - let h = histo64(1000, u64::max_value(), 5); + let h = histo64(1000, u64::MAX, 5); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1000, h.lowest_discernible_value); assert_eq!(5, h.significant_value_digits); @@ -209,10 +209,10 @@ fn init_fields_10m_max_1k_min_middle_precision() { #[test] fn init_fields_max_value_max_unit_magnitude_0_precision() { - let h = histo64(u64::max_value() / 4, u64::max_value(), 0); + let h = histo64(u64::MAX / 4, u64::MAX, 0); - assert_eq!(u64::max_value(), h.highest_trackable_value); - assert_eq!(u64::max_value() / 4, h.lowest_discernible_value); + assert_eq!(u64::MAX, h.highest_trackable_value); + assert_eq!(u64::MAX / 4, h.lowest_discernible_value); assert_eq!(0, h.significant_value_digits); // sub bucket must hold 2 * 10^0 @@ -240,9 +240,9 @@ fn init_fields_max_value_max_unit_magnitude_0_precision() { #[test] fn init_fields_max_value_max_unit_magnitude_max_precision() { - let h = histo64(1 << 45, u64::max_value(), 5); + let h = histo64(1 << 45, u64::MAX, 5); - assert_eq!(u64::max_value(), h.highest_trackable_value); + assert_eq!(u64::MAX, h.highest_trackable_value); assert_eq!(1 << 45, h.lowest_discernible_value); assert_eq!(5, h.significant_value_digits); diff --git a/src/tests/subtract.rs b/src/tests/subtract.rs index 4ea5cd5..45548d6 100644 --- a/src/tests/subtract.rs +++ b/src/tests/subtract.rs @@ -17,7 +17,7 @@ fn assert_min_max_count>>(hist: B) { continue; } - min = Some(cmp::min(min.unwrap_or(u64::max_value()), value)); + min = Some(cmp::min(min.unwrap_or(u64::MAX), value)); max = Some(cmp::max(max.unwrap_or(0), value)); total = total.saturating_add(count.to_u64().unwrap()); } @@ -32,8 +32,8 @@ fn assert_min_max_count>>(hist: B) { #[test] fn subtract_after_add() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1 += TEST_VALUE_LEVEL; h1 += 1000 * TEST_VALUE_LEVEL; @@ -61,7 +61,7 @@ fn subtract_after_add() { #[test] fn subtract_to_zero_counts() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1 += TEST_VALUE_LEVEL; h1 += 1000 * TEST_VALUE_LEVEL; @@ -81,8 +81,8 @@ fn subtract_to_zero_counts() { #[test] fn subtract_to_negative_counts_error() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1 += TEST_VALUE_LEVEL; h1 += 1000 * TEST_VALUE_LEVEL; @@ -100,7 +100,7 @@ fn subtract_to_negative_counts_error() { #[test] fn subtract_subtrahend_values_outside_minuend_range_error() { - let max = u64::max_value() / 2; + let max = u64::MAX / 2; let mut h1 = Histogram::::new_with_max(max, 3).unwrap(); h1 += TEST_VALUE_LEVEL; @@ -122,7 +122,7 @@ fn subtract_subtrahend_values_outside_minuend_range_error() { #[test] fn subtract_values_inside_minuend_range_works() { - let max = u64::max_value() / 2; + let max = u64::MAX / 2; let mut h1 = Histogram::::new_with_max(max, 3).unwrap(); h1 += TEST_VALUE_LEVEL; @@ -155,8 +155,8 @@ fn subtract_values_inside_minuend_range_works() { #[test] fn subtract_values_strictly_inside_minuend_range_yields_same_min_max_no_restat() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1 += 1; h1 += 10; @@ -179,8 +179,8 @@ fn subtract_values_strictly_inside_minuend_range_yields_same_min_max_no_restat() #[test] fn subtract_values_at_extent_of_minuend_zero_count_range_recalculates_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1 += 1; h1 += 10; @@ -202,8 +202,8 @@ fn subtract_values_at_extent_of_minuend_zero_count_range_recalculates_min_max() #[test] fn subtract_values_at_extent_of_minuend_nonzero_count_range_recalculates_same_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); h1.record_n(1, 2).unwrap(); h1.record_n(10, 2).unwrap(); @@ -225,8 +225,8 @@ fn subtract_values_at_extent_of_minuend_nonzero_count_range_recalculates_same_mi #[test] fn subtract_values_within_bucket_precision_of_of_minuend_min_recalculates_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 5).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 5).unwrap(); // sub bucket size is 2 above 2048 with 3 sigfits h1.record(3000).unwrap(); @@ -249,8 +249,8 @@ fn subtract_values_within_bucket_precision_of_of_minuend_min_recalculates_min_ma #[test] fn subtract_values_at_minuend_min_recalculates_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 5).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 5).unwrap(); // sub bucket size is 2 above 2048 with 3 sigfits h1.record(3000).unwrap(); @@ -273,8 +273,8 @@ fn subtract_values_at_minuend_min_recalculates_min_max() { #[test] fn subtract_values_within_bucket_precision_of_of_minuend_max_recalculates_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 5).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 5).unwrap(); // sub bucket size is 2 above 2048 with 3 sigfits h1.record(3000).unwrap(); @@ -297,8 +297,8 @@ fn subtract_values_within_bucket_precision_of_of_minuend_max_recalculates_min_ma #[test] fn subtract_values_at_minuend_max_recalculates_min_max() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 5).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 5).unwrap(); // sub bucket size is 2 above 2048 with 3 sigfits h1.record(3000).unwrap(); @@ -321,13 +321,13 @@ fn subtract_values_at_minuend_max_recalculates_min_max() { #[test] fn subtract_values_minuend_saturated_total_recalculates_saturated() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); - h1.record_n(1, u64::max_value()).unwrap(); - h1.record_n(10, u64::max_value()).unwrap(); - h1.record_n(100, u64::max_value()).unwrap(); - h1.record_n(1000, u64::max_value()).unwrap(); + h1.record_n(1, u64::MAX).unwrap(); + h1.record_n(10, u64::MAX).unwrap(); + h1.record_n(100, u64::MAX).unwrap(); + h1.record_n(1000, u64::MAX).unwrap(); h2.record(10).unwrap(); h2.record(100).unwrap(); @@ -339,7 +339,7 @@ fn subtract_values_minuend_saturated_total_recalculates_saturated() { assert_eq!(1, h1.min()); assert_eq!(1000, h1.max()); // still saturated - assert_eq!(u64::max_value(), h1.len()); + assert_eq!(u64::MAX, h1.len()); assert_min_max_count(h1); assert_min_max_count(h2); @@ -347,11 +347,11 @@ fn subtract_values_minuend_saturated_total_recalculates_saturated() { #[test] fn subtract_values_minuend_saturated_total_recalculates_not_saturated() { - let mut h1 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); + let mut h1 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_max(u64::MAX, 3).unwrap(); - // 3 of these is just under u64::max_value() - let chunk = (u64::max_value() / 16) * 5; + // 3 of these is just under u64::MAX + let chunk = (u64::MAX / 16) * 5; h1.record_n(1, chunk).unwrap(); h1.record_n(10, chunk).unwrap(); @@ -367,7 +367,7 @@ fn subtract_values_minuend_saturated_total_recalculates_not_saturated() { assert_eq!(1, h1.min()); assert_eq!(1000, h1.max()); // not saturated - assert_eq!(u64::max_value() / 16 * 15, h1.len()); + assert_eq!(u64::MAX / 16 * 15, h1.len()); assert_min_max_count(h1); assert_min_max_count(h2); diff --git a/src/tests/tests.rs b/src/tests/tests.rs index 96c8865..9cf2f42 100644 --- a/src/tests/tests.rs +++ b/src/tests/tests.rs @@ -20,5 +20,5 @@ fn new_err_high_not_double_low() { #[test] fn correct_original_min() { // until we get const fns, make sure workaround is correct - assert_eq!(u64::max_value(), super::ORIGINAL_MIN); + assert_eq!(u64::MAX, super::ORIGINAL_MIN); } diff --git a/src/tests/value_calculation.rs b/src/tests/value_calculation.rs index 7e3dd79..b21c84f 100644 --- a/src/tests/value_calculation.rs +++ b/src/tests/value_calculation.rs @@ -58,7 +58,7 @@ fn equivalent_range_unit_magnitude_2() { #[test] fn equivalent_range_unit_magnitude_0_max_buckets() { - let h = histo64(1, u64::max_value(), 3); + let h = histo64(1, u64::MAX, 3); assert_eq!(1, h.equivalent_range(0)); assert_eq!(1, h.equivalent_range(1)); @@ -73,12 +73,12 @@ fn equivalent_range_unit_magnitude_0_max_buckets() { // ... assert_eq!(1 << 53, h.equivalent_range(1 << 63)); - assert_eq!(1 << 53, h.equivalent_range(u64::max_value())); + assert_eq!(1 << 53, h.equivalent_range(u64::MAX)); } #[test] fn equivalent_range_unit_magnitude_0_min_precision_max_buckets() { - let h = histo64(1, u64::max_value(), 0); + let h = histo64(1, u64::MAX, 0); assert_eq!(1, h.equivalent_range(0)); assert_eq!(1, h.equivalent_range(1)); @@ -89,12 +89,12 @@ fn equivalent_range_unit_magnitude_0_min_precision_max_buckets() { // ... assert_eq!(1 << 63, h.equivalent_range(1 << 63)); - assert_eq!(1 << 63, h.equivalent_range(u64::max_value())); + assert_eq!(1 << 63, h.equivalent_range(u64::MAX)); } #[test] fn equivalent_range_unit_magnitude_0_max_precision_max_buckets() { - let h = histo64(1, u64::max_value(), 5); + let h = histo64(1, u64::MAX, 5); assert_eq!(1, h.equivalent_range(0)); assert_eq!(1, h.equivalent_range(1)); @@ -109,12 +109,12 @@ fn equivalent_range_unit_magnitude_0_max_precision_max_buckets() { // ... assert_eq!(1 << 46, h.equivalent_range(1 << 63)); - assert_eq!(1 << 46, h.equivalent_range(u64::max_value())); + assert_eq!(1 << 46, h.equivalent_range(u64::MAX)); } #[test] fn equivalent_range_unit_magnitude_2_max_buckets() { - let h = histo64(4, u64::max_value(), 3); + let h = histo64(4, u64::MAX, 3); assert_eq!(1 << 2, h.equivalent_range(0)); assert_eq!(1 << 2, h.equivalent_range(1)); @@ -130,12 +130,12 @@ fn equivalent_range_unit_magnitude_2_max_buckets() { // ... assert_eq!(1 << 53, h.equivalent_range(1 << 63)); - assert_eq!(1 << 53, h.equivalent_range(u64::max_value())); + assert_eq!(1 << 53, h.equivalent_range(u64::MAX)); } #[test] fn equivalent_range_unit_magnitude_50_max_buckets() { - let h = histo64(1 << 50, u64::max_value(), 3); + let h = histo64(1 << 50, u64::MAX, 3); // 11-bit sub buckets assert_eq!(2048, h.sub_bucket_count); @@ -150,7 +150,7 @@ fn equivalent_range_unit_magnitude_50_max_buckets() { // third assert_eq!(1 << 52, h.equivalent_range(1 << 62)); assert_eq!(1 << 53, h.equivalent_range(1 << 63)); - assert_eq!(1 << 53, h.equivalent_range(u64::max_value())); + assert_eq!(1 << 53, h.equivalent_range(u64::MAX)); } #[test] @@ -194,14 +194,14 @@ fn highest_equivalent_unit_magnitude_2() { #[test] fn highest_equivalent_u64_max_value_saturates() { - let h = histo64(1, u64::max_value(), 3); + let h = histo64(1, u64::MAX, 3); assert_eq!( - u64::max_value() - 1, - h.highest_equivalent(u64::max_value() - 1) + u64::MAX - 1, + h.highest_equivalent(u64::MAX - 1) ); - assert_eq!(u64::max_value(), h.highest_equivalent(u64::max_value())); + assert_eq!(u64::MAX, h.highest_equivalent(u64::MAX)); } #[test] @@ -246,17 +246,17 @@ fn next_non_equivalent_unit_magnitude_2() { #[test] fn next_non_equivalent_u64_max_value_saturates() { - let h = histo64(1, u64::max_value(), 3); + let h = histo64(1, u64::MAX, 3); // the next number would be quite a lot higher... - assert_eq!(1_u64 << 53, h.equivalent_range(u64::max_value())); + assert_eq!(1_u64 << 53, h.equivalent_range(u64::MAX)); // ... but it's capped. assert_eq!( - u64::max_value(), - h.next_non_equivalent(u64::max_value() - 1) + u64::MAX, + h.next_non_equivalent(u64::MAX - 1) ); - assert_eq!(u64::max_value(), h.next_non_equivalent(u64::max_value())); + assert_eq!(u64::MAX, h.next_non_equivalent(u64::MAX)); } #[test] @@ -360,7 +360,7 @@ fn value_for_unit_magnitude_2() { #[test] fn value_for_at_each_index() { - let mut h = histo64(1, u64::max_value(), 3); + let mut h = histo64(1, u64::MAX, 3); let max = 1_000_000; @@ -428,7 +428,7 @@ fn value_for_beyond_histogram_max_still_works() { #[test] fn value_for_impossible_index() { // this is unsupported behavior but it would be good to know if it changes. - let max = u64::max_value(); + let max = u64::MAX; let h = histo64(1, max, 3); let max_index = h.index_for(max).unwrap(); diff --git a/tests/auto_resize.rs b/tests/auto_resize.rs index c255742..c259e30 100644 --- a/tests/auto_resize.rs +++ b/tests/auto_resize.rs @@ -8,7 +8,7 @@ fn histogram_autosizing_edges() { histogram += (1_u64 << 62) - 1; assert_eq!(histogram.buckets(), 52); assert_eq!(histogram.distinct_values(), 54272); - histogram += u64::max_value(); + histogram += u64::MAX; assert_eq!(histogram.buckets(), 54); // unit magnitude = floor(log_2 (1 / 2)) = 0 // sub bucket count magnitude = floor(log_2 (2 * 10^3)) = 10 diff --git a/tests/data_access.rs b/tests/data_access.rs index d83c1f8..401f328 100644 --- a/tests/data_access.rs +++ b/tests/data_access.rs @@ -228,13 +228,13 @@ fn quantile_atorbelow() { #[test] fn quantile_below_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for i in 0..1024 { - h.record_n(i, u64::max_value() - 1).unwrap(); + h.record_n(i, u64::MAX - 1).unwrap(); } - // really it should be 0.5 but it saturates at u64::max_value() + // really it should be 0.5 but it saturates at u64::MAX assert_eq!(1.0, h.quantile_below(512)); } @@ -251,7 +251,7 @@ fn quantile_below_value_beyond_max() { h.record(100_000).unwrap(); } - assert_eq!(1.0, h.quantile_below(u64::max_value())); + assert_eq!(1.0, h.quantile_below(u64::MAX)); } #[test] @@ -282,13 +282,13 @@ fn count_between_low_and_high_beyond_max() { #[test] fn count_between_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for i in 0..1024 { - h.record_n(i, u64::max_value() - 1).unwrap(); + h.record_n(i, u64::MAX - 1).unwrap(); } - assert_eq!(u64::max_value(), h.count_between(100, 200)); + assert_eq!(u64::MAX, h.count_between(100, 200)); } #[test] @@ -306,7 +306,7 @@ fn count_at_beyond_max_value() { // largest expressible value will land in last index h.record((1 << 17) - 1).unwrap(); - assert_eq!(1, h.count_at(u64::max_value())); + assert_eq!(1, h.count_at(u64::MAX)); } #[test] diff --git a/tests/histogram.rs b/tests/histogram.rs index d4e3f38..971e2f4 100644 --- a/tests/histogram.rs +++ b/tests/histogram.rs @@ -237,9 +237,9 @@ fn median_equivalent() { #[test] fn median_equivalent_doesnt_panic_at_extremes() { - let h = Histogram::::new_with_max(u64::max_value(), 3).unwrap(); - let _ = h.median_equivalent(u64::max_value()); - let _ = h.median_equivalent(u64::max_value() - 1); + let h = Histogram::::new_with_max(u64::MAX, 3).unwrap(); + let _ = h.median_equivalent(u64::MAX); + let _ = h.median_equivalent(u64::MAX - 1); let _ = h.median_equivalent(0); let _ = h.median_equivalent(1); } @@ -341,7 +341,7 @@ fn scaled_set_to() { #[test] fn random_write_full_value_range_precision_5_no_panic() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 5).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 5).unwrap(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -357,7 +357,7 @@ fn random_write_full_value_range_precision_5_no_panic() { #[test] fn random_write_full_value_range_precision_0_no_panic() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 0).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 0).unwrap(); let mut rng = rand::rngs::SmallRng::from_entropy(); @@ -388,24 +388,24 @@ fn random_write_middle_of_value_range_precision_3_no_panic() { fn value_count_overflow_from_record_saturates_u16() { let mut h = Histogram::::new_with_max(TRACKABLE_MAX, 2).unwrap(); - h.record_n(3, u16::max_value() - 1).unwrap(); - h.record_n(3, u16::max_value() - 1).unwrap(); + h.record_n(3, u16::MAX - 1).unwrap(); + h.record_n(3, u16::MAX - 1).unwrap(); // individual count has saturated - assert_eq!(u16::max_value(), h.count_at(3)); + assert_eq!(u16::MAX, h.count_at(3)); // total is a u64 though - assert_eq!(u64::from(u16::max_value() - 1) * 2, h.len()); + assert_eq!(u64::from(u16::MAX - 1) * 2, h.len()); } #[test] fn value_count_overflow_from_record_saturates_u64() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.len()); } #[test] @@ -413,43 +413,43 @@ fn value_count_overflow_from_record_autoresize_doesnt_panic_saturates() { let mut h = Histogram::::new_with_bounds(1, 10_000, 3).unwrap(); h.auto(true); - h.record_n(1, u64::max_value() - 1).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); // forces resize - h.record_n(1_000_000_000, u64::max_value() - 1).unwrap(); - h.record_n(1_000_000_000, u64::max_value() - 1).unwrap(); + h.record_n(1_000_000_000, u64::MAX - 1).unwrap(); + h.record_n(1_000_000_000, u64::MAX - 1).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.count_at(1_000_000_000)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.count_at(1_000_000_000)); + assert_eq!(u64::MAX, h.len()); } #[test] fn value_count_overflow_from_add_same_dimensions_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h2.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h2.record_n(1, u64::MAX - 1).unwrap(); h.add(h2).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.len()); } #[test] fn value_count_overflow_from_add_different_precision_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); // different precision - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 4).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 4).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h2.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h2.record_n(1, u64::MAX - 1).unwrap(); h.add(h2).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.len()); } #[test] @@ -458,78 +458,78 @@ fn value_count_overflow_from_add_with_resize_to_same_dimensions_saturates() { h.auto(true); let mut h2 = Histogram::::new_with_bounds(1, 10_000_000_000, 3).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h2.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h2.record_n(1, u64::MAX - 1).unwrap(); // recording at value == h2 max should trigger h to resize to the same dimensions when added - h2.record_n(10_000_000_000, u64::max_value() - 1).unwrap(); + h2.record_n(10_000_000_000, u64::MAX - 1).unwrap(); h.add(h2).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.len()); } #[test] fn total_count_overflow_from_record_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h.record_n(10, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h.record_n(10, u64::MAX - 1).unwrap(); - assert_eq!(u64::max_value() - 1, h.count_at(1)); - assert_eq!(u64::max_value() - 1, h.count_at(10)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX - 1, h.count_at(1)); + assert_eq!(u64::MAX - 1, h.count_at(10)); + assert_eq!(u64::MAX, h.len()); } #[test] fn total_count_overflow_from_add_same_dimensions_saturates_calculating_other_addend_total() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value() - 10).unwrap(); - h2.record_n(10, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 10).unwrap(); + h2.record_n(10, u64::MAX - 1).unwrap(); h2.record_n(20, 10).unwrap(); // just h2's total would overflow h.add(h2).unwrap(); - assert_eq!(u64::max_value() - 10, h.count_at(1)); + assert_eq!(u64::MAX - 10, h.count_at(1)); assert_eq!(10, h.count_at(20)); // if accumulating total count for h2 had overflowed, we would see max_value - 1000 + 9 here - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.len()); } #[test] fn total_count_overflow_from_add_same_dimensions_saturates_when_added_to_orig_total_count() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value() - 10).unwrap(); + h.record_n(1, u64::MAX - 10).unwrap(); h2.record_n(10, 9).unwrap(); h2.record_n(20, 9).unwrap(); // h2's total wouldn't overflow, but it would when added to h1 h.add(h2).unwrap(); - assert_eq!(u64::max_value() - 10, h.count_at(1)); + assert_eq!(u64::MAX - 10, h.count_at(1)); assert_eq!(9, h.count_at(20)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.len()); } #[test] fn total_count_overflow_from_add_different_precision_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); // different precision - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 4).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 4).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); - h2.record_n(20, u64::max_value() - 1).unwrap(); + h2.record_n(20, u64::MAX - 1).unwrap(); h.add(h2).unwrap(); - assert_eq!(u64::max_value() - 1, h.count_at(1)); - assert_eq!(u64::max_value() - 1, h.count_at(20)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX - 1, h.count_at(1)); + assert_eq!(u64::MAX - 1, h.count_at(20)); + assert_eq!(u64::MAX, h.len()); } #[test] @@ -538,19 +538,19 @@ fn total_count_overflow_from_add_with_resize_saturates() { h.auto(true); let mut h2 = Histogram::::new_with_bounds(1, 10_000_000_000, 3).unwrap(); - h.record_n(1, u64::max_value() - 1).unwrap(); - h2.record_n(1, u64::max_value() - 1).unwrap(); - h2.record_n(10_000_000_000, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX - 1).unwrap(); + h2.record_n(1, u64::MAX - 1).unwrap(); + h2.record_n(10_000_000_000, u64::MAX - 1).unwrap(); h.add(h2).unwrap(); - assert_eq!(u64::max_value(), h.count_at(1)); - assert_eq!(u64::max_value(), h.len()); + assert_eq!(u64::MAX, h.count_at(1)); + assert_eq!(u64::MAX, h.len()); } #[test] fn subtract_underflow_guarded_by_per_value_count_check() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); - let mut h2 = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); + let mut h2 = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record_n(1, 1).unwrap(); h2.record_n(1, 100).unwrap(); diff --git a/tests/interval_log.rs b/tests/interval_log.rs index d54d8aa..8da97bc 100644 --- a/tests/interval_log.rs +++ b/tests/interval_log.rs @@ -49,7 +49,7 @@ mod tests { ); assert_eq!( 21, - intervals.iter().filter(|ilh| !ilh.tag().is_none()).count() + intervals.iter().filter(|ilh| ilh.tag().is_some()).count() ); } @@ -108,7 +108,7 @@ mod tests { expected, intervals .iter() - .filter(|ilh| !ilh.tag().is_none()) + .filter(|ilh| ilh.tag().is_some()) .map(|ilh| ( round(duration_as_fp_seconds(ilh.start_timestamp())), round(duration_as_fp_seconds(ilh.duration())), @@ -234,10 +234,10 @@ mod tests { writer.write_comment("start").unwrap(); for i in 0_u32..100 { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for _ in 0..100 { - // ensure no count above i64::max_value(), even when many large values are + // ensure no count above i64::MAX, even when many large values are // bucketed together h.record_n(rng.gen::() >> 32, rng.gen::() >> 32) .unwrap(); @@ -296,7 +296,7 @@ mod tests { round(original_hist.max() as f64 / max_scaling_factor), ilh.max() ); - let tag_string: Option = tags.get(index).unwrap().as_ref().map(|s| s.clone()); + let tag_string: Option = tags.get(index).unwrap().clone(); assert_eq!(tag_string, ilh.tag().map(|t| t.as_str().to_owned())); } } @@ -305,7 +305,7 @@ mod tests { fn parse_interval_log_syntax_error_then_returns_none() { let log = "#Foo\nBar\n".as_bytes(); - let mut iter = IntervalLogIterator::new(&log); + let mut iter = IntervalLogIterator::new(log); assert_eq!( Some(Err(LogIteratorError::ParseError { offset: 5 })), @@ -323,7 +323,7 @@ mod tests { d.as_secs() as f64 + d.subsec_nanos() as f64 / 1_000_000_000_f64 } - fn load_iterator_from_file<'a>(path: &Path) -> IntervalLogBufHolder { + fn load_iterator_from_file(path: &Path) -> IntervalLogBufHolder { let mut buf = Vec::new(); let _ = File::open(path).unwrap().read_to_end(&mut buf).unwrap(); diff --git a/tests/iterators.rs b/tests/iterators.rs index 927fa4d..c14b111 100644 --- a/tests/iterators.rs +++ b/tests/iterators.rs @@ -2,7 +2,7 @@ use hdrhistogram::Histogram; #[test] fn iter_recorded_non_saturated_total_count() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1).unwrap(); h.record(1_000).unwrap(); @@ -19,11 +19,11 @@ fn iter_recorded_non_saturated_total_count() { #[test] fn iter_recorded_saturated_total_count() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value()).unwrap(); - h.record_n(1_000, u64::max_value()).unwrap(); - h.record_n(1_000_000, u64::max_value()).unwrap(); + h.record_n(1, u64::MAX).unwrap(); + h.record_n(1_000, u64::MAX).unwrap(); + h.record_n(1_000_000, u64::MAX).unwrap(); let expected = vec![1, 1_000, h.highest_equivalent(1_000_000)]; assert_eq!( @@ -36,22 +36,22 @@ fn iter_recorded_saturated_total_count() { #[test] fn iter_linear_count_since_last_iteration_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); - h.record_n(1, u64::max_value()).unwrap(); - h.record_n(4, u64::max_value() - 1).unwrap(); - h.record_n(5, u64::max_value() - 1).unwrap(); + h.record_n(1, u64::MAX).unwrap(); + h.record_n(4, u64::MAX - 1).unwrap(); + h.record_n(5, u64::MAX - 1).unwrap(); h.record_n(6, 100).unwrap(); h.record_n(7, 200).unwrap(); h.record_n(10, 400).unwrap(); let expected = vec![ // 0-1 has 1's max value - (1, u64::max_value()), + (1, u64::MAX), // 2-3 has nothing (3, 0), // 4-5 has 2x (max - 1), should saturate - (5, u64::max_value()), + (5, u64::MAX), // 6-7 shouldn't be saturated from 4-5 (7, 300), // 8-9 has nothing @@ -71,7 +71,7 @@ fn iter_linear_count_since_last_iteration_saturates() { #[test] fn iter_linear_visits_buckets_wider_than_step_size_multiple_times() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1).unwrap(); h.record(2047).unwrap(); @@ -120,7 +120,7 @@ fn iter_linear_visits_buckets_wider_than_step_size_multiple_times() { #[test] fn iter_linear_visits_buckets_once_when_step_size_equals_bucket_size() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1).unwrap(); h.record(2047).unwrap(); @@ -191,7 +191,7 @@ fn iter_all_values_all_buckets() { let nonzero_count = iter_values .iter() .filter(|v| v.1 != 0) - .map(|&v| v) + .copied() .collect::>(); assert_eq!(expected, nonzero_count); @@ -223,7 +223,7 @@ fn iter_all_values_all_buckets_unit_magnitude_2() { let nonzero_count = iter_values .iter() .filter(|v| v.1 != 0) - .map(|&v| v) + .copied() .collect::>(); assert_eq!(expected, nonzero_count); @@ -550,8 +550,8 @@ fn iter_quantiles_iterates_to_end_skips_intermediate_at_final_value() { // iterate into that bucket (at quantile iteration 0.25), then skip to quantile iteration 1.0 let expected = vec![ (1, 1, 1, 0.000000999999000001, 0.0), - (1000, 1000_000, 1000_000, 1.0, 0.25), - (1000, 0, 1000_000, 1.0, 1.0), + (1000, 1_000_000, 1_000_000, 1.0, 0.25), + (1000, 0, 1_000_000, 1.0, 1.0), ]; assert_eq!(expected, iter_values); @@ -563,7 +563,7 @@ fn iter_quantiles_saturated_count_before_max_value() { for i in 0..1000 { // this will quickly saturate total count as well as count since last iteration - h.record_n(i, u64::max_value() / 100).unwrap(); + h.record_n(i, u64::MAX / 100).unwrap(); } let iter_values: Vec<(u64, u64, u64, f64, f64)> = h diff --git a/tests/quantile.rs b/tests/quantile.rs index 0b11ef6..7cbadd3 100644 --- a/tests/quantile.rs +++ b/tests/quantile.rs @@ -25,7 +25,7 @@ fn value_at_quantile_internal_count_exceeds_bucket_type() { #[test] fn value_at_quantile_2_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1).unwrap(); h.record(2).unwrap(); @@ -45,7 +45,7 @@ fn value_at_quantile_2_values() { #[test] fn value_at_quantile_5_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); h.record(1).unwrap(); h.record(2).unwrap(); @@ -59,7 +59,7 @@ fn value_at_quantile_5_values() { #[test] fn value_at_quantile_20k() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); for i in 1..20_001 { h.record(i).unwrap(); @@ -86,7 +86,7 @@ fn value_at_quantile_large_numbers() { #[test] fn value_at_quantile_matches_quantile_iter_sequence_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let lengths = vec![1, 5, 10, 50, 100, 500, 1_000, 5_000, 10_000]; let mut errors: u64 = 0; @@ -140,7 +140,7 @@ fn value_at_quantile_matches_quantile_iter_sequence_values() { #[test] fn value_at_quantile_matches_quantile_iter_random_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let lengths = vec![1, 5, 10, 50, 100, 500, 1_000, 5_000, 10_000]; @@ -196,7 +196,7 @@ fn value_at_quantile_matches_quantile_iter_random_values() { #[test] fn value_at_quantile_matches_quantile_at_each_value_sequence_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let lengths = vec![1, 5, 10, 50, 100, 500, 1_000, 5_000, 10_000]; let mut errors: u64 = 0; @@ -211,7 +211,7 @@ fn value_at_quantile_matches_quantile_at_each_value_sequence_values() { assert_eq!(length, h.len()); for v in 1..(length + 1) { - let quantile = Rational::from((v as u64, length as u64)).to_f64(); + let quantile = Rational::from((v, length)).to_f64(); let calculated_value = h.value_at_quantile(quantile); if !h.equivalent(v, calculated_value) { println!( @@ -235,7 +235,7 @@ fn value_at_quantile_matches_quantile_at_each_value_sequence_values() { #[test] fn value_at_quantile_matches_quantile_at_each_value_random_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut values = Vec::new(); let lengths = vec![1, 5, 10, 50, 100, 500, 1_000, 5_000, 10_000]; @@ -282,7 +282,7 @@ fn value_at_quantile_matches_quantile_at_each_value_random_values() { #[test] fn value_at_quantile_matches_random_quantile_random_values() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); let mut values = Vec::new(); let lengths = vec![1, 5, 10, 50, 100, 500, 1_000, 5_000, 10_000]; @@ -342,8 +342,8 @@ struct RandomMaxIter<'a, R: Rng + 'a> { rng: &'a mut R, } -impl<'a, R: Rng + 'a> RandomMaxIter<'a, R> { - fn new(rng: &'a mut R) -> RandomMaxIter { +impl RandomMaxIter<'_, R> { + fn new(rng: &mut R) -> RandomMaxIter { RandomMaxIter { rng } } } @@ -354,11 +354,11 @@ impl<'a, R: Rng + 'a> Iterator for RandomMaxIter<'a, R> { fn next(&mut self) -> Option { let bit_length = self.rng.gen_range(0..=64); - return Some(match bit_length { + Some(match bit_length { 0 => 0, - 64 => u64::max_value(), + 64 => u64::MAX, x => self.rng.gen_range(0..1 << x), - }); + }) } } diff --git a/tests/serialization.rs b/tests/serialization.rs index 2ba9faf..1761061 100644 --- a/tests/serialization.rs +++ b/tests/serialization.rs @@ -50,13 +50,13 @@ mod tests { #[test] fn total_count_overflow_from_deserialize_saturates() { - let mut h = Histogram::::new_with_bounds(1, u64::max_value(), 3).unwrap(); + let mut h = Histogram::::new_with_bounds(1, u64::MAX, 3).unwrap(); // can't go bigger than i64 max because it will be serialized - h.record_n(1, i64::max_value() as u64).unwrap(); - h.record_n(1000, i64::max_value() as u64).unwrap(); - h.record_n(1000_000, i64::max_value() as u64).unwrap(); - assert_eq!(u64::max_value(), h.len()); + h.record_n(1, i64::MAX as u64).unwrap(); + h.record_n(1000, i64::MAX as u64).unwrap(); + h.record_n(1_000_000, i64::MAX as u64).unwrap(); + assert_eq!(u64::MAX, h.len()); let mut vec = Vec::new(); @@ -64,13 +64,12 @@ mod tests { let deser_h: Histogram = Deserializer::new() .deserialize(&mut vec.as_slice()) .unwrap(); - assert_eq!(u64::max_value(), deser_h.len()); + assert_eq!(u64::MAX, deser_h.len()); } fn load_histogram_from_num_per_line(path: &Path) -> Histogram { // max is Java's Long.MAX_VALUE - let mut h: Histogram = - Histogram::new_with_bounds(1, u64::max_value() >> 1, 3).unwrap(); + let mut h: Histogram = Histogram::new_with_bounds(1, u64::MAX >> 1, 3).unwrap(); for num in BufReader::new(File::open(path).unwrap()) .lines() .map(|l| l.unwrap().parse().unwrap()) From 86528740ec12b879a270e14e08a88e812657b6a7 Mon Sep 17 00:00:00 2001 From: bogzbonny Date: Thu, 15 May 2025 16:38:07 -0700 Subject: [PATCH 3/3] unrecord --- src/lib.rs | 86 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index abc150b..03ff2a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -850,6 +850,14 @@ impl Histogram { self.record_n(value, T::one()) } + /// Unrecord `value` in the histogram, removing from the value's current count. + /// + /// Returns an error if `value` exceeds the highest trackable value and auto-resize is + /// disabled. + pub fn unrecord(&mut self, value: u64) -> Result<(), RecordError> { + self.record_n_inner(true, value, T::one(), false) + } + /// Record `value` in the histogram, clamped to the range of the histogram. /// /// This method cannot fail, as any values that are too small or too large to be tracked will @@ -860,13 +868,32 @@ impl Histogram { self.saturating_record_n(value, T::one()) } + /// Unrecord `value` in the histogram, removing from the value's current count. + /// + /// This method cannot fail, as any values that are too small or too large to be tracked will + /// automatically be clamed to be in range. Be aware that this *will* hide extreme outliers + /// from the resulting histogram without warning. Since the values are clamped, the histogram + /// will also not be resized to accomodate the value, even if auto-resize is enabled. + pub fn saturating_unrecord(&mut self, value: u64) { + self.saturating_record_n(value, T::one()) + } + /// Record multiple samples for a value in the histogram, adding to the value's current count. /// /// `count` is the number of occurrences of this value to record. /// /// Returns an error if `value` cannot be recorded; see `RecordError`. pub fn record_n(&mut self, value: u64, count: T) -> Result<(), RecordError> { - self.record_n_inner(value, count, false) + self.record_n_inner(false, value, count, false) + } + + /// Unrecord multiple samples for a value in the histogram, removing from the value's current count. + /// + /// `count` is the number of occurrences of this value to record. + /// + /// Returns an error if `value` cannot be unrecorded; see `RecordError`. + pub fn unrecord_n(&mut self, value: u64, count: T) -> Result<(), RecordError> { + self.record_n_inner(true, value, count, false) } /// Record multiple samples for a value in the histogram, each one clamped to the histogram's @@ -879,12 +906,34 @@ impl Histogram { /// from the resulting histogram without warning. Since the values are clamped, the histogram /// will also not be resized to accomodate the value, even if auto-resize is enabled. pub fn saturating_record_n(&mut self, value: u64, count: T) { - self.record_n_inner(value, count, true).unwrap() + self.record_n_inner(false, value, count, true).unwrap() + } + + /// Unrecord multiple samples for a value in the histogram, removing from the value's current count. + /// + /// `count` is the number of occurrences of this value to record. + /// + /// This method cannot fail, as values that are too small or too large to be recorded will + /// automatically be clamed to be in range. Be aware that this *will* hide extreme outliers + /// from the resulting histogram without warning. Since the values are clamped, the histogram + /// will also not be resized to accomodate the value, even if auto-resize is enabled. + pub fn saturating_unrecord_n(&mut self, value: u64, count: T) { + self.record_n_inner(true, value, count, true).unwrap() } - fn record_n_inner(&mut self, mut value: u64, count: T, clamp: bool) -> Result<(), RecordError> { + fn record_n_inner( + &mut self, + sub: bool, + mut value: u64, + count: T, + clamp: bool, + ) -> Result<(), RecordError> { let recorded_without_resize = if let Some(c) = self.mut_at(value) { - *c = (*c).saturating_add(count); + if sub { + *c = c.saturating_sub(count); + } else { + *c = c.saturating_add(count); + } true } else { false @@ -903,7 +952,12 @@ impl Histogram { let c = self .mut_at(value) .expect("unwrap must succeed since low and high are always representable"); - *c = c.saturating_add(count); + + if sub { + *c = c.saturating_sub(count); + } else { + *c = c.saturating_add(count); + } } else if !self.auto_resize { return Err(RecordError::ValueOutOfRangeResizeDisabled); } else { @@ -916,15 +970,21 @@ impl Histogram { { let c = self.mut_at(value).expect("value should fit after resize"); // after resize, should be no possibility of overflow because this is a new slot - *c = (*c) - .checked_add(&count) - .expect("count overflow after resize"); + if sub { + *c = c.checked_sub(&count).expect("count overflow after resize"); + } else { + *c = c.checked_add(&count).expect("count overflow after resize"); + } } } } self.update_min_max(value); - self.total_count = self.total_count.saturating_add(count.as_u64()); + if sub { + self.total_count = self.total_count.saturating_sub(count.as_u64()); + } else { + self.total_count = self.total_count.saturating_add(count.as_u64()); + } Ok(()) } @@ -963,7 +1023,7 @@ impl Histogram { // only enter loop when calculations will stay non-negative let mut missing_value = value - interval; while missing_value >= interval { - self.record_n_inner(missing_value, count, false)?; + self.record_n_inner(false, missing_value, count, false)?; missing_value -= interval; } } @@ -1705,11 +1765,7 @@ impl Histogram { fn reset_min(&mut self, min: u64) { let internal_value = min & !self.unit_magnitude_mask; // Min unit-equivalent value - self.min_non_zero_value = if min == u64::MAX { - min - } else { - internal_value - }; + self.min_non_zero_value = if min == u64::MAX { min } else { internal_value }; } /// Recalculate min, max, total_count.