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 }
|
Self { index }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(&self, value: &IndexableValue) -> HashSet<Uuid> {
|
pub fn get(&self, value: &IndexableValue) -> Option<&HashSet<Uuid>> {
|
||||||
match self.index.get(value) {
|
self.index.get(value)
|
||||||
Some(set) => set.clone(),
|
|
||||||
None => HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add(&mut self, value: IndexableValue, id: Uuid) {
|
pub fn add(&mut self, value: IndexableValue, id: Uuid) {
|
||||||
|
|
|
||||||
|
|
@ -218,8 +218,8 @@ impl Table {
|
||||||
} else {
|
} else {
|
||||||
match self.indexes.get(&column_position) {
|
match self.indexes.get(&column_position) {
|
||||||
Some(index) => {
|
Some(index) => {
|
||||||
let ids = index.get(value);
|
let ids = index.get(value).cloned();
|
||||||
Ok(Some(ids))
|
Ok(ids)
|
||||||
}
|
}
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,7 @@ trait SqlResponseConsumer {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
fn users_schema() -> TableSchema {
|
fn users_schema() -> TableSchema {
|
||||||
let id: ColumnPosition = 0;
|
let id: ColumnPosition = 0;
|
||||||
|
|
@ -505,7 +506,7 @@ mod tests {
|
||||||
let plato_id = 0;
|
let plato_id = 0;
|
||||||
let aristotle_id = 1;
|
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(&plato_id));
|
||||||
assert!(!plato_ids.contains(&aristotle_id));
|
assert!(!plato_ids.contains(&aristotle_id));
|
||||||
assert!(plato_ids.len() == 1);
|
assert!(plato_ids.len() == 1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue