2019-05-06 14:25:11 +02:00
|
|
|
use std::io::{Read, Write};
|
|
|
|
|
2019-03-29 17:38:57 +01:00
|
|
|
use hashbrown::HashMap;
|
|
|
|
use meilidb_core::DocumentId;
|
2019-05-06 14:25:11 +02:00
|
|
|
|
2019-03-29 17:38:57 +01:00
|
|
|
use crate::{SchemaAttr, Number};
|
|
|
|
|
2019-05-06 14:25:11 +02:00
|
|
|
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
|
|
|
pub struct RankedMap(HashMap<(DocumentId, SchemaAttr), Number>);
|
|
|
|
|
|
|
|
impl RankedMap {
|
|
|
|
pub fn insert(&mut self, document: DocumentId, attribute: SchemaAttr, number: Number) {
|
|
|
|
self.0.insert((document, attribute), number);
|
|
|
|
}
|
|
|
|
|
2019-05-21 13:26:49 +02:00
|
|
|
pub fn remove(&mut self, document: DocumentId, attribute: SchemaAttr) {
|
|
|
|
self.0.remove(&(document, attribute));
|
|
|
|
}
|
|
|
|
|
2019-05-06 14:25:11 +02:00
|
|
|
pub fn get(&self, document: DocumentId, attribute: SchemaAttr) -> Option<Number> {
|
|
|
|
self.0.get(&(document, attribute)).cloned()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn read_from_bin<R: Read>(reader: R) -> bincode::Result<RankedMap> {
|
|
|
|
bincode::deserialize_from(reader).map(RankedMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn write_to_bin<W: Write>(&self, writer: W) -> bincode::Result<()> {
|
|
|
|
bincode::serialize_into(writer, &self.0)
|
|
|
|
}
|
|
|
|
}
|