Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 //! A minimal implementation of Adler32 for Rust.
2 //!
3 //! This provides the simple method adler32(), that exhausts a Read and
4 //! computes the Adler32 hash, as well as the RollingAdler32 struct, that can
5 //! build a hash byte-by-byte, allowing to 'forget' past bytes in a rolling
6 //! fashion.
7 //!
8 //! The adler32 code has been translated (as accurately as I could manage) from
9 //! the zlib implementation.
10
11 #![forbid(unsafe_code)]
12 #![cfg_attr(not(feature = "std"), no_std)]
13
14
15 // adler32 algorithm and implementation taken from zlib; http://www.zlib.net/
16 // It was translated into Rust as accurately as I could manage
17 // The (slow) reference was taken from Wikipedia; https://en.wikipedia.org/
18
19 /* zlib.h -- interface of the 'zlib' general purpose compression library
20 version 1.2.8, April 28th, 2013
21
22 Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
23
24 This software is provided 'as-is', without any express or implied
25 warranty. In no event will the authors be held liable for any damages
26 arising from the use of this software.
27
28 Permission is granted to anyone to use this software for any purpose,
29 including commercial applications, and to alter it and redistribute it
30 freely, subject to the following restrictions:
31
32 1. The origin of this software must not be misrepresented; you must not
33 claim that you wrote the original software. If you use this software
34 in a product, an acknowledgment in the product documentation would be
35 appreciated but is not required.
36 2. Altered source versions must be plainly marked as such, and must not be
37 misrepresented as being the original software.
38 3. This notice may not be removed or altered from any source distribution.
39
40 Jean-loup Gailly Mark Adler
41 [email protected] [email protected]
42
43 */
44
45 // largest prime smaller than 65536
46 const BASErust-analyzer cargo adler32 1.2.0 BASE.: u32 = 65521;
47
48 // NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
49 const NMAXrust-analyzer cargo adler32 1.2.0 NMAX.: usize = 5552;
50
51 #[inline(always)]
52 fn do1rust-analyzer cargo adler32 1.2.0 do1().(adler: &mut u32, sum2: &mut u32, buf: &[u8]) {
53 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().adler rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
54 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().sum2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().adler;
55 }
56
57 #[inline(always)]
58 fn do2rust-analyzer cargo adler32 1.2.0 do2().(adler: &mut u32, sum2: &mut u32, buf: &[u8]) {
59 do1rust-analyzer cargo adler32 1.2.0 do1().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
60 do1rust-analyzer cargo adler32 1.2.0 do1().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
61 }
62
63 #[inline(always)]
64 fn do4rust-analyzer cargo adler32 1.2.0 do4().(adler: &mut u32, sum2: &mut u32, buf: &[u8]) {
65 do2rust-analyzer cargo adler32 1.2.0 do2().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#2]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
66 do2rust-analyzer cargo adler32 1.2.0 do2().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().2..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
67 }
68
69 #[inline(always)]
70 fn do8rust-analyzer cargo adler32 1.2.0 do8().(adler: &mut u32, sum2: &mut u32, buf: &[u8]) {
71 do4rust-analyzer cargo adler32 1.2.0 do4().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
72 do4rust-analyzer cargo adler32 1.2.0 do4().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
73 }
74
75 #[inline(always)]
76 fn do16rust-analyzer cargo adler32 1.2.0 do16().(adler: &mut u32, sum2: &mut u32, buf: &[u8]) {
77 do8rust-analyzer cargo adler32 1.2.0 do8().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#8]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
78 do8rust-analyzer cargo adler32 1.2.0 do8().(adler, sum2, &buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().8..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#16]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
79 }
80
81 /// A rolling version of the Adler32 hash, which can 'forget' past bytes.
82 ///
83 /// Calling remove() will update the hash to the value it would have if that
84 /// past byte had never been fed to the algorithm. This allows you to get the
85 /// hash of a rolling window very efficiently.
86 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
87 pub struct RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
88 arust-analyzer cargo adler32 1.2.0 RollingAdler32#a.: u32,
89 brust-analyzer cargo adler32 1.2.0 RollingAdler32#b.: u32,
90 }
91
92 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
93 fn defaultrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32][Default]default().() -> RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
94 RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().()
95 }
96 }
97
98 impl RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
99 /// Creates an empty Adler32 context (with hash 1).
100 pub fn newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().() -> RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
101 Selfrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]::from_valuerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]from_value().(1)
102 }
103
104 /// Creates an Adler32 context with the given initial value.
105 pub fn from_valuerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]from_value().(adler32: u32) -> RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
106 let a = adler32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0xFFFF;
107 let b = adler32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().16;
108 RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# { arust-analyzer cargo adler32 1.2.0 RollingAdler32#a., brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. }
109 }
110
111 /// Convenience function initializing a context from the hash of a buffer.
112 pub fn from_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]from_buffer().(buffer: &[u8]) -> RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32# {
113 let mut hash = RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().();
114 hash.update_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update_buffer().(buffer);
115 hash
116 }
117
118 /// Returns the current hash.
119 pub fn hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(&self) -> u32 {
120 (self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().16) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a.
121 }
122
123 /// Removes the given `byte` that was fed to the algorithm `size` bytes ago.
124 pub fn removerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]remove().(&mut self, size: usize, byte: u8) {
125 let byte = u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(byte);
126 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. = (self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().BASErust-analyzer cargo adler32 1.2.0 BASE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().byte) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
127 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. = ((self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().BASErust-analyzer cargo adler32 1.2.0 BASE. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1)
128 .wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_add().(BASErust-analyzer cargo adler32 1.2.0 BASE..wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_sub().(size as u32).wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_mul().(byte)))
129 %rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
130 }
131
132 /// Feeds a new `byte` to the algorithm to update the hash.
133 pub fn updaterust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update().(&mut self, byte: u8) {
134 let byte = u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(byte);
135 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. = (self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().byte) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
136 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. = (self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a.) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
137 }
138
139 /// Feeds a vector of bytes to the algorithm to update the hash.
140 pub fn update_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update_buffer().(&mut self, buffer: &[u8]) {
141 let len = buffer.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().();
142
143 // in case user likes doing a byte at a time, keep it fast
144 if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 {
145 self.updaterust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update().(buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
146 return;
147 }
148
149 // in case short lengths are provided, keep it somewhat fast
150 if len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().16 {
151 for byte in buffer.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(len) {
152 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().byte);
153 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a.;
154 }
155 if self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().BASErust-analyzer cargo adler32 1.2.0 BASE. {
156 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`SubAssign<Self>`]sub_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
157 }
158 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
159 return;
160 }
161
162 let mut pos = 0;
163
164 // do length NMAX blocks -- requires just one modulo operation;
165 while pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().NMAXrust-analyzer cargo adler32 1.2.0 NMAX. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().len {
166 let end = pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().NMAXrust-analyzer cargo adler32 1.2.0 NMAX.;
167 while pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().end {
168 // 16 sums unrolled
169 do16rust-analyzer cargo adler32 1.2.0 do16().(&mut self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a., &mut self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b., &buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().16]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
170 pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().16;
171 }
172 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
173 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
174 }
175
176 // do remaining bytes (less than NMAX, still just one modulo)
177 if pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().len {
178 // avoid modulos if none remaining
179 while len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().16 {
180 do16rust-analyzer cargo adler32 1.2.0 do16().(&mut self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a., &mut self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b., &buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().16]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
181 pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().16;
182 }
183 while len rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
184 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().u32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`From<u8>`]from().(buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
185 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a.;
186 pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
187 }
188 self.arust-analyzer cargo adler32 1.2.0 RollingAdler32#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
189 self.brust-analyzer cargo adler32 1.2.0 RollingAdler32#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`RemAssign<Self>`]rem_assign().BASErust-analyzer cargo adler32 1.2.0 BASE.;
190 }
191 }
192 }
193
194 /// Consume a Read object and returns the Adler32 hash.
195 #[cfg(feature = "std")]
196 pub fn adler32rust-analyzer cargo adler32 1.2.0 adler32().<R: stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(mut reader: R) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u32> {
197 let mut hash = RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().();
198 let mut buffer = [0u8; NMAXrust-analyzer cargo adler32 1.2.0 NMAX.];
199 let mut read = reader.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
200 while read rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 {
201 hash.update_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update_buffer().(&buffer[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#read]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().);
202 read = reader.readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#read().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
203 }
204 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(hash.hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().())
205 }
206
207 #[cfg(test)]
208 mod testrust-analyzer cargo adler32 1.2.0 test/ {
209 use randrust-analyzer cargo rand 0.7.3 crate/::Rngrust-analyzer cargo rand 0.7.3 Rng#;
210 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/;
211 #[cfg(target_arch = "wasm32")]
212 use wasm_bindgen_test::wasm_bindgen_test;
213
214 use superrust-analyzer cargo adler32 1.2.0 crate/::{adler32rust-analyzer cargo adler32 1.2.0 adler32()., RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#, BASErust-analyzer cargo adler32 1.2.0 BASE.};
215
216 fn adler32_slowrust-analyzer cargo adler32 1.2.0 test/adler32_slow().<R: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#>(reader: R) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<u32> {
217 let mut a: u32 = 1;
218 let mut b: u32 = 0;
219
220 for byte in reader.bytesrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Read#bytes().() {
221 let byte = byte?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). as u32;
222 a = (a rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().byte) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
223 b = (b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().a) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().BASErust-analyzer cargo adler32 1.2.0 BASE.;
224 }
225
226 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().16) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().a)
227 }
228
229 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
230 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
231 fn testvectorsrust-analyzer cargo adler32 1.2.0 test/testvectors().() {
232 fn do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(v: u32, bytes: &[u8]) {
233 let mut hash = RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().();
234 hash.update_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update_buffer().(&bytes);
235 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hash.hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(), v);
236
237 let r = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(bytes);
238 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(adler32rust-analyzer cargo adler32 1.2.0 adler32().(r).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), v);
239 }
240 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0x00000001, b"");
241 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0x00620062, b"a");
242 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0x024d0127, b"abc");
243 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0x29750586, b"message digest");
244 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0x90860b20, b"abcdefghijklmnopqrstuvwxyz");
245 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(
246 0x8adb150c,
247 b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
248 abcdefghijklmnopqrstuvwxyz\
249 0123456789",
250 );
251 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(
252 0x97b61069,
253 b"1234567890123456789012345678901234567890\
254 1234567890123456789012345678901234567890",
255 );
256 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(0xD6251498, &[255; 64000]);
257 }
258
259 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
260 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
261 fn comparerust-analyzer cargo adler32 1.2.0 test/compare().() {
262 let mut rng = randrust-analyzer cargo rand 0.7.3 crate/::thread_rngrust-analyzer cargo rand 0.7.3 rngs/thread/thread_rng().();
263 let mut data = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0u8; 5589];
264 for size in [
265 0, 1, 3, 4, 5, 31, 32, 33, 67, 5550, 5552, 5553, 5568, 5584, 5589,
266 ]
267 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
268 .clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#cloned().()
269 {
270 rng.fillrust-analyzer cargo rand 0.7.3 Rng#fill().(&mut data[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#size]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().);
271 let r1 = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(&data[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#size]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
272 let r2 = r1.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`][Clone]clone().();
273 if adler32_slowrust-analyzer cargo adler32 1.2.0 test/adler32_slow().(r1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().adler32rust-analyzer cargo adler32 1.2.0 adler32().(r2).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() {
274 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Comparison failed, size={}", size);
275 }
276 }
277 }
278
279 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
280 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
281 fn rollingrust-analyzer cargo adler32 1.2.0 test/rolling().() {
282 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::from_valuerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]from_value().(0x01020304).hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(), 0x01020304);
283
284 fn do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(a: &[u8], b: &[u8]) {
285 let mut total = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().b.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().());
286 total.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(a);
287 total.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<&'a T>`]extend().(b);
288 let mut h = RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::from_bufferrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]from_buffer().(&total[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#(b.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().())]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
289 for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(a.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) {
290 h.removerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]remove().(b.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), a[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().);
291 h.updaterust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update().(total[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().b.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
292 }
293 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(h.hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(), adler32rust-analyzer cargo adler32 1.2.0 adler32().(b).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
294 }
295 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(b"a", b"b");
296 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(b"", b"this a test");
297 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(b"th", b"is a test");
298 do_testrust-analyzer cargo adler32 1.2.0 test/do_test().(b"this a ", b"test");
299 }
300
301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
302 #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
303 fn long_window_removerust-analyzer cargo adler32 1.2.0 test/long_window_remove().() {
304 let mut hash = RollingAdler32rust-analyzer cargo adler32 1.2.0 RollingAdler32#::newrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]new().();
305 let w = 65536;
306 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(w as u32 >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). BASErust-analyzer cargo adler32 1.2.0 BASE.);
307
308 let mut bytes = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; w *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 3];
309 for (i, b) in bytes.iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
310 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().b = i as u8;
311 }
312
313 for (i, b) in bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
314 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().w {
315 hash.removerust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]remove().(w, bytes[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().w]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
316 }
317 hash.updaterust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]update().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().b);
318 if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().w rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
319 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hash.hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(), 0x433a8772);
320 }
321 }
322 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hash.hashrust-analyzer cargo adler32 1.2.0 impl#[RollingAdler32]hash().(), 0xbbba8772);
323 }
324 }