Skip to content

Commit 74e7c87

Browse files
committed
Fix formatting
1 parent d5693bb commit 74e7c87

69 files changed

Lines changed: 1092 additions & 989 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

capi/src/data.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ pub type IterPtr<T> = Box<dyn Iterator<Item = Result<T>>>;
4949
fn iter_next<T>(ptr: *mut Box<dyn Iterator<Item = Result<T>>>, err: *mut *mut ErrorList) -> *mut T {
5050
let it: &mut Box<dyn Iterator<Item = Result<T>>> = cast_mut(ptr);
5151
if let Some(v) = it.next()
52-
&& let Some(v) = map_cerr(v, err) {
53-
return Box::into_raw(Box::new(v));
54-
}
52+
&& let Some(v) = map_cerr(v, err)
53+
{
54+
return Box::into_raw(Box::new(v));
55+
}
5556
std::ptr::null_mut()
5657
}
5758

cli/src/bin/annis_bench_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ extern crate graphannis;
55

66
use clap::*;
77
use criterion::BenchmarkGroup;
8-
use criterion::{measurement::Measurement, Criterion};
8+
use criterion::{Criterion, measurement::Measurement};
99
use std::collections::BTreeSet;
1010
use std::path::{Path, PathBuf};
1111
use std::time::Duration;
1212

1313
use std::sync::Arc;
1414

15+
use graphannis::CorpusStorage;
1516
use graphannis::corpusstorage::{QueryLanguage, SearchQuery};
1617
use graphannis::util::{self, SearchDef};
17-
use graphannis::CorpusStorage;
1818

1919
pub fn create_query_input<M>(
2020
data_dir: &Path,

core/src/annostorage/inmemory.rs

Lines changed: 134 additions & 128 deletions
Large diffs are not rendered by default.

core/src/annostorage/ondisk.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,10 @@ where
707707
})
708708
.filter_map_ok(move |(item, anno_key, item_value)| {
709709
if let Some(item_value) = item_value
710-
&& item_value != value {
711-
return Some((item, anno_key).into());
712-
}
710+
&& item_value != value
711+
{
712+
return Some((item, anno_key).into());
713+
}
713714
None
714715
});
715716
Box::new(it)
@@ -940,27 +941,27 @@ where
940941
.copied()
941942
.unwrap_or_default();
942943
if let Some(histo) = self.histogram_bounds.get(&anno_key)
943-
&& !histo.is_empty() {
944-
let sampled_values = histo.iter().choose_multiple(&mut rng, 20);
945-
946-
let matches = sampled_values
947-
.iter()
948-
.filter(|v| pattern.is_match(v))
949-
.count();
950-
if sampled_values.len() == matches {
951-
// Assume all values match
952-
guessed_count += anno_size;
953-
} else if matches == 0 {
954-
// No match found, but use the bucket size as pessimistic guess
955-
guessed_count +=
956-
(anno_size as f64 / sampled_values.len() as f64) as usize;
957-
} else {
958-
// Use the percent of matched values to guess the overall number
959-
let match_ratio =
960-
(matches as f64) / (sampled_values.len() as f64);
961-
guessed_count += ((anno_size as f64) * match_ratio) as usize;
962-
}
944+
&& !histo.is_empty()
945+
{
946+
let sampled_values = histo.iter().choose_multiple(&mut rng, 20);
947+
948+
let matches = sampled_values
949+
.iter()
950+
.filter(|v| pattern.is_match(v))
951+
.count();
952+
if sampled_values.len() == matches {
953+
// Assume all values match
954+
guessed_count += anno_size;
955+
} else if matches == 0 {
956+
// No match found, but use the bucket size as pessimistic guess
957+
guessed_count +=
958+
(anno_size as f64 / sampled_values.len() as f64) as usize;
959+
} else {
960+
// Use the percent of matched values to guess the overall number
961+
let match_ratio = (matches as f64) / (sampled_values.len() as f64);
962+
guessed_count += ((anno_size as f64) * match_ratio) as usize;
963963
}
964+
}
964965
}
965966
}
966967
}

core/src/annostorage/symboltable.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,19 @@ where
8484

8585
pub fn get_value(&self, id: usize) -> Option<Arc<T>> {
8686
if id < self.by_id.len()
87-
&& let Some(ref val) = self.by_id[id] {
88-
return Some(val.clone());
89-
}
87+
&& let Some(ref val) = self.by_id[id]
88+
{
89+
return Some(val.clone());
90+
}
9091
None
9192
}
9293

9394
pub fn get_value_ref(&self, id: usize) -> Option<&T> {
9495
if id < self.by_id.len()
95-
&& let Some(ref val) = self.by_id[id] {
96-
return Some(val.as_ref());
97-
}
96+
&& let Some(ref val) = self.by_id[id]
97+
{
98+
return Some(val.as_ref());
99+
}
98100
None
99101
}
100102

core/src/dfs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl<'a> CycleSafeDFS<'a> {
113113
}
114114
trace!(
115115
"enter_node finished with result {} for node {}",
116-
found,
117-
node
116+
found, node
118117
);
119118
Ok(found)
120119
}

core/src/graph/mod.rs

Lines changed: 78 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -521,11 +521,12 @@ impl<CT: ComponentType> Graph<CT> {
521521
)?;
522522
// only add edge if both nodes already exist
523523
if let (Some(source), Some(target)) = (source, target)
524-
&& let Ok(ctype) = CT::from_str(component_type) {
525-
let c = Component::new(ctype, layer.into(), component_name.into());
526-
let gs = self.get_or_create_writable(&c)?;
527-
gs.add_edge(Edge { source, target })?;
528-
}
524+
&& let Ok(ctype) = CT::from_str(component_type)
525+
{
526+
let c = Component::new(ctype, layer.into(), component_name.into());
527+
let gs = self.get_or_create_writable(&c)?;
528+
gs.add_edge(Edge { source, target })?;
529+
}
529530
}
530531
UpdateEvent::DeleteEdge {
531532
source_node,
@@ -543,12 +544,13 @@ impl<CT: ComponentType> Graph<CT> {
543544
&mut node_id_cache,
544545
)?;
545546
if let (Some(source), Some(target)) = (source, target)
546-
&& let Ok(ctype) = CT::from_str(component_type) {
547-
let c = Component::new(ctype, layer.into(), component_name.into());
547+
&& let Ok(ctype) = CT::from_str(component_type)
548+
{
549+
let c = Component::new(ctype, layer.into(), component_name.into());
548550

549-
let gs = self.get_or_create_writable(&c)?;
550-
gs.delete_edge(&Edge { source, target })?;
551-
}
551+
let gs = self.get_or_create_writable(&c)?;
552+
gs.delete_edge(&Edge { source, target })?;
553+
}
552554
}
553555
UpdateEvent::AddEdgeLabel {
554556
source_node,
@@ -569,22 +571,23 @@ impl<CT: ComponentType> Graph<CT> {
569571
&mut node_id_cache,
570572
)?;
571573
if let (Some(source), Some(target)) = (source, target)
572-
&& let Ok(ctype) = CT::from_str(component_type) {
573-
let c = Component::new(ctype, layer.into(), component_name.into());
574-
let gs = self.get_or_create_writable(&c)?;
575-
// only add label if the edge already exists
576-
let e = Edge { source, target };
577-
if gs.is_connected(source, target, 1, Included(1))? {
578-
let anno = Annotation {
579-
key: AnnoKey {
580-
ns: anno_ns.into(),
581-
name: anno_name.into(),
582-
},
583-
val: anno_value.into(),
584-
};
585-
gs.add_edge_annotation(e, anno)?;
586-
}
574+
&& let Ok(ctype) = CT::from_str(component_type)
575+
{
576+
let c = Component::new(ctype, layer.into(), component_name.into());
577+
let gs = self.get_or_create_writable(&c)?;
578+
// only add label if the edge already exists
579+
let e = Edge { source, target };
580+
if gs.is_connected(source, target, 1, Included(1))? {
581+
let anno = Annotation {
582+
key: AnnoKey {
583+
ns: anno_ns.into(),
584+
name: anno_name.into(),
585+
},
586+
val: anno_value.into(),
587+
};
588+
gs.add_edge_annotation(e, anno)?;
587589
}
590+
}
588591
}
589592
UpdateEvent::DeleteEdgeLabel {
590593
source_node,
@@ -604,19 +607,20 @@ impl<CT: ComponentType> Graph<CT> {
604607
&mut node_id_cache,
605608
)?;
606609
if let (Some(source), Some(target)) = (source, target)
607-
&& let Ok(ctype) = CT::from_str(component_type) {
608-
let c = Component::new(ctype, layer.into(), component_name.into());
609-
let gs = self.get_or_create_writable(&c)?;
610-
// only add label if the edge already exists
611-
let e = Edge { source, target };
612-
if gs.is_connected(source, target, 1, Included(1))? {
613-
let key = AnnoKey {
614-
ns: anno_ns.into(),
615-
name: anno_name.into(),
616-
};
617-
gs.delete_edge_annotation(&e, &key)?;
618-
}
610+
&& let Ok(ctype) = CT::from_str(component_type)
611+
{
612+
let c = Component::new(ctype, layer.into(), component_name.into());
613+
let gs = self.get_or_create_writable(&c)?;
614+
// only add label if the edge already exists
615+
let e = Edge { source, target };
616+
if gs.is_connected(source, target, 1, Included(1))? {
617+
let key = AnnoKey {
618+
ns: anno_ns.into(),
619+
name: anno_name.into(),
620+
};
621+
gs.delete_edge_annotation(&e, &key)?;
619622
}
623+
}
620624
}
621625
} // end match update entry type
622626
ComponentType::after_update_event(change, self, &mut update_graph_index)?;
@@ -886,9 +890,10 @@ impl<CT: ComponentType> Graph<CT> {
886890
pub fn is_loaded(&self, c: &Component<CT>) -> bool {
887891
let entry: Option<&Option<Arc<dyn GraphStorage>>> = self.components.get(c);
888892
if let Some(gs_opt) = entry
889-
&& gs_opt.is_some() {
890-
return true;
891-
}
893+
&& gs_opt.is_some()
894+
{
895+
return true;
896+
}
892897
false
893898
}
894899

@@ -1018,32 +1023,33 @@ impl<CT: ComponentType> Graph<CT> {
10181023

10191024
pub fn optimize_gs_impl(&mut self, c: &Component<CT>) -> Result<()> {
10201025
if let Some(gs) = self.get_graphstorage(c)
1021-
&& let Some(stats) = gs.get_statistics() {
1022-
let opt_info = registry::get_optimal_impl_heuristic(self, stats);
1023-
1024-
// convert if necessary
1025-
if opt_info.id != gs.serialization_id() {
1026-
let mut new_gs = registry::create_from_info(&opt_info)?;
1027-
let converted = if let Some(new_gs_mut) = Arc::get_mut(&mut new_gs) {
1028-
info!(
1029-
"converting component {} to implementation {}",
1030-
c, opt_info.id,
1031-
);
1032-
new_gs_mut.copy(self.get_node_annos(), gs.as_ref())?;
1033-
true
1034-
} else {
1035-
false
1036-
};
1037-
if converted {
1038-
// insert into components map
1039-
info!(
1040-
"finished conversion of component {} to implementation {}",
1041-
c, opt_info.id,
1042-
);
1043-
self.components.insert(c.clone(), Some(new_gs.clone()));
1044-
}
1026+
&& let Some(stats) = gs.get_statistics()
1027+
{
1028+
let opt_info = registry::get_optimal_impl_heuristic(self, stats);
1029+
1030+
// convert if necessary
1031+
if opt_info.id != gs.serialization_id() {
1032+
let mut new_gs = registry::create_from_info(&opt_info)?;
1033+
let converted = if let Some(new_gs_mut) = Arc::get_mut(&mut new_gs) {
1034+
info!(
1035+
"converting component {} to implementation {}",
1036+
c, opt_info.id,
1037+
);
1038+
new_gs_mut.copy(self.get_node_annos(), gs.as_ref())?;
1039+
true
1040+
} else {
1041+
false
1042+
};
1043+
if converted {
1044+
// insert into components map
1045+
info!(
1046+
"finished conversion of component {} to implementation {}",
1047+
c, opt_info.id,
1048+
);
1049+
self.components.insert(c.clone(), Some(new_gs.clone()));
10451050
}
10461051
}
1052+
}
10471053

10481054
Ok(())
10491055
}
@@ -1114,13 +1120,15 @@ impl<CT: ComponentType> Graph<CT> {
11141120
.keys()
11151121
.filter(move |c| {
11161122
if let Some(ctype) = ctype.clone()
1117-
&& ctype != c.get_type() {
1118-
return false;
1119-
}
1123+
&& ctype != c.get_type()
1124+
{
1125+
return false;
1126+
}
11201127
if let Some(name) = name
1121-
&& name != c.name {
1122-
return false;
1123-
}
1128+
&& name != c.name
1129+
{
1130+
return false;
1131+
}
11241132
true
11251133
})
11261134
.cloned();

0 commit comments

Comments
 (0)