Skip to content

Commit

Permalink
Use FnvHashMap for keyed bucket entries
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yomo committed Jul 26, 2022
1 parent 5ab5f07 commit 80a1418
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/aggregation/agg_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::collections::HashMap;

use fnv::FnvHashMap;
use serde::{Deserialize, Serialize};

use super::agg_req::BucketAggregationInternal;
Expand Down Expand Up @@ -145,7 +146,7 @@ pub enum BucketEntries<T> {
/// Vector format bucket entries
Vec(Vec<T>),
/// HashMap format bucket entries
HashMap(HashMap<String, T>),
HashMap(FnvHashMap<String, T>),
}

/// This is the default entry for a bucket, which contains a key, count, and optionally
Expand Down
6 changes: 4 additions & 2 deletions src/aggregation/intermediate_agg_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ impl IntermediateBucketResult {
.expect("unexpected aggregation, expected range aggregation")
.keyed;
let buckets = if is_keyed {
let mut bucket_map = HashMap::new();
let mut bucket_map =
FnvHashMap::with_capacity_and_hasher(buckets.len(), Default::default());
for bucket in buckets {
bucket_map.insert(bucket.key.to_string(), bucket);
}
Expand All @@ -306,7 +307,8 @@ impl IntermediateBucketResult {
)?;

let buckets = if req.as_histogram().unwrap().keyed {
let mut bucket_map = HashMap::new();
let mut bucket_map =
FnvHashMap::with_capacity_and_hasher(buckets.len(), Default::default());
for bucket in buckets {
bucket_map.insert(bucket.key.to_string(), bucket);
}
Expand Down

0 comments on commit 80a1418

Please sign in to comment.