MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / merge

Method merge

nodedb-cluster/src/distributed_document/merge_sort.rs:59–70  ·  view source on GitHub ↗

Perform the global merge sort and apply the global LIMIT. Each shard already applied `ORDER BY + LIMIT` locally, so we have at most `num_shards × limit` rows. The global sort + limit produces the correct result.

(&mut self, global_limit: usize)

Source from the content-addressed store, hash-verified

57 /// at most `num_shards × limit` rows. The global sort + limit produces
58 /// the correct result.
59 pub fn merge(&mut self, global_limit: usize) -> Vec<ShardRow> {
60 match self.direction {
61 SortDirection::Ascending => {
62 self.rows.sort_by(|a, b| a.sort_key.cmp(&b.sort_key));
63 }
64 SortDirection::Descending => {
65 self.rows.sort_by(|a, b| b.sort_key.cmp(&a.sort_key));
66 }
67 }
68 self.rows.truncate(global_limit);
69 self.rows.clone()
70 }
71
72 /// Total rows collected before merge.
73 pub fn total_rows(&self) -> usize {

Callers 2

merge_sort_ascendingFunction · 0.45
merge_sort_descendingFunction · 0.45

Calls 3

cmpMethod · 0.45
truncateMethod · 0.45
cloneMethod · 0.45

Tested by 2

merge_sort_ascendingFunction · 0.36
merge_sort_descendingFunction · 0.36