mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-06-02 00:20:42 +00:00
BytesRef is now wrapping an addr
This commit is contained in:
@@ -148,7 +148,7 @@ impl<'a> HashMap<'a> {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn iter<'b: 'a>(&'b self) -> impl Iterator<Item=(&'a [u8], u32)> + 'b {
|
||||
pub fn iter<'b: 'a>(&'b self) -> impl Iterator<Item = (&'a [u8], u32)> + 'b {
|
||||
let heap: &'a Heap = self.heap;
|
||||
let table: &'b [KeyValue] = &self.table;
|
||||
self.occupied
|
||||
@@ -175,12 +175,12 @@ impl<'a> HashMap<'a> {
|
||||
let (addr, val): (u32, &mut V) = self.heap.allocate_object();
|
||||
assert_eq!(addr, key_bytes_ref.addr() + 2 + key_bytes.len() as u32);
|
||||
self.set_bucket(hash, key_bytes_ref, bucket);
|
||||
return val
|
||||
}
|
||||
if kv.hash == hash {
|
||||
return val;
|
||||
} else if kv.hash == hash {
|
||||
let stored_key: &[u8] = self.get_key(kv.key);
|
||||
if stored_key == key_bytes {
|
||||
return self.heap.get_mut_ref(kv.key.addr() + 2 + stored_key.len() as u32);
|
||||
let expull_addr = kv.key.addr() + 2 + stored_key.len() as u32;
|
||||
return self.heap.get_mut_ref(expull_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,11 +166,10 @@ impl InnerHeap {
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.get_slice(BytesRef(start - self.buffer_len))
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
let start = start as usize;
|
||||
let len = NativeEndian::read_u16(&self.buffer[start..start + 2]) as usize;
|
||||
&self.buffer[start + 2.. start + 2 + len]
|
||||
&self.buffer[start + 2..start + 2 + len]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,38 +9,39 @@ pub use self::hashmap::HashMap;
|
||||
|
||||
|
||||
|
||||
// #[test]
|
||||
// fn test_unrolled_linked_list() {
|
||||
// let heap = Heap::with_capacity(30_000_000);
|
||||
// {
|
||||
// heap.clear();
|
||||
// let mut ks: Vec<usize> = (1..5).map(|k| k * 100).collect();
|
||||
// ks.push(2);
|
||||
// ks.push(3);
|
||||
// for k in (1..5).map(|k| k * 100) {
|
||||
// let mut hashmap: HashMap = HashMap::new(10, &heap);
|
||||
// for j in 0..k {
|
||||
// for i in 0..500 {
|
||||
// let mut list: &mut ExpUnrolledLinkedList = hashmap.get_or_create(i.to_string());
|
||||
// list.push(i * j, &heap);
|
||||
// }
|
||||
// }
|
||||
// for i in 0..500 {
|
||||
// match hashmap.lookup(i.to_string()) {
|
||||
// Entry::Occupied(addr) => {
|
||||
// let v: &mut ExpUnrolledLinkedList = heap.get_mut_ref(addr);
|
||||
// let mut it = v.iter(addr, &heap);
|
||||
// for j in 0..k {
|
||||
// assert_eq!(it.next().unwrap(), i * j);
|
||||
// }
|
||||
// assert!(!it.next().is_some());
|
||||
// }
|
||||
// _ => {
|
||||
// panic!("should never happen");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
#[test]
|
||||
fn test_unrolled_linked_list() {
|
||||
use std::collections;
|
||||
let heap = Heap::with_capacity(30_000_000);
|
||||
{
|
||||
heap.clear();
|
||||
let mut ks: Vec<usize> = (1..5).map(|k| k * 100).collect();
|
||||
ks.push(2);
|
||||
ks.push(3);
|
||||
for k in (1..5).map(|k| k * 100) {
|
||||
let mut hashmap: HashMap = HashMap::new(10, &heap);
|
||||
for j in 0..k {
|
||||
for i in 0..500 {
|
||||
let v: &mut ExpUnrolledLinkedList = hashmap.get_or_create(i.to_string());
|
||||
v.push(i * j, &heap);
|
||||
}
|
||||
}
|
||||
let mut map_addr: collections::HashMap<Vec<u8>, u32> = collections::HashMap::new();
|
||||
for (key, addr) in hashmap.iter() {
|
||||
map_addr.insert(Vec::from(key), addr);
|
||||
}
|
||||
|
||||
// }
|
||||
// }
|
||||
for i in 0..500 {
|
||||
let key: String = i.to_string();
|
||||
let addr: u32 = *map_addr.get(key.as_bytes()).unwrap();
|
||||
let exp_pull: &ExpUnrolledLinkedList = heap.get_ref(addr);
|
||||
let mut it = exp_pull.iter(addr, &heap);
|
||||
for j in 0..k {
|
||||
assert_eq!(it.next().unwrap(), i * j);
|
||||
}
|
||||
assert!(!it.next().is_some());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user