Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
Last active January 23, 2023 12:32
Show Gist options
  • Save ebresafegaga/4c8aeea663c609ba4675aad50d52bff0 to your computer and use it in GitHub Desktop.
Save ebresafegaga/4c8aeea663c609ba4675aad50d52bff0 to your computer and use it in GitHub Desktop.
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