Compressing word fields
This commit is contained in:
1 parent
e5622c70de
commit
0de809fcce
4 files changed
+121
-81
No files matched your search
@@ -1,9 +1,9 @@
|
||||
use litemap::LiteMap;
|
||||
use crate::data::entities::WordData;
|
||||
use crate::data::repositories::{DataRepository, DataRepositoryInner};
|
||||
use crate::data::Id;
|
||||
use crate::data_provider::{SqliteDbLayer, TableAccessQuerySet};
|
||||
use litemap::LiteMap;
|
||||
use rusqlite::{Error, Params, Row};
|
||||
use crate::data::{Id, SmallId};
|
||||
|
||||
pub type WordRepository = DataRepository<WordData, WordDataLayer>;
|
||||
pub type WordRepositoryInner = DataRepositoryInner<WordData, WordDataLayer>;
|
||||
@@ -61,7 +61,7 @@ impl TableAccessQuerySet<WordData> for WordQuerySet {
|
||||
}
|
||||
|
||||
fn additional_to_string(map: &LiteMap<Id, String>) -> String {
|
||||
let mut parts = vec![];
|
||||
let mut parts = Vec::with_capacity(map.len() * 2);
|
||||
for (id, value) in map {
|
||||
parts.push(id.to_string());
|
||||
parts.push(value.clone());
|
||||
@@ -69,7 +69,20 @@ fn additional_to_string(map: &LiteMap<Id, String>) -> String {
|
||||
parts.join("")
|
||||
}
|
||||
|
||||
fn additional_from_string_temp(data: String) -> LiteMap<Id, String> {
|
||||
|
||||
let pre_map : LiteMap<String, String> = serde_json::from_str(data.as_str()).unwrap();
|
||||
LiteMap::from(pre_map.iter().map(|(k, v)| (match k.as_str() {
|
||||
"reading" => Id(1),
|
||||
"description" => Id(2),
|
||||
"context" => Id(3),
|
||||
&_ => Id(0) }, v.to_string())).collect())
|
||||
}
|
||||
|
||||
fn additional_from_string(data: String) -> LiteMap<Id, String> {
|
||||
if data.is_empty() {
|
||||
return LiteMap::new()
|
||||
}
|
||||
let parts = data.split('').collect::<Vec<&str>>();
|
||||
let chunks = parts.chunks(2).collect::<Vec<&[&str]>>();
|
||||
let mut map = LiteMap::with_capacity(parts.len());
|
||||
|
||||
Reference in new issue
Block a user