Return reference in index_column.get()
This commit is contained in:
parent
f0d29eb399
commit
b04f3d167b
3 changed files with 6 additions and 8 deletions
|
|
@ -12,11 +12,8 @@ impl ColumnIndex {
|
|||
Self { index }
|
||||
}
|
||||
|
||||
pub fn get(&self, value: &IndexableValue) -> HashSet<Uuid> {
|
||||
match self.index.get(value) {
|
||||
Some(set) => set.clone(),
|
||||
None => HashSet::new(),
|
||||
}
|
||||
pub fn get(&self, value: &IndexableValue) -> Option<&HashSet<Uuid>> {
|
||||
self.index.get(value)
|
||||
}
|
||||
|
||||
pub fn add(&mut self, value: IndexableValue, id: Uuid) {
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ impl Table {
|
|||
} else {
|
||||
match self.indexes.get(&column_position) {
|
||||
Some(index) => {
|
||||
let ids = index.get(value);
|
||||
Ok(Some(ids))
|
||||
let ids = index.get(value).cloned();
|
||||
Ok(ids)
|
||||
}
|
||||
None => Ok(None),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ trait SqlResponseConsumer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn users_schema() -> TableSchema {
|
||||
let id: ColumnPosition = 0;
|
||||
|
|
@ -505,7 +506,7 @@ mod tests {
|
|||
let plato_id = 0;
|
||||
let aristotle_id = 1;
|
||||
|
||||
let plato_ids = index.get(&String("Plato".to_string()));
|
||||
let plato_ids = index.get(&String("Plato".to_string())).cloned().unwrap_or(HashSet::new());
|
||||
assert!(plato_ids.contains(&plato_id));
|
||||
assert!(!plato_ids.contains(&aristotle_id));
|
||||
assert!(plato_ids.len() == 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue