MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / apply_distinct_all_operation

Function apply_distinct_all_operation

crates/gitql-engine/src/engine_distinct.rs:29–70  ·  view source on GitHub ↗

Apply Distinct all operator that depend on all selected fields in the object

(object: &mut GitQLObject, hidden_selections: &[String])

Source from the content-addressed store, hash-verified

27
28/// Apply Distinct all operator that depend on all selected fields in the object
29fn apply_distinct_all_operation(object: &mut GitQLObject, hidden_selections: &[String]) {
30 let titles: Vec<&String> = object
31 .titles
32 .iter()
33 .filter(|s| !hidden_selections.contains(s))
34 .collect();
35
36 let titles_count = titles.len();
37 let hidden_selection_count = hidden_selections.len();
38
39 let objects = &object.groups[0].rows;
40 let mut new_objects = Group { rows: vec![] };
41 let mut values_set: HashSet<u64> = HashSet::new();
42
43 for object in objects {
44 // Build row of the selected only values
45 let mut row_values: Vec<String> = Vec::with_capacity(titles_count);
46 for i in 0..titles.len() {
47 if let Some(value) = object.values.get(i + hidden_selection_count) {
48 row_values.push(value.literal());
49 }
50 }
51
52 // Compute the hash for row of values
53 let mut hasher = DefaultHasher::new();
54 row_values.hash(&mut hasher);
55 let values_hash = hasher.finish();
56
57 // If this hash is unique, insert the row
58 if values_set.insert(values_hash) {
59 new_objects.rows.push(Row {
60 values: object.values.clone(),
61 });
62 }
63 }
64
65 // If number of total rows is changed, update the main group rows
66 if objects.len() != new_objects.len() {
67 object.groups[0].rows.clear();
68 object.groups[0].rows.append(&mut new_objects.rows);
69 }
70}
71
72/// Apply Distinct on one or more valid fields from the object
73fn apply_distinct_on_operation(object: &mut GitQLObject, distinct_fields: &[String]) {

Callers 1

apply_distinct_operatorFunction · 0.85

Calls 3

containsMethod · 0.80
lenMethod · 0.45
literalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…