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