mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-03 15:52:55 +00:00
fixed args for simd stuff.
This commit is contained in:
@@ -8,15 +8,17 @@ pub trait Collector {
|
||||
fn collect(&mut self, doc_id: DocId);
|
||||
}
|
||||
|
||||
pub struct TestCollector {
|
||||
pub struct FirstNCollector {
|
||||
docs: Vec<DocAddress>,
|
||||
current_segment: Option<SegmentId>,
|
||||
limit: usize,
|
||||
}
|
||||
|
||||
impl TestCollector {
|
||||
pub fn new() -> TestCollector {
|
||||
TestCollector {
|
||||
impl FirstNCollector {
|
||||
pub fn with_limit(limit: usize) -> FirstNCollector {
|
||||
FirstNCollector {
|
||||
docs: Vec::new(),
|
||||
limit: limit,
|
||||
current_segment: None,
|
||||
}
|
||||
}
|
||||
@@ -26,13 +28,75 @@ impl TestCollector {
|
||||
}
|
||||
}
|
||||
|
||||
impl Collector for TestCollector {
|
||||
impl Collector for FirstNCollector {
|
||||
|
||||
fn set_segment(&mut self, segment: &SegmentReader) {
|
||||
self.current_segment = Some(segment.id());
|
||||
}
|
||||
|
||||
fn collect(&mut self, doc_id: DocId) {
|
||||
self.docs.push(DocAddress(self.current_segment.clone().unwrap(), doc_id));
|
||||
if self.docs.len() < self.limit {
|
||||
self.docs.push(DocAddress(self.current_segment.clone().unwrap(), doc_id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
|
||||
pub struct CountCollector {
|
||||
count: usize,
|
||||
}
|
||||
|
||||
impl CountCollector {
|
||||
pub fn new() -> CountCollector {
|
||||
CountCollector {
|
||||
count: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn count(&self,) -> usize {
|
||||
self.count
|
||||
}
|
||||
}
|
||||
|
||||
impl Collector for CountCollector {
|
||||
|
||||
fn set_segment(&mut self, segment: &SegmentReader) {
|
||||
}
|
||||
|
||||
fn collect(&mut self, doc_id: DocId) {
|
||||
self.count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pub struct MultiCollector<'a> {
|
||||
collectors: Vec<&'a mut Collector>,
|
||||
}
|
||||
|
||||
impl<'a> MultiCollector<'a> {
|
||||
pub fn from(collectors: Vec<&'a mut Collector>) -> MultiCollector {
|
||||
MultiCollector {
|
||||
collectors: collectors,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Collector for MultiCollector<'a> {
|
||||
|
||||
fn set_segment(&mut self, segment: &SegmentReader) {
|
||||
for collector in self.collectors.iter_mut() {
|
||||
collector.set_segment(segment);
|
||||
}
|
||||
}
|
||||
|
||||
fn collect(&mut self, doc_id: DocId) {
|
||||
for collector in self.collectors.iter_mut() {
|
||||
collector.collect(doc_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
use libc::size_t;
|
||||
use std::ptr;
|
||||
|
||||
// #[link(name = "simdcompression", kind = "static")]
|
||||
extern {
|
||||
fn encode_native(data: *mut u32, num_els: size_t, output: *mut u32) -> size_t;
|
||||
fn encode_native(data: *mut u32, num_els: size_t, output: *mut u32, output_capacity: size_t) -> size_t;
|
||||
fn decode_native(compressed_data: *const u32, compressed_size: size_t, uncompressed: *mut u32, output_capacity: size_t) -> size_t;
|
||||
}
|
||||
|
||||
@@ -27,8 +26,8 @@ impl Encoder {
|
||||
self.input_buffer.clear();
|
||||
let input_len = input.len();
|
||||
if input_len + 10000 >= self.input_buffer.len() {
|
||||
self.input_buffer = (0..input_len as u32 + 10000).collect();
|
||||
self.output_buffer = (0..input_len as u32 + 10000).collect();
|
||||
self.input_buffer = (0..(input_len as u32) + 1024).collect();
|
||||
self.output_buffer = (0..(input_len as u32) + 1024).collect();
|
||||
// TODO use resize when available
|
||||
}
|
||||
// TODO use clone_from when available
|
||||
@@ -37,7 +36,8 @@ impl Encoder {
|
||||
let written_size = encode_native(
|
||||
self.input_buffer.as_mut_ptr(),
|
||||
input_len as size_t,
|
||||
self.output_buffer.as_mut_ptr()
|
||||
self.output_buffer.as_mut_ptr(),
|
||||
self.output_buffer.len() as size_t,
|
||||
);
|
||||
return &self.output_buffer[0..written_size];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,37 @@ use tantivy::core::reader::SegmentReader;
|
||||
use regex::Regex;
|
||||
|
||||
|
||||
|
||||
pub struct TestCollector {
|
||||
docs: Vec<DocAddress>,
|
||||
current_segment: Option<SegmentId>,
|
||||
}
|
||||
|
||||
impl TestCollector {
|
||||
pub fn new() -> TestCollector {
|
||||
TestCollector {
|
||||
docs: Vec::new(),
|
||||
current_segment: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn docs(self,) -> Vec<DocAddress> {
|
||||
self.docs
|
||||
}
|
||||
}
|
||||
|
||||
impl Collector for TestCollector {
|
||||
|
||||
fn set_segment(&mut self, segment: &SegmentReader) {
|
||||
self.current_segment = Some(segment.id());
|
||||
}
|
||||
|
||||
fn collect(&mut self, doc_id: DocId) {
|
||||
self.docs.push(DocAddress(self.current_segment.clone().unwrap(), doc_id));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_indexing() {
|
||||
let mut schema = Schema::new();
|
||||
|
||||
Reference in New Issue
Block a user