Signal query #5

Merged
ThePerfectComputer merged 9 commits from signal_query into main 2022-09-02 19:08:26 +00:00
Showing only changes of commit 223d36c1a6 - Show all commits

View file

@ -145,155 +145,121 @@ impl Signal {
Ok((timestamp, signal_val)) Ok((timestamp, signal_val))
} }
// pub(super) fn query_num_val_on_tmln( pub(super) fn query_num_val_on_tmln(
// &self, &self,
// //(REMOVE THIS COMMENT)below is from self desired_time: BigUint,
// nums_encoded_as_fixed_width_le_u8: &Vec<u8>, tmstmps_encoded_as_u8s: &Vec<u8>,
// lsb_indxs_of_num_tmstmp_vals_on_tmln: &Vec<LsbIdxOfTmstmpValOnTmln>, all_signals: &Vec<Signal>,
// tmstmps_encoded_as_u8s: &Vec<u8>, ) -> Result<BigUint, SignalErrors> {
// all_signals: &Vec<Signal>, let signal_idx = match self {
// //(REMOVE THIS COMMENT)below is from self Self::Data { self_idx, .. } => {
// // TODO : should this be usize? let SignalIdx(idx) = self_idx;
// desired_time: BigUint, *idx
// ) -> Result<BigUint, SignalErrors> { }
// let signal_idx = match self { Self::Alias {
// Self::Data { name: _,
// name, signal_alias,
// sig_type, } => {
// signal_error, let SignalIdx(idx) = signal_alias;
// num_bits, *idx
// self_idx, }
// .. };
// } => {
// let SignalIdx(idx) = self_idx;
// *idx
// }
// Self::Alias { name, signal_alias } => {
// let SignalIdx(idx) = signal_alias;
// *idx
// }
// };
// let ( let (nums_encoded_as_fixed_width_le_u8, lsb_indxs_of_num_tmstmp_vals_on_tmln, num_bytes) =
// nums_encoded_as_fixed_width_le_u8, match &all_signals[signal_idx] {
// lsb_indxs_of_num_tmstmp_vals_on_tmln, Signal::Data {
// tmstmps_encoded_as_u8s, num_bytes,
// num_bits, ref nums_encoded_as_fixed_width_le_u8,
// name, ref lsb_indxs_of_num_tmstmp_vals_on_tmln,
// ) = match all_signals[signal_idx] { ..
// Signal::Data { } => {
// name, if num_bytes.is_none() {
// sig_type, return Err(SignalErrors::NoNumBytes);
// signal_error, }
// num_bits, Ok((
// self_idx, nums_encoded_as_fixed_width_le_u8,
// ref nums_encoded_as_fixed_width_le_u8, lsb_indxs_of_num_tmstmp_vals_on_tmln,
// string_vals, num_bytes,
// ref lsb_indxs_of_num_tmstmp_vals_on_tmln, ))
// byte_len_of_num_tmstmp_vals_on_tmln, }
// lsb_indxs_of_string_tmstmp_vals_on_tmln, Signal::Alias { .. } => Err(SignalErrors::PointsToAlias),
// byte_len_of_string_tmstmp_vals_on_tmln, }?;
// scope_parent, // this signal should at least have some events, otherwise, trying to index into
// } => { // an empty vector later on would fail
// if num_bits.is_none() { if lsb_indxs_of_num_tmstmp_vals_on_tmln.is_empty() {
// return Err(SignalErrors::NoNumBits); return Err(SignalErrors::EmptyTimeline);
// } }
// Ok((
// nums_encoded_as_fixed_width_le_u8,
// lsb_indxs_of_num_tmstmp_vals_on_tmln,
// tmstmps_encoded_as_u8s,
// num_bits,
// name,
// ))
// }
// Signal::Alias { name, signal_alias } => Err(SignalErrors::PointsToAlias),
// }?;
// // this signal should at least have some events, otherwise, trying to index into
// // an empty vector later on would fail
// if lsb_indxs_of_num_tmstmp_vals_on_tmln.is_empty() {
// return Err(SignalErrors::EmptyTimeline);
// }
// // assertion that value_sequence is a proper multiple of // assertion that value_sequence is a proper multiple of
// // timeline_markers // timeline_markers
// let bytes_required = let bytes_required = num_bytes.ok_or_else(|| {
// Signal::bytes_required(&num_bits, &name).map_err(|arg| SignalErrors::Other(arg))?; SignalErrors::Other(format!(
// if lsb_indxs_of_num_tmstmp_vals_on_tmln.len() "Error near {}:{}. num_bytes empty.",
// != (nums_encoded_as_fixed_width_le_u8.len() * bytes_required as usize) file!(),
// { line!()
// return Err(SignalErrors::TimelineNotMultiple); ))
// } })?;
if lsb_indxs_of_num_tmstmp_vals_on_tmln.len()
!= (nums_encoded_as_fixed_width_le_u8.len() * bytes_required as usize)
{
return Err(SignalErrors::TimelineNotMultiple);
}
// // let TimelineIdx(desired_time) = desired_time; // check if we're requesting a value that occurs before the recorded
// start of the timeline
let (timeline_start_time, _) = self.lookup_time_and_val(0, tmstmps_encoded_as_u8s)?;
if desired_time < timeline_start_time {
return Err(SignalErrors::PreTimeline {
desired_time: desired_time,
timeline_start_time: timeline_start_time,
});
}
// // check if we're requesting a value that occurs before the recorded let mut lower_idx = 0usize;
// // start of the timeline let mut upper_idx = lsb_indxs_of_num_tmstmp_vals_on_tmln.len() - 1;
// let TimelineIdx(timeline_start_time) = timeline_cursors.first().unwrap(); let (timeline_end_time, timeline_end_val) =
// if desired_time < *timeline_start_time { self.lookup_time_and_val(upper_idx, tmstmps_encoded_as_u8s)?;
// return Err(SignalErrors::PreTimeline {
// desired_time: TimelineIdx(desired_time),
// timeline_start_time: TimelineIdx(*timeline_start_time),
// });
// }
// let mut lower_idx = 0usize; // check if we're requesting a value that occurs beyond the end of the timeline,
// let mut upper_idx = timeline_cursors.len() - 1; // if so, return the last value in this timeline
if desired_time > timeline_end_time {
return Ok(timeline_end_val);
}
// // check if we're requesting a value that occurs beyond the end of the timeline, // This while loop is the meat of the lookup. Performance is log2(n),
// // if so, return the last value in this timeline // where n is the number of events on the timeline.
// let TimelineIdx(timeline_end_time) = timeline_cursors.last().unwrap(); // We can assume that by the time we get here, that the desired_time
// if desired_time > *timeline_end_time { // is an event that occurs on the timeline, given that we handle any events
// let range = (value_sequence_as_bytes.len() - bytes_per_value)..; // occuring after or before the recorded tiimeline in the code above.
// let value_by_bytes = &value_sequence_as_bytes[range]; while lower_idx <= upper_idx {
// let value = BigUint::from_bytes_le(value_by_bytes); let mid_idx = lower_idx + ((upper_idx - lower_idx) / 2);
let (curr_time, curr_val) =
self.lookup_time_and_val(mid_idx, tmstmps_encoded_as_u8s)?;
let ordering = curr_time.cmp(&desired_time);
// return Ok(value); match ordering {
// } std::cmp::Ordering::Less => {
lower_idx = mid_idx + 1;
}
std::cmp::Ordering::Equal => {
return Ok(curr_val);
}
std::cmp::Ordering::Greater => {
upper_idx = mid_idx - 1;
}
}
}
// // This while loop is the meat of the lookup. Performance is log2(n), let (left_time, left_val) =
// // where n is the number of events on the timeline. self.lookup_time_and_val(lower_idx - 1, tmstmps_encoded_as_u8s)?;
// // We can assume that by the time we get here, that the desired_time let (right_time, _) = self.lookup_time_and_val(lower_idx - 1, tmstmps_encoded_as_u8s)?;
// // is an event that occurs on the timeline, given that we handle any events
// // occuring after or before the recorded tiimeline in the code above.
// while lower_idx <= upper_idx {
// let mid_idx = lower_idx + ((upper_idx - lower_idx) / 2);
// let TimelineIdx(curr_time) = timeline_cursors[mid_idx];
// let ordering = curr_time.cmp(&desired_time);
// match ordering { let ordered_left = left_time < desired_time;
// std::cmp::Ordering::Less => { let ordered_right = desired_time < right_time;
// lower_idx = mid_idx + 1; if !(ordered_left && ordered_right) {
// } return Err(SignalErrors::OrderingFailure);
// std::cmp::Ordering::Equal => { }
// let u8_timeline_start_idx = mid_idx * bytes_per_value;
// let u8_timeline_end_idx = u8_timeline_start_idx + bytes_per_value;
// let range = u8_timeline_start_idx..u8_timeline_end_idx;
// let value_by_bytes = &value_sequence_as_bytes[range];
// let value = BigUint::from_bytes_le(value_by_bytes);
// return Ok(value);
// }
// std::cmp::Ordering::Greater => {
// upper_idx = mid_idx - 1;
// }
// }
// }
// let idx = lower_idx - 1; return Ok(left_val);
// let TimelineIdx(left_time) = timeline_cursors[idx]; }
// let TimelineIdx(right_time) = timeline_cursors[idx + 1];
// let ordered_left = left_time < desired_time;
// let ordered_right = desired_time < right_time;
// if !(ordered_left && ordered_right) {
// return Err(SignalErrors::OrderingFailure);
// }
// let u8_timeline_start_idx = idx * bytes_per_value;
// let u8_timeline_end_idx = u8_timeline_start_idx + bytes_per_value;
// let range = u8_timeline_start_idx..u8_timeline_end_idx;
// let value_by_bytes = &value_sequence_as_bytes[range];
// let value = BigUint::from_bytes_le(value_by_bytes);
// return Ok(value);
// }
} }