Skip to content

Commit 19a859d

Browse files
authored
term hashmap remove copy in is_empty, unused unordered_id (#2229)
1 parent 83af14c commit 19a859d

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

columnar/src/columnar/writer/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl ColumnarWriter {
338338
let mut columns: Vec<(&[u8], ColumnType, Addr)> = self
339339
.numerical_field_hash_map
340340
.iter()
341-
.map(|(column_name, addr, _)| {
341+
.map(|(column_name, addr)| {
342342
let numerical_column_writer: NumericalColumnWriter =
343343
self.numerical_field_hash_map.read(addr);
344344
let column_type = numerical_column_writer.numerical_type().into();
@@ -348,27 +348,27 @@ impl ColumnarWriter {
348348
columns.extend(
349349
self.bytes_field_hash_map
350350
.iter()
351-
.map(|(term, addr, _)| (term, ColumnType::Bytes, addr)),
351+
.map(|(term, addr)| (term, ColumnType::Bytes, addr)),
352352
);
353353
columns.extend(
354354
self.str_field_hash_map
355355
.iter()
356-
.map(|(column_name, addr, _)| (column_name, ColumnType::Str, addr)),
356+
.map(|(column_name, addr)| (column_name, ColumnType::Str, addr)),
357357
);
358358
columns.extend(
359359
self.bool_field_hash_map
360360
.iter()
361-
.map(|(column_name, addr, _)| (column_name, ColumnType::Bool, addr)),
361+
.map(|(column_name, addr)| (column_name, ColumnType::Bool, addr)),
362362
);
363363
columns.extend(
364364
self.ip_addr_field_hash_map
365365
.iter()
366-
.map(|(column_name, addr, _)| (column_name, ColumnType::IpAddr, addr)),
366+
.map(|(column_name, addr)| (column_name, ColumnType::IpAddr, addr)),
367367
);
368368
columns.extend(
369369
self.datetime_field_hash_map
370370
.iter()
371-
.map(|(column_name, addr, _)| (column_name, ColumnType::DateTime, addr)),
371+
.map(|(column_name, addr)| (column_name, ColumnType::DateTime, addr)),
372372
);
373373
columns.sort_unstable_by_key(|(column_name, col_type, _)| (*column_name, *col_type));
374374

src/indexer/segment_writer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,9 @@ mod tests {
510510

511511
#[test]
512512
fn test_hashmap_size() {
513-
assert_eq!(compute_initial_table_size(100_000).unwrap(), 1 << 11);
514-
assert_eq!(compute_initial_table_size(1_000_000).unwrap(), 1 << 14);
515-
assert_eq!(compute_initial_table_size(15_000_000).unwrap(), 1 << 18);
513+
assert_eq!(compute_initial_table_size(100_000).unwrap(), 1 << 12);
514+
assert_eq!(compute_initial_table_size(1_000_000).unwrap(), 1 << 15);
515+
assert_eq!(compute_initial_table_size(15_000_000).unwrap(), 1 << 19);
516516
assert_eq!(compute_initial_table_size(1_000_000_000).unwrap(), 1 << 19);
517517
assert_eq!(compute_initial_table_size(4_000_000_000).unwrap(), 1 << 19);
518518
}

src/postings/postings_writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(crate) fn serialize_postings(
5353
term_offsets.extend(
5454
ctx.term_index
5555
.iter()
56-
.map(|(bytes, addr, _unordered_id)| (Term::wrap(bytes), addr)),
56+
.map(|(bytes, addr)| (Term::wrap(bytes), addr)),
5757
);
5858
term_offsets.sort_unstable_by_key(|(k, _)| k.clone());
5959

stacker/src/arena_hashmap.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::mem;
44
use super::{Addr, MemoryArena};
55
use crate::fastcpy::fast_short_slice_copy;
66
use crate::memory_arena::store;
7-
use crate::UnorderedId;
87

98
/// Returns the actual memory size in bytes
109
/// required to create a table with a given capacity.
@@ -26,22 +25,20 @@ type HashType = u64;
2625
struct KeyValue {
2726
key_value_addr: Addr,
2827
hash: HashType,
29-
unordered_id: UnorderedId,
3028
}
3129

3230
impl Default for KeyValue {
3331
fn default() -> Self {
3432
KeyValue {
3533
key_value_addr: Addr::null_pointer(),
3634
hash: 0,
37-
unordered_id: UnorderedId::default(),
3835
}
3936
}
4037
}
4138

4239
impl KeyValue {
4340
#[inline]
44-
fn is_empty(self) -> bool {
41+
fn is_empty(&self) -> bool {
4542
self.key_value_addr.is_null()
4643
}
4744
#[inline]
@@ -96,12 +93,12 @@ pub struct Iter<'a> {
9693
}
9794

9895
impl<'a> Iterator for Iter<'a> {
99-
type Item = (&'a [u8], Addr, UnorderedId);
96+
type Item = (&'a [u8], Addr);
10097

10198
fn next(&mut self) -> Option<Self::Item> {
10299
self.inner.next().map(move |kv| {
103100
let (key, offset): (&'a [u8], Addr) = self.hashmap.get_key_value(kv.key_value_addr);
104-
(key, offset, kv.unordered_id)
101+
(key, offset)
105102
})
106103
}
107104
}
@@ -207,16 +204,13 @@ impl ArenaHashMap {
207204
}
208205

209206
#[inline]
210-
fn set_bucket(&mut self, hash: HashType, key_value_addr: Addr, bucket: usize) -> UnorderedId {
211-
let unordered_id = self.len as UnorderedId;
207+
fn set_bucket(&mut self, hash: HashType, key_value_addr: Addr, bucket: usize) {
212208
self.len += 1;
213209

214210
self.table[bucket] = KeyValue {
215211
key_value_addr,
216212
hash,
217-
unordered_id,
218213
};
219-
unordered_id
220214
}
221215

222216
#[inline]
@@ -290,14 +284,8 @@ impl ArenaHashMap {
290284
/// If the key already as an associated value, then it will be passed
291285
/// `Some(previous_value)`.
292286
#[inline]
293-
pub fn mutate_or_create<V>(
294-
&mut self,
295-
key: &[u8],
296-
mut updater: impl FnMut(Option<V>) -> V,
297-
) -> UnorderedId
298-
where
299-
V: Copy + 'static,
300-
{
287+
pub fn mutate_or_create<V>(&mut self, key: &[u8], mut updater: impl FnMut(Option<V>) -> V)
288+
where V: Copy + 'static {
301289
if self.is_saturated() {
302290
self.resize();
303291
}
@@ -320,14 +308,15 @@ impl ArenaHashMap {
320308
store(&mut data[stop..], val);
321309
}
322310

323-
return self.set_bucket(hash, key_addr, bucket);
311+
self.set_bucket(hash, key_addr, bucket);
312+
return;
324313
}
325314
if kv.hash == hash {
326315
if let Some(val_addr) = self.get_value_addr_if_key_match(key, kv.key_value_addr) {
327316
let v = self.memory_arena.read(val_addr);
328317
let new_v = updater(Some(v));
329318
self.memory_arena.write_at(val_addr, new_v);
330-
return kv.unordered_id;
319+
return;
331320
}
332321
}
333322
// This allows fetching the next bucket before the loop jmp
@@ -361,7 +350,7 @@ mod tests {
361350
});
362351
let mut vanilla_hash_map = HashMap::new();
363352
let iter_values = hash_map.iter();
364-
for (key, addr, _) in iter_values {
353+
for (key, addr) in iter_values {
365354
let val: u32 = hash_map.memory_arena.read(addr);
366355
vanilla_hash_map.insert(key.to_owned(), val);
367356
}
@@ -390,7 +379,7 @@ mod tests {
390379
}
391380
let mut terms_back: Vec<String> = hash_map
392381
.iter()
393-
.map(|(bytes, _, _)| String::from_utf8(bytes.to_vec()).unwrap())
382+
.map(|(bytes, _)| String::from_utf8(bytes.to_vec()).unwrap())
394383
.collect();
395384
terms_back.sort();
396385
terms.sort();

0 commit comments

Comments
 (0)