projects
/
python_utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
1172b67
)
Update docs.
author
Scott Gasch
<
[email protected]
>
Mon, 4 Jul 2022 18:23:40 +0000
(11:23 -0700)
committer
Scott Gasch
<
[email protected]
>
Mon, 4 Jul 2022 18:23:40 +0000
(11:23 -0700)
iter_utils.py
patch
|
blob
|
history
diff --git
a/iter_utils.py
b/iter_utils.py
index 00c4221b26201d7c0a3a1b5bfee938d00371d914..977cf1df2b7e103f140757a71316339522d6c3ff 100644
(file)
--- a/
iter_utils.py
+++ b/
iter_utils.py
@@
-6,7
+6,9
@@
from typing import Any, List, Optional
class PeekingIterator(Iterator):
class PeekingIterator(Iterator):
- """An iterator that lets you peek at the next item on deck.
+ """An iterator that lets you peek() at the next item on deck.
+ Returns None when there is no next item (i.e. when __next__()
+ will produce a StopIteration exception).
>>> p = PeekingIterator(iter(range(3)))
>>> p.__next__()
>>> p = PeekingIterator(iter(range(3)))
>>> p.__next__()
@@
-57,6
+59,12
@@
class SamplingIterator(Iterator):
collects a random sample (of size sample_size) of the stream that can
be queried at any time.
collects a random sample (of size sample_size) of the stream that can
be queried at any time.
+ Note that until sample_size elements have been seen the sample will
+ be less than sample_size elements in length.
+
+ Note that if sample_size is > len(source_iter) then it will produce
+ a copy of source_iter.
+
>>> import collections
>>> import random
>>> import collections
>>> import random
@@
-89,7
+97,7
@@
class SamplingIterator(Iterator):
return self
def __next__(self) -> Any:
return self
def __next__(self) -> Any:
- item = self.source_iter.__next__()
# or raise
+ item = self.source_iter.__next__()
self.stream_length_so_far += 1
# Filling the resovoir
self.stream_length_so_far += 1
# Filling the resovoir