Skip to content

Commit eca6628

Browse files
authored
Minor refactoring (#1266)
1 parent 9679c5f commit eca6628

File tree

208 files changed

+2015
-2331
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

208 files changed

+2015
-2331
lines changed

bitpacker/src/bitpacker.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{convert::TryInto, io};
1+
use std::convert::TryInto;
2+
use std::io;
23

34
pub struct BitPacker {
45
mini_buffer: u64,

bitpacker/src/blocked_bitpacker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
use super::bitpacker::BitPacker;
2+
use super::compute_num_bits;
13
use crate::{minmax, BitUnpacker};
24

3-
use super::{bitpacker::BitPacker, compute_num_bits};
4-
55
const BLOCK_SIZE: usize = 128;
66

77
/// `BlockedBitpacker` compresses data in blocks of
88
/// 128 elements, while keeping an index on it
9-
///
109
#[derive(Debug, Clone)]
1110
pub struct BlockedBitpacker {
1211
// bitpacked blocks

bitpacker/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
mod bitpacker;
22
mod blocked_bitpacker;
33

4-
pub use crate::bitpacker::BitPacker;
5-
pub use crate::bitpacker::BitUnpacker;
4+
pub use crate::bitpacker::{BitPacker, BitUnpacker};
65
pub use crate::blocked_bitpacker::BlockedBitpacker;
76

87
/// Computes the number of bits that will be used for bitpacking.

common/src/bitset.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use ownedbytes::OwnedBytes;
21
use std::convert::TryInto;
32
use std::io::Write;
4-
use std::u64;
5-
use std::{fmt, io};
3+
use std::{fmt, io, u64};
4+
5+
use ownedbytes::OwnedBytes;
66

77
#[derive(Clone, Copy, Eq, PartialEq)]
88
pub struct TinySet(u64);
@@ -187,7 +187,6 @@ fn num_buckets(max_val: u32) -> u32 {
187187

188188
impl BitSet {
189189
/// serialize a `BitSet`.
190-
///
191190
pub fn serialize<T: Write>(&self, writer: &mut T) -> io::Result<()> {
192191
writer.write_all(self.max_value.to_le_bytes().as_ref())?;
193192
for tinyset in self.tinysets.iter().cloned() {
@@ -353,7 +352,6 @@ impl ReadOnlyBitSet {
353352
}
354353

355354
/// Iterate the tinyset on the fly from serialized data.
356-
///
357355
#[inline]
358356
fn iter_tinysets(&self) -> impl Iterator<Item = TinySet> + '_ {
359357
self.data.chunks_exact(8).map(move |chunk| {
@@ -363,7 +361,6 @@ impl ReadOnlyBitSet {
363361
}
364362

365363
/// Iterate over the positions of the elements.
366-
///
367364
#[inline]
368365
pub fn iter(&self) -> impl Iterator<Item = u32> + '_ {
369366
self.iter_tinysets()
@@ -415,14 +412,14 @@ impl<'a> From<&'a BitSet> for ReadOnlyBitSet {
415412
#[cfg(test)]
416413
mod tests {
417414

418-
use super::BitSet;
419-
use super::ReadOnlyBitSet;
420-
use super::TinySet;
415+
use std::collections::HashSet;
416+
421417
use ownedbytes::OwnedBytes;
422418
use rand::distributions::Bernoulli;
423419
use rand::rngs::StdRng;
424420
use rand::{Rng, SeedableRng};
425-
use std::collections::HashSet;
421+
422+
use super::{BitSet, ReadOnlyBitSet, TinySet};
426423

427424
#[test]
428425
fn test_read_serialized_bitset_full_multi() {
@@ -710,10 +707,10 @@ mod tests {
710707
#[cfg(all(test, feature = "unstable"))]
711708
mod bench {
712709

713-
use super::BitSet;
714-
use super::TinySet;
715710
use test;
716711

712+
use super::{BitSet, TinySet};
713+
717714
#[bench]
718715
fn bench_tinyset_pop(b: &mut test::Bencher) {
719716
b.iter(|| {

common/src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ pub fn u64_to_f64(val: u64) -> f64 {
104104
#[cfg(test)]
105105
pub mod test {
106106

107-
use super::{f64_to_u64, i64_to_u64, u64_to_f64, u64_to_i64};
108-
use super::{BinarySerializable, FixedSize};
109-
use proptest::prelude::*;
110107
use std::f64;
111108

109+
use proptest::prelude::*;
110+
111+
use super::{f64_to_u64, i64_to_u64, u64_to_f64, u64_to_i64, BinarySerializable, FixedSize};
112+
112113
fn test_i64_converter_helper(val: i64) {
113114
assert_eq!(u64_to_i64(i64_to_u64(val)), val);
114115
}
@@ -157,10 +158,10 @@ pub mod test {
157158
#[test]
158159
fn test_f64_order() {
159160
assert!(!(f64_to_u64(f64::NEG_INFINITY)..f64_to_u64(f64::INFINITY))
160-
.contains(&f64_to_u64(f64::NAN))); //nan is not a number
161-
assert!(f64_to_u64(1.5) > f64_to_u64(1.0)); //same exponent, different mantissa
162-
assert!(f64_to_u64(2.0) > f64_to_u64(1.0)); //same mantissa, different exponent
163-
assert!(f64_to_u64(2.0) > f64_to_u64(1.5)); //different exponent and mantissa
161+
.contains(&f64_to_u64(f64::NAN))); // nan is not a number
162+
assert!(f64_to_u64(1.5) > f64_to_u64(1.0)); // same exponent, different mantissa
163+
assert!(f64_to_u64(2.0) > f64_to_u64(1.0)); // same mantissa, different exponent
164+
assert!(f64_to_u64(2.0) > f64_to_u64(1.5)); // different exponent and mantissa
164165
assert!(f64_to_u64(1.0) > f64_to_u64(-1.0)); // pos > neg
165166
assert!(f64_to_u64(-1.5) < f64_to_u64(-1.0));
166167
assert!(f64_to_u64(-2.0) < f64_to_u64(1.0));

common/src/serialize.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::Endianness;
2-
use crate::VInt;
1+
use std::io::{Read, Write};
2+
use std::{fmt, io};
3+
34
use byteorder::{ReadBytesExt, WriteBytesExt};
4-
use std::fmt;
5-
use std::io;
6-
use std::io::Read;
7-
use std::io::Write;
5+
6+
use crate::{Endianness, VInt};
87

98
/// Trait for a simple binary serialization.
109
pub trait BinarySerializable: fmt::Debug + Sized {
@@ -202,8 +201,7 @@ impl BinarySerializable for String {
202201
#[cfg(test)]
203202
pub mod test {
204203

205-
use super::VInt;
206-
use super::*;
204+
use super::{VInt, *};
207205
use crate::serialize::BinarySerializable;
208206
pub fn fixed_size_test<O: BinarySerializable + FixedSize + Default>() {
209207
let mut buffer = Vec::new();

common/src/vint.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use super::BinarySerializable;
2-
use byteorder::{ByteOrder, LittleEndian};
31
use std::io;
4-
use std::io::Read;
5-
use std::io::Write;
2+
use std::io::{Read, Write};
3+
4+
use byteorder::{ByteOrder, LittleEndian};
5+
6+
use super::BinarySerializable;
67

78
/// Wrapper over a `u64` that serializes as a variable int.
89
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -174,9 +175,7 @@ impl BinarySerializable for VInt {
174175
#[cfg(test)]
175176
mod tests {
176177

177-
use super::serialize_vint_u32;
178-
use super::BinarySerializable;
179-
use super::VInt;
178+
use super::{serialize_vint_u32, BinarySerializable, VInt};
180179

181180
fn aux_test_vint(val: u64) {
182181
let mut v = [14u8; 10];

common/src/writer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl<W: TerminatingWrite> TerminatingWrite for CountingWriter<W> {
5454
}
5555
}
5656

57-
/// Struct used to prevent from calling [`terminate_ref`](trait.TerminatingWrite.html#tymethod.terminate_ref) directly
57+
/// Struct used to prevent from calling
58+
/// [`terminate_ref`](trait.TerminatingWrite.html#tymethod.terminate_ref) directly
5859
///
5960
/// The point is that while the type is public, it cannot be built by anyone
6061
/// outside of this module.
@@ -64,9 +65,7 @@ pub struct AntiCallToken(());
6465
pub trait TerminatingWrite: Write {
6566
/// Indicate that the writer will no longer be used. Internally call terminate_ref.
6667
fn terminate(mut self) -> io::Result<()>
67-
where
68-
Self: Sized,
69-
{
68+
where Self: Sized {
7069
self.terminate_ref(AntiCallToken(()))
7170
}
7271

@@ -97,9 +96,10 @@ impl<'a> TerminatingWrite for &'a mut Vec<u8> {
9796
#[cfg(test)]
9897
mod test {
9998

100-
use super::CountingWriter;
10199
use std::io::Write;
102100

101+
use super::CountingWriter;
102+
103103
#[test]
104104
fn test_counting_writer() {
105105
let buffer: Vec<u8> = vec![];

examples/basic_search.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ fn main() -> tantivy::Result<()> {
9191
old_man_doc.add_text(title, "The Old Man and the Sea");
9292
old_man_doc.add_text(
9393
body,
94-
"He was an old man who fished alone in a skiff in the Gulf Stream and \
95-
he had gone eighty-four days now without taking a fish.",
94+
"He was an old man who fished alone in a skiff in the Gulf Stream and he had gone \
95+
eighty-four days now without taking a fish.",
9696
);
9797

9898
// ... and add it to the `IndexWriter`.

examples/custom_collector.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use tantivy::collector::{Collector, SegmentCollector};
1313
use tantivy::fastfield::{DynamicFastFieldReader, FastFieldReader};
1414
use tantivy::query::QueryParser;
15-
use tantivy::schema::Field;
16-
use tantivy::schema::{Schema, FAST, INDEXED, TEXT};
15+
use tantivy::schema::{Field, Schema, FAST, INDEXED, TEXT};
1716
use tantivy::{doc, Index, Score, SegmentReader};
1817

1918
#[derive(Default)]

0 commit comments

Comments
 (0)