Add size_hint to ops (not very useful)
This commit is contained in:
parent
0b55ddda6b
commit
b521d22513
12 changed files with 71 additions and 0 deletions
|
@ -363,6 +363,18 @@ impl<P: MpsFilterPredicate + 'static> Iterator for MpsFilterStatement<P> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
match &self.iterable {
|
||||
VariableOrOp::Variable(s) => self.context.as_ref()
|
||||
.and_then(|x| x.variables.get_opt(s))
|
||||
.and_then(|x| match x {
|
||||
MpsType::Op(op) => Some(op.size_hint()),
|
||||
_ => None
|
||||
}),
|
||||
VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok()
|
||||
}.unwrap_or((0, None))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MpsFilterStatementFactory<
|
||||
|
|
|
@ -310,6 +310,18 @@ impl<P: MpsFilterPredicate + 'static> Iterator for MpsFilterReplaceStatement<P>
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
match &self.iterable {
|
||||
VariableOrOp::Variable(s) => self.context.as_ref()
|
||||
.and_then(|x| x.variables.get_opt(s))
|
||||
.and_then(|x| match x {
|
||||
MpsType::Op(op) => Some(op.size_hint()),
|
||||
_ => None
|
||||
}),
|
||||
VariableOrOp::Op(op) => op.try_real_ref().map(|x| x.size_hint()).ok()
|
||||
}.unwrap_or((0, None))
|
||||
}
|
||||
}
|
||||
|
||||
fn declare_or_replace_item(
|
||||
|
|
|
@ -101,6 +101,10 @@ impl<S: MpsSorter + 'static> Iterator for MpsSortStatement<S> {
|
|||
}
|
||||
self.item_cache.pop_front()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.iterable.try_real_ref().map(|x| x.size_hint()).unwrap_or((0, None))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MpsSortStatementFactory<S: MpsSorter + 'static, F: MpsSorterFactory<S> + 'static> {
|
||||
|
|
|
@ -49,6 +49,10 @@ impl Iterator for CommentStatement {
|
|||
fn next(&mut self) -> Option<Self::Item> {
|
||||
None
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for CommentStatement {
|
||||
|
|
|
@ -36,6 +36,10 @@ impl Iterator for EmptyStatement {
|
|||
fn next(&mut self) -> Option<Self::Item> {
|
||||
None
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for EmptyStatement {
|
||||
|
|
|
@ -95,6 +95,10 @@ impl Iterator for FilesStatement {
|
|||
None => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.file_iter.as_ref().map(|x| x.size_hint()).unwrap_or((0, None))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for FilesStatement {
|
||||
|
|
|
@ -147,6 +147,15 @@ impl Iterator for RepeatStatement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
if self.inner_done {
|
||||
let len = (self.cache.len() * (self.repetitions + 1)) - self.cache_position;
|
||||
(len, Some(len))
|
||||
} else {
|
||||
(0, None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for RepeatStatement {
|
||||
|
|
|
@ -51,6 +51,10 @@ impl Iterator for ResetStatement {
|
|||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for ResetStatement {
|
||||
|
|
|
@ -55,6 +55,10 @@ impl Iterator for SqlInitStatement {
|
|||
Err(e) => Some(Err(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for SqlInitStatement {
|
||||
|
|
|
@ -108,6 +108,11 @@ impl Iterator for SqlStatement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let len = self.rows.as_ref().map(|x| x.len());
|
||||
(len.unwrap_or(0), len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SqlStatement {
|
||||
|
|
|
@ -170,6 +170,11 @@ impl Iterator for SimpleSqlStatement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let len = self.rows.as_ref().map(|x| x.len());
|
||||
(len.unwrap_or(0), len)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for SimpleSqlStatement {
|
||||
|
|
|
@ -120,6 +120,10 @@ impl Iterator for AssignStatement {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, Some(1))
|
||||
}
|
||||
}
|
||||
|
||||
impl MpsOp for AssignStatement {
|
||||
|
|
Loading…
Reference in a new issue