Last active
January 23, 2023 12:32
-
-
Save ebresafegaga/4c8aeea663c609ba4675aad50d52bff0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (next, _) = linearization.get_items_adjacent(parent.id); | |
let next = next.and_then(|item| match item.kind { | |
TermKind::RecordField { | |
ident, | |
record, | |
value: ValueState::Known(value), | |
.. | |
} if value == parent.id => Some((ident, record)), | |
_ => None, | |
}); | |
// Oops.. leaking internals | |
// let next = | |
// linearization | |
// .id_to_index | |
// .get(&parent.id) | |
// .copied() | |
// .and_then(|index| { | |
// linearization.linearization.get(index - 1).and_then(|item| { | |
// match item.kind { | |
// TermKind::RecordField { | |
// ident, | |
// record, | |
// value: ValueState::Known(value), | |
// .. | |
// } if value == parent.id => Some((ident, record)), | |
// _ => None, | |
// } | |
// }) | |
// }); | |
// let next = | |
// // Oops.. linear search | |
// // we can do better! | |
// // a record field comes before it's value for sure | |
// // 1. we can split the linearization and search the left. | |
// // 2. we can use the position and our knowledge from the linearization | |
// // algorithm to calculate the exact position. | |
// linearization | |
// .linearization | |
// .iter() | |
// .find_map(|item| match item.kind { | |
// TermKind::RecordField { | |
// ident, | |
// record, | |
// value: ValueState::Known(value), | |
// .. | |
// } if value == parent.id => Some((ident, record)), | |
// _ => None, | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment